Clean Architecture — DDD for my Flutter, Spring and React projects

Maxime F.
3 min readJan 7, 2023

--

DDD or Domain Driven Design allows you to build application that focus on what it is really needed to be built. All use cases, logics must be known at advance… At least before the first version of your application. Therefore allowing you to structure your code in different units and easily segregate responsabilities.

For the past years, i had to develop projects in many languages with different frameworks and even though these frameworks came most of the time with powerful in-built APIs and utils, they lacks of projects architecture. That was a big problem at the start cause when you witch of projects, you had to switch sometimes from languages, frameworks and code architecture leading you to require more times to adapt to the project before being fully functionnal. The language and framework were not the big deal cause it was mostly one i already knew. But the architecture of code was sometimes totally different. It was mostly an architecture that is realated to the framework rather than being something general that could even be language or framework agnostic (what a real architecture must be).

With time, i started to learn what Clean Architecture is and what are different designs patterns or concepts related to it and so to structure my project to respect those designs. I ended with an architecture that i use in almost all my monolytic application projects with

  • Layered Architecture for the global architecture and structure of components.
  • DDD for the Software Design
  • MVVM or MVC for the logic design pattern and interaction between main components.
  • Event Handling or Messaging pattern for the communication between sub components.

The main structure or the base structure used is like

DDD Project Structure tree

This structure allows me to easily respect the Onion architecture and have something like that

DDD — Onion Architecture

With

  • Foundation: The core of application code. It contains all code that every part of the application depends on. You could have code of contracts (interfaces), façades, helpers, exceptions etc…
  • Data: The data layer of DDD, contains all code related to data management of the application like repositories, models, DAO etc…
  • Domain: The Domain layer of DDD, contains codes related to the application business logic like Use Cases, Manager, entities, value object etc…
  • Presentation: The Presentation layer of DDD. It contains codes related to the user interaction or interface like ViewModels, Controllers, Views, Responses etc…
  • Application: This layer is responsible of the initilisation of the application and contains codes of configuration, dependency injection and service location.

After that, depending on the type of language and framework. The subfolders could be little different with structure like

  • For Flutter
DDD — Flutter Projects Tree
  • For React
DDD — React Projects Tree
  • For Java Spring
DDD — Java Spring Projects Tree

So even though there’s little difference between project trees (mostly in Presentation layer), they all have similarities and this way i can easily switch and know where to look or add something without taking too much times to adapt.

Hope you enjoy reading and it’ll help you somehow!!!

--

--

Maxime F.
Maxime F.

No responses yet