100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Clean Architecture

Coined by Robert C. Martin ("Uncle Bob")

AdvancedConcept5.4K learners

Clean Architecture is a software architecture pattern, described by Robert C. Martin, that organizes code into concentric layers with dependencies pointing strictly inward toward core business rules, keeping frameworks, databases, and UI…

Definition

Clean Architecture is a software architecture pattern, described by Robert C. Martin, that organizes code into concentric layers with dependencies pointing strictly inward toward core business rules, keeping frameworks, databases, and UI as replaceable outer details.

Overview

Clean Architecture was described by Robert C. Martin (widely known as 'Uncle Bob') in his 2017 book Clean Architecture, synthesizing ideas from several earlier architecture patterns — including hexagonal architecture, onion architecture, and DCI (Data, Context, Interaction) — into a single set of guiding principles. The architecture is typically drawn as a set of concentric circles. At the very center sit Entities, representing enterprise-wide business rules and core domain objects. The next ring out holds Use Cases (or Interactors), which encode application-specific business rules and orchestrate the flow of data to and from entities. Outside that is the Interface Adapters layer, which converts data between the format most convenient for use cases/entities and the format most convenient for external agents like databases or the web (this is where controllers, presenters, and gateways live). The outermost ring, Frameworks and Drivers, contains the actual technology choices — the web framework, the database, external APIs, dependency-injection frameworks. The pattern's single governing rule is the Dependency Rule: source code dependencies must point only inward, from outer, more volatile, technology-specific layers toward inner, more stable, business-rule layers. Inner layers must never reference anything from outer layers, including their names or types. Because outer layers depend on abstractions (interfaces) defined by inner layers rather than the other way around, this achieves the Dependency Inversion Principle at an architectural scale: business rules can be compiled, tested, and reasoned about with zero knowledge of which database, web framework, or UI technology the application ultimately uses. The practical benefits mirror hexagonal architecture's: business logic is independently testable without a database or web server running, and technology decisions (which framework, which database) become deferrable and replaceable details rather than foundational constraints baked into the core. Clean Architecture is influential across many language ecosystems and is frequently cited alongside Domain-Driven Design in discussions of how to structure large, long-lived applications, though critics note that its strict layering and heavy use of interfaces/DTOs can introduce significant boilerplate for smaller or simpler applications where the flexibility payoff isn't needed.

Key Concepts

  • Organizes code into concentric layers: Entities, Use Cases, Interface Adapters, Frameworks/Drivers
  • Governed by the 'Dependency Rule' — dependencies point strictly inward, never outward
  • Business rules (Entities, Use Cases) have zero knowledge of databases, frameworks, or UI
  • Achieves the Dependency Inversion Principle at the architectural level via inward-facing interfaces
  • Synthesizes ideas from hexagonal architecture, onion architecture, and DCI
  • Enables testing core business logic without a running database, server, or UI
  • Treats framework and database choices as replaceable, deferred implementation details
  • Described by Robert C. Martin in his 2017 book Clean Architecture

Use Cases

Structuring large, long-lived applications expected to evolve significantly over time
Isolating core business rules for fast, dependency-free unit testing
Deferring technology decisions (framework, database) until later in a project's lifecycle
Supporting multiple delivery mechanisms (web, CLI, mobile) over the same core logic
Enterprise applications where business rules must remain stable across framework upgrades
Codebases practicing Domain-Driven Design that need a matching architectural structure

Frequently Asked Questions

From the Blog