Web apps & software

What is clean architecture?

Clean architecture is a way of structuring an application so that its core business rules depend on nothing external. Databases, web frameworks, user interfaces and third-party APIs sit in outer layers and plug into the core, never the other way round.

The dependency rule

Picture concentric circles. In the middle are entities and use cases, such as "calculate a quote" or "cancel a booking". Around them are adapters that translate between the core and the outside world: controllers, repositories, API clients. On the outside sit the framework, the database and the UI. Source code may only point inward. The quote calculation never imports the database library; it asks for an interface that the outer layer implements.

What that buys you

  • Core logic can be unit tested in milliseconds without a database or web server.
  • Swapping a payment provider, email service or even a framework touches the adapters, not the rules.
  • New developers find business logic in one predictable place.

The trade-off

More files, more interfaces and more mapping between layers. In a small CRUD app this can feel like paperwork. Related styles, such as hexagonal architecture (ports and adapters) and onion architecture, share the same goal with different diagrams. A pragmatic team applies the rule where the logic is valuable and keeps simple screens simple.

Questions, answered

Robert C. Martin, in a 2012 blog post and later a book of the same name.

No. It is used in Java, C#, PHP, TypeScript, Dart and many others.

By the Stegnor team · Updated