<arch.design/>
Principles/Clean Architecture
{ }CodeArchitectureintermediate2012solidtestabilitydependency-ruleuncle-bob

Clean Architecture

Organise code into concentric dependency rings so business logic never depends on frameworks, databases, or UI.

5/5
{ }
Operates at: Code level

Inside a codebase — classes, modules, files

Interactive visualization

Live
dependency ruleFrameworks & DriversWeb, DB, UI, DevicesInterface AdaptersControllers, Presenters, GatewaysUse CasesApplication Business RulesEntitiesEnterprise Business RulesEntitiesBusiness Rules

The Dependency Rule

Source-code dependencies must always point inward. Nothing in an inner circle can know about something in an outer circle — not a function name, class, variable, or framework type.

Click any ring to explore its responsibility.

Click any concentric ring to explore its role and responsibilities.

How it works

Clean Architecture, introduced by Robert C. Martin (Uncle Bob), arranges code into four concentric layers: Entities, Use Cases, Interface Adapters, and Frameworks & Drivers. The Dependency Rule is absolute — source-code dependencies must always point inward. Nothing in an inner layer knows anything about an outer layer.

Entities encapsulate enterprise-wide business rules. Use Cases orchestrate data flow to and from Entities. Interface Adapters convert data between Use Cases and delivery mechanisms. Frameworks & Drivers are the outermost circle: databases, web frameworks, and external APIs.

This separation lets you swap a REST API for gRPC, replace a SQL database with a NoSQL one, or test Use Cases without spinning up a web server.

Why it matters

Most software rot starts when business rules leak into framework code. Clean Architecture keeps the core testable, portable, and framework-independent — critical as systems grow.

When to use

  • Long-lived products where frameworks and databases may change
  • Teams where different layers are owned by different groups
  • When comprehensive unit testing of business logic is required
  • Monoliths that may need to be decomposed into microservices later

When NOT to use

  • Small scripts or one-off tools
  • Prototype / MVP with tight deadlines
  • Simple CRUD apps with no meaningful business logic

Trade-offs

+

Business logic is framework-independent and highly testable

More initial boilerplate and indirection

+

Replacing databases or frameworks is safe and isolated

Over-engineering risk for simple domains

+

Clear ownership boundaries between teams

Learning curve for developers new to the pattern

In production

Netflix

Recommendation engine core logic isolated from delivery infrastructure

Shopify

Checkout domain isolated from payment gateway providers

Uber

Fare calculation engine independent of platform and persistence layers

Industry adoption

5/5Ubiquitous — used at virtually every scale-focused company.

Related principles