Skip to content
BENIBIX Learn

Clean Architecture

Development🏗️ ArchitectureArchitecture Styles

Also known as Onion Architecture, Uncle Bob Architecture

The rules of the business sit in the middle. Tools stay at the edge.

Think of it like

Think of it like an onion. The most important part is in the middle, safe from the outside.

Example

Lucy's pricing rules live in plain code with no database calls. Her team moves from one database to another, and not one pricing line changes.

Why it matters

The rules are what make a business unique. Keeping them apart from tools means they outlive those tools.

Definition

Clean architecture puts the business rules at the center of an app. The database, the web framework and the screens sit in outer rings. The key rule is that code only points inward: the center knows nothing about the outer rings. So you can swap a database or framework without touching the rules. Robert C. Martin described it in 2012.

Common mistake

Adding every layer from the diagram to a small app. Four folders for twenty lines of code is too much.

Key takeaways

  1. 1
    Rules in the center. The heart of the app.
  2. 2
    Point inward. Center knows nothing outside.
  3. 3
    Swap the tools. Rules stay the same.

Compare