C4 diagrams
Draw software architecture as a small set of maps at different zoom levels,
one abstraction per map. Based on Simon Brown's C4 model
and Software Architecture for Developers. The point is communication: each
diagram tells a different part of the same story to a different audience, and
each one stands on its own without a narrative.
Not this skill (use instead)
- Domain modelling, ports/adapters, error design ->
architecture skill.
This skill draws and verifies the model; that one decides what to model.
- Decision rationale, ADRs, keeping docs from rotting ->
living-documentation
skill. C4 shows static structure; the why belongs in ADRs/a guidebook.
- Behaviour: business processes, workflows, state, data models. C4 is static
structure only. Use BPMN / UML state / sequence / ER instead.
The core in 30 seconds (sticky rules)
- Only two diagrams for most systems: System Context + Container. Add
Component only when it earns its place; Code almost never. Don't draw all four
by default.
- A Container is an app or data store that must be running - a web app,
SPA, mobile app, serverless function, database schema, S3 bucket. NOT a
Docker container. NOT a JAR/DLL/module/package. Deployment is a separate
diagram.
- A Component runs in the same process as its container - a grouping of
code behind an interface. Not independently deployable, not a folder/package.
Describe components by responsibility, never one box per source folder.
- One abstraction level per diagram. Never put components next to external
systems, or classes on a container diagram.
- Evidence-first when deriving from code. Every element traces to something
you read. Label Observed vs Inferred. Never invent actors, external
systems, or components. Misleading diagrams are worse than none.
- Every diagram needs a title + legend. Every element needs type +
technology + a one-line responsibility. Every arrow is one-directional,
specifically labelled, with a protocol on inter-container lines. No bare
"Uses" / "DB" / "Backend".
- A diagram you haven't rendered is not done. Render it, read the errors,
fix, repeat.
Decision tree
Designing a NEW system from a spec?
-> Elicit first (actors, external systems, boundaries), then model.
Hand design questions to the `architecture` skill. references/deriving-from-code.md (greenfield branch)
Documenting an EXISTING repo?
-> Evidence-first discovery loop. references/deriving-from-code.md
Which diagrams?
-> Context + Container always. Component only for the 1-2 containers where it
helps. Deployment when runtime topology matters. Dynamic sparingly, for one
tricky flow. Code almost never. references/c4-model.md
Which output format?
-> Default: Mermaid C4 (renders inline on GitHub/GitLab/VS Code, zero setup).
references/mermaid-c4.md
-> Serious multi-level model, long-lived docs, or repo already has a
workspace.dsl: Structurizr DSL as single source of truth, export to render.
references/structurizr-dsl.md
-> Escape hatches: D2 (best local layout) / C4-PlantUML (richest notation).
references/structurizr-dsl.md#alternatives
The C4 abstractions (condensed)
Person -> uses -> Software System -> made of Containers (apps + data
stores) -> made of Components -> made of Code.
| Diagram |
Scope |
Shows |
Audience |
| System Context |
one system |
the system + its users + external systems |
everyone |
| Container |
one system |
the apps/data stores inside + how they talk |
technical |
| Component |
one container |
components inside that container |
developers |
| Code |
one component |
classes/functions (usually generated) |
developers |
| Deployment |
one environment |
instances mapped onto infrastructure |
technical/ops |
| Dynamic |
one use case |
numbered runtime collaboration |
technical |
| System Landscape |
an org/dept |
portfolio map of many systems |
everyone |
Full definitions, the container/component landmines, and when to use each:
references/c4-model.md.
The metadata + relationship + legend contract, colours, and anti-patterns:
references/notation-and-quality.md.
Workflow
- Pick the entry mode - derive-from-code or greenfield
(references/deriving-from-code.md).
- Model the smallest useful set - Context + Container first. Resist scope
creep. Split a crowded diagram into several focused ones at the same level
rather than cramming.
- Choose format - Mermaid by default; Structurizr DSL when it's a real
multi-level model or one already exists.
- Render and verify -
scripts/render.sh <file> picks the renderer, runs
it, and reports errors. Fix until it renders cleanly. For Mermaid destined
for a README/PR, note it renders natively on GitHub with no tooling. Use
scripts/example-workspace.dsl as a known-good Structurizr DSL smoke test
or sample when checking local renderer setup.
- Self-review against the quality checklist
(references/notation-and-quality.md)
before presenting.
Companion: the software guidebook
Sibling-skill boundaries (architecture, living-documentation) are in "Not
this skill" above.
- The
Software Architecture for Developers "software guidebook" (Context,
Functional Overview, Quality Attributes, Constraints, Principles, Software
Architecture, External Interfaces, Code, Data, Infrastructure, Deployment,
Operation & Support, Decision Log) is the text companion these diagrams slot
into. arc42 is the other common one.
1---2name: c4-diagrams3description: C4 architecture diagrams - System Context, Container, Component, Code, plus Dynamic and Deployment views (Simon Brown's C4 model). Use whenever the user wants to draw, update, or review an architecture diagram, model or visualise a system's structure, reverse-engineer C4 from an existing codebase or repo, write or edit a Structurizr DSL workspace (workspace.dsl), or produce a Mermaid / PlantUML / D2 architecture diagram - even when they don't say "C4" (e.g. "diagram how this service fits together", "draw the containers for this repo").4---5
6# C4 diagrams
7
8Draw software architecture as a small set of **maps at different zoom levels**,
9one abstraction per map. Based on Simon Brown's [C4 model](https://c4model.com)
10and *Software Architecture for Developers*. The point is communication: each
11diagram tells a different part of the same story to a different audience, and
12each one stands on its own without a narrative.
13
14## Not this skill (use instead)
15
16- **Domain modelling, ports/adapters, error design** -> `architecture` skill.
17 This skill draws and verifies the model; that one decides *what* to model.
18- **Decision rationale, ADRs, keeping docs from rotting** -> `living-documentation`
19 skill. C4 shows static structure; the *why* belongs in ADRs/a guidebook.
20- **Behaviour: business processes, workflows, state, data models.** C4 is static
21 structure only. Use BPMN / UML state / sequence / ER instead.
22
23## The core in 30 seconds (sticky rules)
24
251. **Only two diagrams for most systems: System Context + Container.** Add
26 Component only when it earns its place; Code almost never. Don't draw all four
27 by default.
282. **A Container is an app or data store that must be *running*** - a web app,
29 SPA, mobile app, serverless function, database schema, S3 bucket. **NOT a
30 Docker container. NOT a JAR/DLL/module/package.** Deployment is a separate
31 diagram.
323. **A Component runs *in the same process* as its container** - a grouping of
33 code behind an interface. Not independently deployable, not a folder/package.
34 Describe components by **responsibility**, never one box per source folder.
354. **One abstraction level per diagram.** Never put components next to external
36 systems, or classes on a container diagram.
375. **Evidence-first when deriving from code.** Every element traces to something
38 you read. Label **Observed vs Inferred**. Never invent actors, external
39 systems, or components. Misleading diagrams are worse than none.
406. **Every diagram needs a title + legend. Every element needs type +
41 technology + a one-line responsibility. Every arrow is one-directional,
42 specifically labelled, with a protocol on inter-container lines.** No bare
43 "Uses" / "DB" / "Backend".
447. **A diagram you haven't rendered is not done.** Render it, read the errors,
45 fix, repeat.
46
47## Decision tree
48
49```text
50Designing a NEW system from a spec?
51 -> Elicit first (actors, external systems, boundaries), then model.
52 Hand design questions to the `architecture` skill. references/deriving-from-code.md (greenfield branch)
53
54Documenting an EXISTING repo?
55 -> Evidence-first discovery loop. references/deriving-from-code.md
56
57Which diagrams?
58 -> Context + Container always. Component only for the 1-2 containers where it
59 helps. Deployment when runtime topology matters. Dynamic sparingly, for one
60 tricky flow. Code almost never. references/c4-model.md
61
62Which output format?
63 -> Default: Mermaid C4 (renders inline on GitHub/GitLab/VS Code, zero setup).
64 references/mermaid-c4.md
65 -> Serious multi-level model, long-lived docs, or repo already has a
66 workspace.dsl: Structurizr DSL as single source of truth, export to render.
67 references/structurizr-dsl.md
68 -> Escape hatches: D2 (best local layout) / C4-PlantUML (richest notation).
69 references/structurizr-dsl.md#alternatives
70```
71
72## The C4 abstractions (condensed)
73
74`Person` -> uses -> `Software System` -> made of `Container`s (apps + data
75stores) -> made of `Component`s -> made of `Code`.
76
77| Diagram | Scope | Shows | Audience |
78|---|---|---|---|
79| **System Context** | one system | the system + its users + external systems | everyone |
80| **Container** | one system | the apps/data stores inside + how they talk | technical |
81| **Component** | one container | components inside that container | developers |
82| **Code** | one component | classes/functions (usually generated) | developers |
83| *Deployment* | one environment | instances mapped onto infrastructure | technical/ops |
84| *Dynamic* | one use case | numbered runtime collaboration | technical |
85| *System Landscape* | an org/dept | portfolio map of many systems | everyone |
86
87Full definitions, the container/component landmines, and when to use each:
88[references/c4-model.md](references/c4-model.md).
89
90The metadata + relationship + legend contract, colours, and anti-patterns:
91[references/notation-and-quality.md](references/notation-and-quality.md).
92
93## Workflow
94
951. **Pick the entry mode** - derive-from-code or greenfield
96 ([references/deriving-from-code.md](references/deriving-from-code.md)).
972. **Model the smallest useful set** - Context + Container first. Resist scope
98 creep. Split a crowded diagram into several focused ones at the same level
99 rather than cramming.
1003. **Choose format** - Mermaid by default; Structurizr DSL when it's a real
101 multi-level model or one already exists.
1024. **Render and verify** - `scripts/render.sh <file>` picks the renderer, runs
103 it, and reports errors. Fix until it renders cleanly. For Mermaid destined
104 for a README/PR, note it renders natively on GitHub with no tooling. Use
105 `scripts/example-workspace.dsl` as a known-good Structurizr DSL smoke test
106 or sample when checking local renderer setup.
1075. **Self-review against the quality checklist**
108 ([references/notation-and-quality.md](references/notation-and-quality.md#quality-checklist))
109 before presenting.
110
111## Companion: the software guidebook
112
113Sibling-skill boundaries (`architecture`, `living-documentation`) are in "Not
114this skill" above.
115
116- The `Software Architecture for Developers` "software guidebook" (Context,
117 Functional Overview, Quality Attributes, Constraints, Principles, Software
118 Architecture, External Interfaces, Code, Data, Infrastructure, Deployment,
119 Operation & Support, Decision Log) is the text companion these diagrams slot
120 into. arc42 is the other common one.