CLEAN architecture

https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html

We need CLEAN architecture so that the system we built:

  1. Independent of frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.
  2. Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
  3. Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.

The dependency rule

  • Source code dependencies can only point inwards
  • Nothing in an inner circle can know anything at all about something in an outer circle
  • The name of something declared in an outer circle must not be mentioned by the code in an inner circle

Entities

  • Entities encapsulate Enterprise wide business rules.
  • An entity can be an object with methods, or it can be a set of data structures and functions.
  • They encapsulate the most general and high-level rules.
  • They are the least likely to change when something external changes.

Use Cases

  • This layer contains application specific business rules. It encapsulates and implements all of the use cases of the system

Interface adapters

  • A set of adapters that convert data from the format most convenient for the use cases and entities

Frameworks and Drivers

  • The outermost layer is generally composed of frameworks and tools such as the Database, the Web framework, etc.
Last updated on