The C4 model
C4 is a way to describe software architecture as a set of maps at different zoom levels, created by Simon Brown. This page is a short introduction; the reference is c4model.com.
Most architecture diagrams are boxes and arrows with no agreed meaning: is that box a server, a library, a team? C4 fixes this with a small set of abstractions and one diagram per zoom level. Like Google Maps, you zoom in only where it helps.
Abstractions
| Level | Abstraction | What it is | Examples |
|---|---|---|---|
| 1 | Person | A human user or role, not an individual. | Customer, Back-office agent |
| 1 | Software system | Something that delivers value to people, owned by one team or organisation. | Your product, a payment provider, an ERP |
| 2 | Container | A separately deployable or runnable unit that executes code or stores data. Not a Docker container in the strict sense. | Web app, mobile app, API, worker, database, queue |
| 3 | Component | A grouping of related functionality behind an interface, inside one container. | Module, package, service class |
| 4 | Code | Classes, functions, tables. | Usually generated by your IDE: not supported here. |
Each element has a name, a short description of its responsibility and, for containers and components, a technology. Relationships link elements with a verb phrase ("Places orders using") and, between containers, a protocol ("HTTPS/JSON").
The diagrams
Each view shows one level, plus the elements directly connected to it. All views below come from the same file, examples/online-banking.json.
Level 1: System context
The big picture, for everyone, technical or not: the system, its users and the systems it depends on.
Level 2: Containers
Inside the system: what runs or is deployed separately, and how the pieces talk. The dashed frame is the boundary of the system.
Level 3: Components
Inside one container: its main building blocks. Draw this level only where it helps; many teams stop at containers.
Supplementary diagrams
- System landscape: every person and software system of the organisation, with no central system.
- Dynamic: one scenario, step by step. Each numbered step follows a relationship of the model.
C4 also defines deployment diagrams. They are not supported yet.
Notation used here
C4 is notation independent. This runtime draws:
- Blue for what belongs to the systems you model, a little lighter at each level down (person, system, container, component);
- Grey for elements marked
external: owned by someone else; - a dashed frame for the boundary of the system or container being zoomed into, and for groups;
- the element type and technology under the name, in brackets:
[Container: Go]; - relationship labels with the description, then the technology in brackets;
- a legend under each diagram.
The colour belongs to the element, not to the view: an element looks the same in every diagram. Tags and styles change it on purpose.
Modelling tips
- System or container? If another team owns it, or users see it as a product of its own, it is a software system. If it is deployed as part of what you design, it is a container.
- Data stores are containers of the system that owns them, not systems. Tag them
Databaseand give the tag acylindershape. - Queues and topics are containers too (
pipeshape), not the broker that hosts them: one container per significant queue or topic, in the system that owns its message format. Draw publish and consume relationships through them. - Relationship direction follows the initiator: the caller points to the callee; a consumer points to the topic it reads from.
- Declare relationships at the most detailed level you model. Links between parents are derived automatically.
- Keep views small. Past ~20 elements, split the view or exclude elements;
inspectwarns about it.
Anti-patterns
- Mixing levels in one view (a component next to systems).
- A database or Kafka modelled as a software system.
- One container for the whole broker that every service talks to: it hides who exchanges what.
- Forgetting external systems: identity provider, payment, email, monitoring.
- Vague relationships ("Uses", "Calls") or no description at all.
- Going down to components before the containers are agreed.
Credits and further reading
The C4 model was created by Simon Brown, who maintains it at c4model.com. Its abstractions, diagram types and modelling advice are his; this page only summarises them. Read the original for the complete method.
- c4model.com: the official site.
- Structurizr, also by Simon Brown, and its DSL: the modelling language this JSON format borrows its concepts from.