Skip to content

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.

Four levels of zoom1. Context shows the system as one box, with the people and systems around it. Anyone can read it. 2. Containers zoom into the system to show the separately deployable or running parts and how they talk. 3. Components and code zoom further into a single container, for the developers working on it. 1. System contextsystem, users, neighbors 2. Containersapps, databases, queues3. Componentsinside one containerDeploymentwhere containers run Dynamicone flow, step by step 4. Codeclasses, generated123
Four levels of zoom Most teams only need the first two; draw levels 3 and 4 only where they add value.
  1. Context shows the system as one box, with the people and systems around it. Anyone can read it.
  2. Containers zoom into the system to show the separately deployable or running parts and how they talk.
  3. 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.

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.

Container diagram: a lending platformLending platform Borrowerperson Credit bureauexternal system Email providerexternal system Web appReact, TypeScript Lending APIJava, Spring Boot DatabasePostgreSQL NotifierJava worker Message brokerKafka topicsJSON over HTTPS
Container diagram: a lending platform A fictional example. Every box is a separately running thing, labeled with its technology.
  • 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.
  • 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.

For enterprise-wide capability or process modeling, use a notation built for it, such as ArchiMate or BPMN. C4 is for software systems.

  • 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.

Written and edited by Abhinav Taduka, enterprise software architect.