Skip to Content
Mengty Learns
Architecture

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.

explanationbeginnerTested with typescript 7.0.2Updated Nov 27, 2026

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

TL;DR

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:

  1. Level 1 — System Context: your system as one box, surrounded by its users and external systems.
  2. 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.)
  3. Level 3 — Components: zoom inside one Container to show its logical modules/packages.
  4. 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

Overview of C4 Model: Zooming from Context to Code. 5 steps.
Overview5 steps in this flow

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 1 (Context): Who uses Mengty Learns and what external systems it touches.

Level 2 — Containers (Mengty Learns)

Level 2 (Containers): Static export bundle, generated cards.json, and browser localStorage (zero backend).

Level 3 — Components (Web App Container)

Level 3 (Components): Major internal modules inside the static Next.js application.

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

When to use
  • 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.
When to avoid
  • 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

Pros
  • Clear, hierarchical vocabulary shared by product, ops, and engineering.
  • Levels 1 and 2 change slowly, so diagrams stay accurate for months or years.
Cons
  • 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