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