The Clean Architecture

The Clean Architecture

Rony Le

In this article, I mainly share about the idea, philosophy and importance features of Clean Architecture

  1. Clean Architecture is like all other architecture, it is multi-layer/layer architecture.
  2. The philosophy of this architecture considers business rules (enterprise & application) to be the most important, which means it isolates the business rules part. So we see that entities and use cases are the two most important layers and the center of the circle. And interface adapters and frameworks & drivers are elements and are placed at the outermost of the circle.
  3. The circles represent the layers, the more outside, the more detailed (low level/details), the more in the center, the more abstract (high level)
    The circles represent the layers, the more outside, the more detailed (low level/details), the more in the center, the more abstract (high level)
  4. This architecture uses Dependency Inversion
  • High level does not depend on low level, they depend on abstraction
  • Abstraction does not depend on its implementations/details

Screenshot-2023-06-14-at-20.25.21-1
There is confusion for beginners to approach this architecture when looking at the moving "arrow" on the figure. It's not call direction from outside to inside but dependency direction. As mentioned above, the low level is outside the circle and the high level is inside the circle, so the philosophy of this axis is that the low level will depend on the high level.

Flow of control
Screenshot-2023-06-14-at-20.35.08

  • Controller and Presenter are the same color because they are interface adapters. They are implementation details and are dependent on the color red
  • Use Case Output Port, Interactor and Input Port are Application Business Rules, and often when code, they are usually declared in the same place, because if these interfaces are in different places and different packages, it will be wrong Dependency Inversion or simply rather than being dependent on imports from each other, not decoupling
  1. Controller is where the program starts and calls into the User Case Input Port (interface).
  2. Use Case Interactor, it will implement the Use Case Input Port
  3. Use Case Interactor, it will call up the Use Case Output Port for it to go out
  4. Finally, Presenter will implement the Use Case Output Port

In the next article, we will go into implementing Clean Architecture.