Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Explanation of directory structure

Cervon Wong edited this page Nov 25, 2020 · 2 revisions

Explanation of directory structure

The structure takes inspiration from Matt Rešetár's Clean Architecture course.

Overview

lib/
├───core
│   ├───constants
│   ├───data
│   ├───domain
│   ├───presentation
│   └───theme
├───features
│   ├───timetable
│   │   ├───data
│   │   ├───domain
│   │   └───presentation
│   └───<etc.>
└───screens
    ├───AboutScreen.dart
    └───<etc.>

core directory

The core directory contains code that is used in multiple places in the app. Code in the core directory should not depend on any other directories. But other directories may, and should if needed, depend on the core directory.

features directory

Package-by-feature uses directories to reflect the features that exists in the app. It holds code related to a single feature together in a single directory. One feature directory will not depend on another feature directory (one feature should not depend on another feature in the app).

If one feature directory really needs to depend on another feature directory. Consider moving the dependency into the core folder if it is used by many other parts of your code, or combining the two feature directories into a single directory.

data, domain, presentation

There are actually more sub-directories within these directories:

├───data
│   ├───data_sources
│   ├───models
│   └───repositories
├───domain
│   ├───entities
│   ├───repositories
│   └───use_cases
└───presentation
    ├───bloc
    └───widgets

Please see Matt Rešetár's Clean Architecture course on more explanation on each of these sub-directories.

screens directory

The screens directory holds classes in the form of FooScreen.dart. These are usually Widgets that represent a navigation destination. Widgets in the screens directory may depend on one or more feature directories. No other code should depend on Widgets in the screens directory.