Topic 045 / Core
UML and architecture modeling, including the C4 model
Chapter 4.2 · Modeling and Communicating Design
What and why
As a system grows, verbal descriptions of its structure diverge from reality, and different audiences need different zoom levels — an executive does not want a class diagram, and a new engineer cannot onboard from one paragraph. UML is a shared diagram vocabulary (class, sequence, state, and others); the C4 model is four nested levels of a single notation — context, container, component, code — where each level answers one audience's question at one zoom. Builds on: → 14 (software architecture fundamentals).
Diagram
| Level | Answers | Shows | Audience |
|---|---|---|---|
| Context | What is this system, and who/what uses it? | The system as one box, plus users and external systems | Anyone, including non-engineers |
| Container | What are the deployable/runnable units inside it? | Web app, API, database, queue (≈ HLD, → 12) | Engineers, architects |
| Component | What are the modules inside one container? | The internal structure of one container (≈ LLD, → 13) | The team owning that container |
| Code | What are the classes/interfaces inside one component? | Class diagrams — drawn rarely; the code itself is usually clearer | That component's own developers |
How it works
- Decide the question and the audience first — the zoom level follows from that, not from habit.
- Draw the Context diagram: the system as one box, the people and external systems around it, nothing inside.
- Zoom to Container only for the containers relevant to the current question — not every container the system will ever have.
- Zoom to Component only when one container's internals are contested or confusing enough to need a picture.
- Stop before Code level in most cases: a class diagram goes stale the moment the code changes, and the code is already the most accurate diagram of itself.
Practical example
(illustrative). For the task manager: a Context diagram shows one box ("Task Manager") with a User and an Email Provider around it; a Container diagram, drawn only when discussing deployment, shows a Web App, an API, and a Postgres database — three containers, no more detail than the question requires.
When to use it
- Use when: onboarding a new engineer, running a cross-team design review, or writing an ADR (→ 57) that needs a picture instead of a paragraph.
- Avoid when: a single-service, single-audience situation is simple enough that a one-paragraph description says the same thing with less upkeep.
- Failure scenarios: one diagram trying to answer every question at once, becoming illegible; a Code-level class diagram committed once and never updated, actively misleading anyone who trusts it.
- Simpler alternative: a short paragraph, for a system small enough that nobody disagrees about its shape.
Practice
(20–30 min; no lab services — paper or any diagramming tool). Draw the Context and Container diagrams for the task manager (Project 1): one box for the system, its users and any external system (email) at Context level; Web App, API, and database as containers. Done when someone unfamiliar with the system can name every container and what talks to what using only the diagram.
Key takeaway
C4 gives each audience the right zoom level, with Context always first and Code level drawn rarely. Done when you can: pick the right C4 level for a given question without defaulting to the most detailed one. Used next in → 46 (sequence diagrams zoom into one interaction), → 57 (ADRs cite these diagrams instead of restating them).
References
C4 model — see references.md.
Source directory