vishal patel
UnderstoodIntermediateUpdated 2026-09-23

Clean Architecture

Concentric rings — entities, use cases, interface adapters, frameworks — with one rule: source-code dependencies only point inward.

dependency-ruleuse-casestestability

The idea

Clean Architecture generalises Hexagonal, Onion and similar styles into one dependency rule: code in an inner circle knows nothing about outer circles. Frameworks, databases and the web are details that sit at the edge.

diagram

The four rings

RingContainsChanges when…
EntitiesCore business objects and invariantsThe business itself changes
Use casesOne class/function per user intention (AddItemsToRelease)A workflow changes
Interface adaptersControllers, DTO mappers, repository implementationsThe API or storage shape changes
Frameworks & driversWeb framework, DB, UI, queuesYou upgrade or swap technology

Crossing boundaries: when a use case needs to call outward (to save data, say), it calls an interface it owns. The outer ring implements it. This is dependency inversion applied at the architecture level.

Use it when
  • Long-lived products where frameworks will change during the system's life
  • Complex workflows you want to unit test by use case
  • Large teams that need clear conventions
Avoid it when
  • Microservices that are basically a DB table with an API
  • Hackathons, POCs, throwaway code

Trade-offs

  • ✅ The business logic outlives frameworks, and use cases read like documentation.
  • ❌ Mapping objects between rings (DTO → entity → persistence model) adds boilerplate.
  • ❌ Teams sometimes create four rings for a service with two endpoints. Size the structure to the problem.
Architect's tip

Pragmatic version: keep entities + use cases framework-free, and allow a thin "infrastructure" folder to hold everything else. You get most of the benefit at half the ceremony.

Sources & further learning

Videos, courses, docs and books I recommend for this topic.

Related topics