Documenting architecture with C4
Most architecture diagrams fail for the same reason: they mix levels of detail. One box is a whole company system, the next is a database table, arrows mean five different things, and there’s no key. The C4 model, created by Simon Brown, fixes this with a simple idea borrowed from maps: zoom levels. Each diagram shows one level of detail, and you zoom in only where someone needs more.
C4 is notation-independent and tool-independent. It works on a whiteboard, in a drawing tool or as diagrams-as-code.
The four levels
Section titled “The four levels”- Context shows the system as one box, with the people and systems around it. Anyone can read it.
- Containers zoom into the system to show the separately deployable or running parts and how they talk.
- Components and code zoom further into a single container, for the developers working on it.
| Level | Shows | Audience | How often you need it |
|---|---|---|---|
| 1. System context | Your system as one box; the people who use it; the other systems it depends on | Everyone, including non-technical stakeholders | Always |
| 2. Container | Applications, services, databases, queues and file stores, with technology choices and how they communicate | Architects, developers, operations | Almost always |
| 3. Component | The major building blocks inside one container and their responsibilities | Developers of that container | When the container is complex |
| 4. Code | Classes, interfaces, tables | Developers | Rarely; generate it from code if needed |
C4 also has supporting diagrams: system landscape (all systems in the organization), deployment (where containers run, such as clusters and regions) and dynamic (the steps of one flow).
“Container” in C4 means anything that runs or stores data on its own, such as a web app, an API, a database or a serverless function. It predates and isn’t the same as a Docker container.
Example: a container diagram
Section titled “Example: a container diagram”Here’s a level 2 diagram for a fictional lending platform. External people and systems sit outside the boundary; each box names its technology; each arrow says what it carries.
How it works
Section titled “How it works”- One diagram, one level, one purpose. Give every diagram a title that says its level and scope.
- Every element gets a name, a type and a short description; containers also name their technology.
- Every arrow is one-way and labeled with what it does or carries (“reads and writes orders”, “JSON over HTTPS”).
- Include a key explaining shapes, colors and line styles.
- Keep diagrams as code where possible. Structurizr DSL, PlantUML’s C4 library and Mermaid all support C4, so diagrams live next to the code and change in the same pull request.
- Model once, view many. Tools like Structurizr let you define elements once and generate every view, so the diagrams never contradict each other.
- Readable by mixed audiences, because each level is pitched at one audience.
- Quick to learn: a team can be productive with it in an hour.
- Consistent across teams, which makes architecture reviews faster.
- Static structure only; behavior and runtime detail need dynamic or sequence diagrams.
- Doesn’t cover enterprise views like business capabilities or value streams. Pair it with an enterprise approach such as TOGAF or ArchiMate.
- Diagrams still rot if they’re not kept next to the code.
When to use it
Section titled “When to use it”- Documenting any software system for developers, architects and stakeholders.
- Onboarding new team members and preparing for architecture reviews.
- Alongside architecture decision records, which explain why the diagrams look the way they do.
When to avoid it
Section titled “When to avoid it”For enterprise-wide capability or process modeling, use a notation built for it, such as ArchiMate or BPMN. C4 is for software systems.
Common pitfalls
Section titled “Common pitfalls”- Level 4 diagrams drawn by hand, out of date within a week.
- Unlabeled arrows and no key.
- Mixing levels, for example a database table next to an external system.
- Calling a Kubernetes pod a “container” in a C4 diagram without explaining which meaning you intend.
Related patterns
Section titled “Related patterns”- See it applied: Example Lending, context, container, component and deployment views for one platform
- Quality attributes and NFRs
- Trade-off analysis
- ADR generator
- TOGAF and the ADM
Further reading
Section titled “Further reading”- Simon Brown, The C4 model for visualising software architecture (opens in a new tab)
- Structurizr (opens in a new tab), diagrams as code for C4
- Mermaid, C4 diagrams (opens in a new tab)
Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.