My account

Architecture Diagrams with the C4 Model

One huge diagram helps nobody. The C4 model draws the system at four zoom levels: system context, containers, components and code. Each level answers different questions for different readers. Every box has a name, a type and a job; every line has a label and a direction. Keep diagrams next to the code, as text, so they stay true.

Not reviewedWritten with AI helpReading time: 13 minOnline shop exampleFour zoom levelsDiagrams as code4+1 views

Author: bezzad

Contents

The problem: the diagram nobody understands

Our online shop has one “architecture diagram” on the wiki. It has 60 boxes, lines in every direction, three colors with no legend, and some boxes are apps, some are classes, some are teams.

A new developer looks at it for ten minutes and still cannot answer simple questions: “Which app do I change to add a payment method? Where is the order data stored?”

The problem is not the drawing tool. The problem is that one picture tries to answer every question for every reader.

The idea: zoom levels, like a map

A map of a country does not show the streets. A street map does not show the whole country. You zoom in when you need more detail.

The C4 model (by Simon Brown) applies this idea to software. It has four levels, and each level is for a different reader:

1. System contextour system andwho uses it2. Containersapps, databases,queues3. Componentsparts insideone app4. Codeclass Orderclass OrderLineIOrderRepositoryusually from the IDE,rarely drawnEveryoneDevelopers, opsOne teamOnly if usefulZoom in one level at a time, like a map. Each level has its own readers.
Each level zooms into one box of the level before.
  1. System context. Our system as one box, the people who use it, and the other systems it talks to. Readers: everyone, including the business.
  2. Containers. Inside our system: the things that run or store data. Web app, API, database, message broker, worker. Readers: developers, operations, security.
  3. Components. Inside one container: its main parts and their jobs. Readers: the team that builds this container.
  4. Code. Classes and their relations. Usually generated by the IDE; draw it only when it really helps.
A word about "container": In C4, a container is anything that runs or stores data on its own: a web app, a mobile app, an API, a database, a queue. It is not the same as a Docker container, although one often runs in the other.

Level 1: system context

Customer[Person]Support staff[Person]Online Shop[Software system]Sells products onlinePayment provider[External system]Shipping company[External system]Email service[External system]Browses and buysAnswers questionsTakes paymentsBooks deliverySends emails
The shop as one box. People on one side, other systems on the other. Every line says what happens.

This one diagram answers: who uses the system, and what does it depend on? It is the best diagram to start a project, to explain the system to a manager, or to discuss security borders.

Level 2: containers

CustomerOnline Shop [Software system]Web app[React]Pages for shoppingAPI[ASP.NET Core]Orders, cart, pricesOrders database[PostgreSQL]Message broker[RabbitMQ]Worker[.NET]Email service[External]Payment[External]usesJSON/HTTPSreads, writes"order placed"deliverssends confirmation
Inside the shop: what runs, what stores data, and how they talk. Technology is written on each box.

This is the diagram developers and operations use most. It shows:

  • Every app and data store, with its technology.
  • How they talk: HTTP, messages, database calls.
  • What is ours and what is external.

Level 3: components

Zoom into one container, for example the API. Its components could be: Cart, Ordering, Pricing, Payments adapter. Draw this only for containers where the inside is not obvious, and only as deep as the team needs.

Rules that make diagrams readable

  1. A title on every diagram. “Online Shop, containers, October 2026”.
  2. Every box has: a name, a type (person, system, container, component), the technology when it matters, and one short line about its job.
  3. Every line has: a direction and a label with a verb: “places orders”, “reads and writes”, “sends confirmation”. Add the protocol when it matters.
  4. A legend if you use colors or shapes. Colors must not be the only way to tell things apart.
  5. One level per diagram. Do not mix apps and classes in one picture.
  6. Fewer boxes. If a diagram needs more than about 20 boxes, split it.

Extra diagram types can help next to the four levels:

  • A dynamic diagram shows the order of steps for one scenario, for example “place an order”, with numbered lines.
  • A deployment diagram shows where containers run: servers, regions, clusters.

Diagrams as code

A diagram in a drawing tool is easy to forget. Diagrams written as text in the repository are reviewed in pull requests and change with the code. One model can create many views. For example, with the Structurizr DSL:

workspace {
  model {
    customer = person "Customer"
    shop = softwareSystem "Online Shop" {
      web = container "Web app" "Pages for shopping" "React"
      api = container "API" "Orders, cart, prices" "ASP.NET Core"
      db = container "Orders database" "" "PostgreSQL"
    }
    payment = softwareSystem "Payment provider"

    customer -> web "Browses and buys"
    web -> api "Calls" "JSON/HTTPS"
    api -> db "Reads and writes"
    api -> payment "Takes payments" "HTTPS"
  }
  views {
    systemContext shop { include * autolayout lr }
    container shop { include * autolayout lr }
  }
}

PlantUML and Mermaid also have C4 support. The tool matters less than the habit: diagrams live next to the code and are updated in the same pull request.

Other ways to describe architecture

C4 is one popular approach. You may meet others:

Logical viewWhat the system does:domain parts and their relationsDevelopment viewHow the code is organized:projects, modules, packagesProcess viewWhat runs at the same time:processes, threads, messagesPhysical viewWhere it runs:servers, regions, network+1 Scenariostie the views together
The 4+1 model looks at the same system from four sides, and scenarios check that the views fit together.
  • The 4+1 view model (Philippe Kruchten): logical, development, process and physical views, plus scenarios that walk through them.
  • Viewpoints and perspectives (Rozanski and Woods): a view for each group of stakeholders (functional, information, deployment …), and “perspectives” like security or performance that you check across all views.
  • UML. Useful pieces: sequence diagrams for the order of calls, deployment diagrams, sometimes class diagrams. Most teams use only a small part of it.
  • ArchiMate. A language for enterprise architecture: business processes, applications and technology in one model. Common in large organizations with TOGAF.
  • Flowcharts for business processes and decisions.
Question A good picture
Who uses the system and what does it depend on? C4 system context
What runs where, and with which technology? C4 containers, deployment diagram
In which order do the calls happen in checkout? Dynamic diagram or UML sequence diagram
How does the business process work? Flowchart, or an Event Storming timeline
How do business, apps and infrastructure fit across the company? ArchiMate

Common mistakes

Mistake Result The right way
One diagram for everything Nobody understands it. One level per diagram, one audience per level.
Boxes with only a name Readers guess what each box is. Name, type, technology and job.
Lines without labels “This connects to that” says nothing. A verb on every line, and a direction.
Colors without a legend Different readers see different meanings. A legend, and a title.
Diagrams only in a drawing tool Out of date after one month. Diagrams as code, next to the code.

Summary in six lines

  1. One diagram cannot serve every reader; draw zoom levels.
  2. C4 levels: system context, containers, components, code.
  3. A container is anything that runs or stores data on its own.
  4. Every box: name, type, technology, job. Every line: direction and a verb.
  5. Keep diagrams as code in the repository and update them with the code.
  6. Other tools exist: 4+1 views, viewpoints, UML, ArchiMate; choose by the question you want to answer.

Done reading this lesson?Mark it as finished so it shows in your lessons list and report card.