Open the editor

Clean architecture

Entities, use cases, adapters and frameworks, with every dependency pointing inwards.

Clean architecture diagram: Entities, Use cases (interactors), Ports at the use-case edge, Interface adapters, Frameworks and drivers

Clean architecture, described by Robert C. Martin in 2012, arranges code in concentric circles: entities in the centre, then use cases, then interface adapters, then frameworks and drivers on the outside. Its one rule is the dependency rule: source code may only depend on things further in. Nothing in an inner circle knows the name of anything in an outer one.

The diagram lays the circles out from left (outermost) to right (innermost) so the arrows are easy to read. Where an inner circle needs something from outside, such as saving data, it declares an interface and an outer circle implements it.

The parts of the pattern

Entities
Enterprise-wide business objects and rules, with no knowledge of the application around them.
Use cases (interactors)
Application-specific rules, such as "place an order". They orchestrate entities.
Ports at the use-case edge
A repository interface and an output boundary, owned by the use cases.
Interface adapters
Controllers, presenters and gateways that convert data between the use cases and the outside.
Frameworks and drivers
The web framework, the database and the UI: details that plug in at the edge.

How it works

  1. The web framework hands a request to the controller.
  2. The controller converts it into a request model and calls the place-order interactor.
  3. The interactor uses the Order and Customer entities and saves through the repository interface.
  4. The SQL repository, which implements that interface, writes to the database.
  5. The interactor passes the result to the output boundary; the presenter formats it for the view.

When to use it, and when not to

Good fit

  • Long-lived systems with real business rules that must outlive frameworks.
  • Teams that need to test use cases in isolation.
  • Large codebases where a shared, explicit dependency rule prevents decay.

Think twice

  • Small apps and prototypes: four circles of mapping code for a CRUD form is waste.
  • Teams that copy the folder layout but ignore the dependency rule, getting the cost without the benefit.

Edit this diagram

Click Open the diagram in the editor to get your own copy, saved in your browser. Rename the boxes to match your system, swap the generic boxes for technology icons from the palette, then export a PNG, SVG or PDF, or share a link. No sign-up.