The C4 Model: Zoom Levels for Architecture Diagrams

Most architecture diagrams fail in the same way. Boxes of different kinds sit next to each other, arrows have no labels, there's no legend, and a database, a team and a Java package all look the same. Everyone in the meeting nods, and everyone understands something different.

The C4 model, created by Simon Brown, fixes that with one simple idea: draw a system the way a map app shows a city, at a few fixed zoom levels. Each level has a clear audience and a clear set of things that belong on it. The four levels are Context, Containers, Components and Code.

Explore It Yourself

Below is Roarline, the fictional ticketing platform used across this documentation section. Click the boxes with a + to zoom in.

The Four Levels

LevelShowsFor whomWorth drawing?
1. System contextYour system as one box, the people who use it and the systems it depends onEveryone, including non-technical peopleAlways
2. ContainersThe apps, services, databases and queues that make up the system, and how they communicateDevelopers, operations, architectsAlmost always
3. ComponentsThe major building blocks inside one container, such as modules or servicesDevelopers of that containerOnly for containers complex enough to need it
4. CodeClasses, interfaces, tablesDevelopers working on a specific partRarely; generate it from the code if you need it

"Container" doesn't mean Docker

In C4, a container is anything that needs to run or store data on its own: a web app, a mobile app, a backend service, a database, a message queue, a serverless function. It often happens to run in a Docker container, but that's a coincidence of naming. If you could deploy it, start it or back it up separately, it's probably a container.

When to Stop Zooming

Most teams get the most value from levels 1 and 2. They change slowly, they fit on one screen, and they answer the questions new team members actually ask. Draw level 3 only for the containers where people regularly get lost, like Roarline's Application. Level 4 goes out of date the moment someone refactors, so let your IDE draw it when you need it.

A good test: if a diagram needs a verbal explanation every time you show it, it is either missing labels or mixing levels.

Rules for Diagrams That Explain Themselves

C4 and arc42

C4 and arc42 fit together naturally. arc42 says where things go; C4 says how to draw them.

C4 diagramarc42 section
System context3. Context and Scope
Containers and components5. Building Block View (level 1 and 2)
Dynamic diagram (a numbered flow between elements)6. Runtime View
Deployment diagram (containers mapped to infrastructure)7. Deployment View

Diagrams as Code

Diagrams drawn by hand rot quickly. Describing the model as text lets you review it in pull requests, generate every level from one source, and keep names consistent. This is how part of Roarline looks in the Structurizr DSL:

workspace "Roarline" {
  model {
    fan = person "Fan" "Buys tickets for live events"
    psp = softwareSystem "Payment provider" "Charges and refunds cards" "External"

    roarline = softwareSystem "Roarline" "Ticketing platform" {
      webShop = container "Web shop" "Fans browse and buy" "TypeScript, React"
      app = container "Application" "All business logic" "Java, Spring Boot"
      db = container "Database" "One schema per module" "PostgreSQL" "Database"
    }

    fan -> webShop "buys tickets"
    webShop -> app "calls" "JSON/HTTPS"
    app -> db "reads and writes" "SQL"
    app -> psp "charges" "HTTPS"
  }

  views {
    systemContext roarline {
      include *
      autoLayout
    }
    container roarline {
      include *
      autoLayout
    }
  }
}

Other popular options are the C4 extension for PlantUML and the C4 diagram types in Mermaid. The interactive diagram on this page works the same way: it is generated from a small data model, and automated tests check that every arrow connects two boxes that actually exist.

Key Takeaways

Further Reading

Case study: RoarlineGoals, decisions and incidents behind the system in these diagrams.