Definition: Software architecture pattern by Robert C. Martin that enforces separation of concerns through concentric layers, isolating business logic from frameworks and databases.
— Source: NERVICO, Product Development Consultancy
What is Clean Architecture
Clean Architecture is a software architecture pattern proposed by Robert C. Martin (“Uncle Bob”) that organizes code into concentric layers with one fundamental rule: dependencies always point inward. The innermost layer contains pure business logic, completely isolated from frameworks, databases, and delivery mechanisms like APIs or graphical interfaces.
The goal is to make technology decisions (which database to use, which web framework to choose) implementation details that can be changed without affecting business rules.
How it works
The architecture divides into four main layers. At the center are the Entities, representing fundamental business rules. The next layer contains Use Cases, which orchestrate data flow between entities. Then come Interface Adapters, which convert data between the format used by use cases and the one needed by external mechanisms. The outer layer holds Frameworks and Drivers: the database, the web server, the user interface.
The dependency rule states that code in an inner layer can never know about or depend on anything in an outer layer. This dependency inversion is achieved through interfaces defined in inner layers and implemented in outer ones.
Why it matters
Clean Architecture allows teams to work in parallel on different layers without conflicts. It simplifies unit testing because business logic does not depend on infrastructure. And when the time comes to change databases, migrate to another framework, or expose a new API, the impact is confined to the outer layers.
Practical example
A billing system implements the rule “apply 21% VAT to domestic invoices” as an Entity. The “Create Invoice” use case orchestrates validation and calculation. An adapter converts the invoice into the format PostgreSQL needs to persist it. If the team migrates to MongoDB tomorrow, only the adapter changes. The 21% VAT rule remains untouched.