Clean architecture

Clean architecture is a software design approach that organises code into concentric layers, isolating core business logic from technical concerns such as frameworks, databases and user interfaces. Dependencies point inward toward the domain, so external technologies can change without rewriting the rules that define what the application actually does.

The dependency rule and the layers

Clean architecture, popularised by Robert C. Martin, builds on earlier models such as hexagonal architecture (ports and adapters) and onion architecture. Its single governing principle is the dependency rule: source code dependencies may only point inward, toward higher-level policy. An inner layer never knows the name of an outer one.

The layers, from the centre outward, are typically:

  • Entities — enterprise-wide business rules and core domain objects, the most stable part of the system.
  • Use cases — application-specific business rules that orchestrate entities to fulfil a given operation.
  • Interface adapters — controllers, presenters and gateways that convert data between the use cases and external formats.
  • Frameworks and drivers — the web framework, database, UI and third-party tools, kept at the outermost edge.

Crossing inward over a boundary is done through interfaces (abstractions) defined by the inner layer and implemented by the outer one. This dependency inversion is what lets a database engine, an API client or even the entire web framework be swapped without touching the domain.

Clean architecture vs. layered MVC

Traditional layered (n-tier) or MVC applications often let the domain depend on the framework and the persistence layer, which couples business rules to technical choices. Clean architecture inverts that direction.

AspectClean architectureConventional layered MVC
Dependency directionAlways inward, toward the domainOften top-down, domain depends on data/framework
Business logic locationIsolated in entities and use casesFrequently spread across controllers and models
Framework couplingPushed to the outer edge, replaceableTightly embedded in core code
Testability of rulesDomain testable without DB or web serverTests often require framework or database
Cost to swap a technologyLocalised to adaptersRipples through the codebase

The trade-off is upfront effort: more interfaces, mapping between layers and boilerplate. For short-lived or trivial projects this overhead is rarely justified; for long-lived business platforms it pays back in maintainability.

Maintainability and when it pays off

The practical benefit of clean architecture is that the parts most likely to change — UI, frameworks, databases, external services — are kept furthest from the parts that change least: the business rules. This separation produces several concrete advantages:

  • Independent testing — use cases can be exercised with in-memory test doubles, without spinning up a database or HTTP server.
  • Technology flexibility — migrating from one database or framework version to another affects adapters, not the domain.
  • Clear boundaries — each layer has a defined responsibility, which limits the blast radius of a change.
  • Longevity — business logic survives the inevitable churn of front-end and infrastructure choices.

Clean architecture is most relevant for systems with substantial, durable business logic: ERP, CRM, billing engines and other platforms expected to evolve over years. For prototypes or thin CRUD interfaces, a lighter layered approach is usually a more proportionate choice.

Questions fréquentes

The dependency rule states that source code dependencies must only point inward, toward higher-level policy. Outer layers like frameworks and databases depend on inner layers such as use cases and entities, never the reverse. Inward references across boundaries use interfaces defined by the inner layer, which keeps business rules independent of technical details.

Both isolate business logic from external concerns and share the same intent. Hexagonal architecture (ports and adapters) frames this as a core surrounded by interchangeable adapters connected through ports. Clean architecture generalises the idea into concentric layers governed by the dependency rule, but the underlying principle of protecting the domain is the same.

No. Clean architecture adds interfaces, layer mapping and boilerplate that only pay off when business logic is substantial and long-lived, such as in ERP or CRM platforms. For prototypes, short-lived tools or simple CRUD applications, the overhead often outweighs the benefit, and a lighter layered approach is more appropriate.

No. Clean architecture is a structural principle, not a tool. It applies in any language that supports abstraction and dependency inversion, and it deliberately keeps frameworks at the outer edge so they remain replaceable. The same layered approach can be implemented in PHP, Java, C#, TypeScript or others.

Building a custom software project? We design bespoke software aligned with your roadmap.

See our custom software expertise