The C4 Model: Context, Container, Component, Code
Visualize software architecture at four zoom levels—System Context, Containers, Components, and Code—applied to Mengty Learns itself.
TL;DR
The C4 model zooms into a system like Google Maps across four levels: Context (who uses it), Container (deployable apps & stores), Component (internal modules), and Code (classes). Below, we map Mengty Learns itself using C4.
Intent
Draw architecture diagrams at a consistent level of abstraction so stakeholders, DevOps engineers, and developers each get the exact zoom level they need without a wall of boxes and arrows.
Problem
Ad-hoc architecture diagrams mix "Customer", "Kubernetes Ingress", "PostgreSQL", and "OrderValidator.ts" on the same slide. Product managers get lost in class names, and engineers still don't know which process talks to which database.
Solution
Simon Brown's C4 model defines four hierarchical zoom levels:
- Level 1 — System Context: your system as one box, surrounded by its users and external systems.
- Level 2 — Containers: zoom inside the system to show separately deployable apps, static bundles, APIs, and data stores. (Note: in C4, "Container" means a deployable unit, not specifically Docker.)
- Level 3 — Components: zoom inside one Container to show its logical modules/packages.
- Level 4 — Code: zoom inside one Component to show classes/functions (usually auto-generated or skipped).
Real-world analogy
▶ Flow: watch it work
C4 Model: Zooming from Context to Code
Press Start or tap any step dot to trace the path.
▸All steps (5)
Structure: Mengty Learns in C4
Level 1 — System Context (Mengty Learns)
Level 2 — Containers (Mengty Learns)
Level 3 — Components (Web App Container)
Code
At Level 4 (Code), you inspect the actual TypeScript types inside the Flow & Diagram component—for example, FlowNode in components/diagram/types.ts:
// Level 4 detail: actual shape in components/diagram/types.ts (read-only reference)
export interface C4DiagramNode {
id: string;
label: string;
subtitle?: string;
rank?: number;
order?: number;
}When to use / when to avoid
- Onboarding new engineers—Levels 1 and 2 explain the whole system in 5 minutes.
- Architecture reviews and ADRs where mixing deployment boxes with class names causes confusion.
- Maintaining hand-drawn Level 4 (Code) diagrams—they go stale on the next refactor; read the IDE instead.
How to implement
Draw Level 1 (Context) first
One box for your system, plus actors and external dependencies.
Draw Level 2 (Containers)
Show every deployable app, worker, queue, and database, with protocols (HTTPS, SQL).
Add Level 3 (Components) only where needed
Zoom into core services to show module boundaries; skip trivial CRUD containers.
Pros / Cons
- Clear, hierarchical vocabulary shared by product, ops, and engineering.
- Levels 1 and 2 change slowly, so diagrams stay accurate for months or years.
- Level 4 diagrams rot quickly if drawn manually.
- The word "Container" occasionally confuses newcomers who think of Docker.
Relations
Check yourself
Check Yourself
1. In the C4 model, what does 'Container' mean at Level 2?
2. Which C4 level is usually skipped in manual documentation because it goes stale fastest?
Sources
Related Notes
Queues & Asynchronous Work
Decouple slow work from HTTP requests with queues vs pub/sub, at-least-once delivery, idempotency keys, exponential backoff retries, and dead-letter queues.
OWASP Top 10 (2025) Summary
Summary of the current OWASP Top 10:2025 web application security risks, what changed from 2021, and practical mitigations.