Flutter apps need structure that is easy to orient yourself in, testable and maintainable.

With a client-centric service such as Firebase Firestore, it's extremely important to keep your code clean.

Domain-Driven Design - the big picture

We can use a view model of our choice, whether it be ChangeNotifier, MobX Store, or even the new StateNotifier.

The domain layer is completely independent of all the other layers. Just pure business logic & data.

With Domain-Driven Design, UI is dumbest part of the app. That's because it's at the boundary of our code and it's totally dependent on the Flutter framework.

Architectural Layers of DDD

Unlike with the spaghetti architecture ๐Ÿ, you will always know where to put a certain class when you're following the Domain-Driven Design principles.

Every architectural layer contains features and possibly a core folder which holds classes common to all the features in that layer (helpers, abstract classes, ...).

For folder structure Layers will hold features, not the other way around. This will still keep the code readable but, most importantly, it will ensure that adding more features and sub-features is going to be a pure bliss.

Presentation Layer

Application Layer

Domain Layer

Infrastructure Layer

Untitled

<aside> ๐Ÿ“” Arrows represent the flow of data. This can be either uni-directional or bi-directional.

</aside>

<aside> ๐Ÿ“” The domain layer isย completely independentย of all the other layers. Just pure business logic & data. It has to have ZERO dependencies on other layers.

</aside>