Drawing clean architecture diagrams in C4 with PlantUML
C4 is a methodology that gives architecture diagrams a fixed storyboard; PlantUML is its best carrier. Here’s the shortest path from zero to productive.
What is C4
C4, from Simon Brown, splits architecture into four zoom levels:
| Level | View | Audience |
|---|---|---|
| 1 — System Context | What value does the system provide? | Any stakeholder |
| 2 — Container | Which independently-deployable units make it up? | Architects / ops |
| 3 — Component | What modules live in a container? | Developers |
| 4 — Code | Class diagram inside a module (optional) | Developers |
Core idea: no single diagram explains everything; layered zoom handles it.
The toolkit: C4-PlantUML
C4 has an official PlantUML implementation:
1 | @startuml |
C4-PlantUML adds on top of PlantUML:
Person/System/System_Ext— humans or external systemsContainer/ContainerDb/ContainerQueue— deployable unitsComponent/ComponentDb— modules inside a containerRel/Rel_Back— relationshipsSystem_Boundary/Container_Boundary— boundaries
Internal networks: vendor it
!include of remote URLs often times out behind corporate networks. Vendor it:
1 | git clone --depth=1 https://github.com/plantuml-stdlib/C4-PlantUML.git source/plantuml/c4 |
Then:
1 | !includeurl https://raw.githubusercontent.com/.../C4_Container.puml ❌ |
Add a CI step to keep vendored C4 in sync.
Full example: all 4 levels
Level 1 — System Context
1 | @startuml |
Level 2 — Container
1 | @startuml |
Level 3 — Component
1 | @startuml |
Level 4 — Code (optional)
Use plain class diagrams:
1 | @startuml |
C4 vs off-the-shelf component diagram
| Dimension | Plain component diagram | C4 |
|---|---|---|
| Zoom levels | Single, free | 4 fixed levels |
| Boundaries | Free hand-drawn | System_Boundary standard |
| Relationship types | Any | Rel standardized + labeled |
| Renderer | Native PlantUML | C4-PlantUML stdlib |
| Learning curve | Low | Medium (4-level concept first) |
| Use case | Quick sketch | Long-term team doc |
C4’s biggest value: different people draw similar-looking diagrams, which lowers the cost of team communication.
Practical tips
Layout direction
1 | LAYOUT_TOP_DOWN() ! default |
Colors and theme
1 | UpdateElementStyle("c4model:boundary", $bgColor="#FAFAFA", $borderColor="#2F4858") |
Dark background:
1 | UpdateElementStyle("c4model:boundary", $bgColor="#161B22", $borderColor="#58A6FF") |
Multi-zoom in one image
Level 2 with LAYOUT_TOP_DOWN() + LAYOUT_WITH_LEGEND() renders cleanly for multi-zoom slides.
My team’s practice
4 levels, 4 files:
1 | docs/architecture/ |
CI auto-renders SVG:
1 | - run: | |
Each render commits back. New hires see Level 1/2/3 and grok the system in 5 minutes.
Common mistakes
- Level 1 too detailed — Context should have 3-6 elements. More than that and it’s really a Level 2.
- Drawing all 4 levels for every system — small systems need only Level 2; only go to Level 3 for complex distributed systems.
- No labels on relationships — every
Rel(A, B)should say what the interaction is. - Wrong choice of Container — Container is a “deployable, separate process” unit. One Go binary is a Container; a goroutine inside it is not.
- Forget to vendor — remote
!includeoften fails on internal networks; CI failure is a good teacher.
Gotchas
- Latest tag isn’t always default GitHub branch — pin to a v2.x tag.
ShowPerson/HidePersoncontrols person display level — handy on complex diagrams.AddRelTagstyles relationships:AddRelTag("async", $lineColor="#888", $lineStyle=DashedLine), thenRel(..., "async")applies it.
When not to use C4
- Flow / state diagrams — sequence or state, not C4.
- Marketing deck illustrations — C4 is too clean, lacks visual punch.
- Diagrams with 1-2 elements — overkill; a single box + arrow is fine.
TL;DR
C4 gives architecture diagrams a fixed grammar. PlantUML is its best carrier. Four zoom levels mean everyone draws similar-looking diagrams — and diagrams that humans can read are diagrams that earn their keep.
- Title: Drawing clean architecture diagrams in C4 with PlantUML
- Author: puml.online
- Created at : 2026-07-29 14:50:00
- Updated at : 2026-08-14 21:34:29
- Link: https://puml.online/blog/plantuml-c4-architecture-en/
- License: This work is licensed under CC BY-NC-SA 4.0.