The four levels of C4 diagrams, one system drawn at each level, and C4 Mermaid code you can paste onto a board.
The C4 model is a way to diagram software architecture at four levels of detail (system context, containers, components and code), where each level zooms into one part of the level above. Simon Brown created it so developers could draw maps of their code instead of a muddle of boxes and lines. To use it, draw a system context diagram first, then a container diagram, and stop at the level where more detail stops helping your readers.
Figure 1The four levels of the C4 model. Each level zooms into one box of the level above. The highlighted box is the rule of thumb: most teams only need levels 1 and 2. Draw levels 3 and 4 only when they add value.
Highlighted: levels 1 and 2, most teams need only these two. Draw them for every system. Levels 3 and 4: draw them only when they add value, and generate code diagrams from your IDE.
The C4 model is a set of four diagram types for describing one software system at different levels of zoom, plus a small vocabulary for what goes in them: people, software systems, containers and components. Its creator calls it “an easy to learn, developer friendly approach to software architecture diagramming” (c4model.com).
The problem it fixes is familiar. Ask a developer to diagram their system and, in Simon Brown’s words, “you’ll likely get a confused mess of boxes and lines” (c4model.com): no title, unlabelled arrows, a database next to a whole product next to a class. C4 gives every box a type and every diagram one level, which is why he describes it as “Google Maps for your code” (InfoQ). The roots go back to 2006-2009, the C4 name to 2011, and he has taught it to more than 10,000 people in about 40 countries (C4 FAQ).
The four levels of the C4 model are the system context diagram, the container diagram, the component diagram and the code diagram. Each one zooms into a single box of the level above, and each is for a different audience, from everyone down to the developers working on one part:
Level | What it shows | Who it’s for | When to draw it |
|---|---|---|---|
Level 1: System context | The system as one box, its users and the systems it talks to | Everyone, technical or not | Always |
Level 2: Container | The apps and data stores inside the system, their technology and how they talk | Architects, developers and operations | Always |
Level 3: Component | The parts inside one container and what each one does | Architects and developers | Only when it adds value |
Level 4: Code | Classes, interfaces or tables inside one component | Architects and developers | Rarely: generate it from your IDE |
The “when to draw it” column comes from the official site, which says the system context and container diagrams “are sufficient for most software development teams” (c4model.com). On top of the four, the C4 model has three supporting diagrams: a system landscape diagram (several systems at once), a dynamic diagram (how elements work together at runtime for one feature) and a deployment diagram (how containers map onto servers or cloud services in an environment such as production).
Here’s one system drawn at three levels. A dental clinic lets patients book appointments online and texts them a reminder the day before. The clinic’s calendars live in a practice management system it buys, not builds. Each figure zooms into the highlighted box of the one before.
A C4 system context diagram shows your system as a single box in the middle, the people who use it, and the other software systems it depends on or that depend on it. It leaves out technology and internals on purpose, so anyone can read it, and the official site recommends one for every team (c4model.com).
Figure 2C4 system context diagram: clinic booking system. The clinic booking system, highlighted, is the system in scope: the only box the clinic builds. The receptionist never touches it directly, which is worth knowing before anyone designs a staff screen.
People
Software systems
A C4 container diagram zooms into the system and shows the applications and data stores it’s made of, the technology of each and how they talk to each other. It’s the diagram new developers and on-call engineers reach for first. Like the context diagram, it’s recommended for every team (c4model.com).
A container here is not a Docker container. The official definition starts with “Not Docker!” and goes on: “a container represents an application or a data store” that has to be running for the system to work (c4model.com).
Figure 3C4 container diagram: clinic booking system. Four containers inside the dashed boundary. The API application, highlighted, is the container Figure 4 zooms into: it's the one that talks to the practice management system.
Outside the system
Inside the clinic booking system (the dashed boundary)
A C4 component diagram zooms into one container and shows its main parts, what each is responsible for and how they depend on each other. A component is “a grouping of related functionality encapsulated behind a well-defined interface”, not a separately deployable unit (c4model.com). The official site says to draw a component diagram only if it adds value (c4model.com).
Figure 4C4 component diagram: clinic booking system, API application. Four components inside the API application. The practice system client, highlighted, is the only component that calls the practice management system, so a change to that vendor's API stays in one place.
Outside the API application
Inside the API application (the dashed boundary)
A C4 code diagram zooms into one component and shows how it’s built, usually as a UML class diagram or an entity relationship diagram. For the practice system client, it would show the client class and its request and response types. We didn’t draw one: the official site advises against code diagrams for long-lived documentation, “because most IDEs can generate this level of detail on demand” (c4model.com).
A C4 diagram can use any shapes and colors, because the model is notation independent. What it asks for is labels: every element has a name, its type, its technology and a one-line description, every line points one way and says what it does, and every diagram has a title and a key (C4 notation).
Most unclear C4 diagrams fail on the labels, not the boxes. The notation guide asks for labels that avoid “single words like, “Uses”” (C4 notation). Here are four labels as they often get drawn, and as Figures 3 and 4 draw them:
API application → Database: Uses
Relationship: API application reads and writes Database [SQL]
Worker → SMS: Uses
Relationship: Reminder worker sends texts through SMS gateway [HTTPS]
Backend
Element: API application [Container: Node.js]. Checks free slots and takes bookings.
Utils
Element: Practice system client [Component: TypeScript module]. Wraps the practice system's API.
Draw C4 diagrams from the outside in: a system context diagram first, then a container diagram, then a component diagram only for the containers that need one. Write the labels as you go, not at the end, because naming the type and technology of each box is where the arguments that matter happen.
In Whimsical, draw each level on its own board with shapes and connectors, or paste C4 Mermaid code and tidy the result. The four figures in this guide are boards you can copy and rename for your own system.
To make a C4 diagram from Mermaid code, start the code with a C4 keyword such as C4Container, declare each element with Person, System, Container or Component, and each relationship with Rel, then render it or paste it onto a board. Mermaid, a text syntax for diagrams, has five C4 types: C4Context, C4Container, C4Component, C4Dynamic and C4Deployment (Mermaid docs). The code lives next to your source, so the diagram can change in the same pull request as the system. This is Figure 3 as Mermaid:
Paste that code onto a Whimsical board with Command + V (Mac) or Control + V (PC) and you get editable shapes, not a picture: people, systems, containers and components inside their boundaries (Mermaid article). In our test with the code above, the boundary became a dashed group, the database a cylinder and the external systems gray, and every relationship kept its label and technology.
Two things don’t carry over. The paste lays the diagram out top to bottom and skips layout hints such as Rel_U and UpdateLayoutConfig, so expect to move a few boxes and untangle a crossing line by hand. And C4 isn’t among the diagram types that copy back out as Mermaid, so keep the code as the source and treat the board as the place you explain it.
The C4 model describes a system’s static structure at four fixed levels with any notation, UML is a standard notation with many diagram types for structure and behavior, and ad hoc boxes and lines have no agreed rules at all. C4 sits in between: more structure than a sketch, far less to learn than UML.
C4 model | UML | Ad hoc boxes and lines | |
|---|---|---|---|
Describes | Static structure, at four levels of zoom | Structure and behavior, in many diagram types | Whatever the author drew |
Notation | Any shapes, with a title, key and labelled lines | A fixed, standard set of symbols | None agreed |
To learn | Four element types | Many diagram types and symbols | Nothing, but every reader guesses |
Best for | Explaining one custom-built system to its team | Detailed design: classes, states, sequences | Quick whiteboard sketches |
The C4 FAQ is relaxed about mixing them: “If you’re using UML (or SysML, ArchiMate, etc) and it’s working for you, stick with it”, and add UML state or entity relationship diagrams next to C4 ones where you need them (C4 FAQ). If what you need is one picture of a whole cloud setup rather than levels, start from the architecture diagram template or the AWS architecture diagram template.
Yes. A coding agent such as Claude or Cursor can read a repository and draft a system context or container diagram, because containers usually show up in deployment files and relationships in the code that calls other services. We’d check every box before sharing it: a model will happily turn a folder name into a container, and a diagram that’s confidently wrong is worse than none.
With the Whimsical MCP, the agent can draw the diagram straight onto a board, from the same Mermaid C4 code you’d paste yourself. This prompt asks for Figure 3’s level, with the labelling rules from this guide:
C4 stands for the four diagrams at the core of the model: context (the system context diagram), containers, components and code. Simon Brown named the diagram types around 2010 and first used the C4 name in early 2011. The last C originally meant classes and was later renamed code.
No. In the C4 model, a container is an application or a data store that has to be running for the system to work, such as a web app, an API, a database or a scheduled job. A Docker container can hold a C4 container, but the two words mean different things.
Yes, for custom-built software that a team owns and has to explain. It takes four element types to learn, works with any notation or tool, and its first two levels cover what most teams need. Its FAQ names embedded systems and heavily customized products such as SAP or Salesforce as less suited, though context and container diagrams still help there.
No. The C4 model covers the static structure of a system, and its FAQ suggests adding UML diagrams, entity relationship diagrams or others for behavior, state and data. If your team already uses UML and it works, the advice is to stick with it. C4 suits teams that had fallen back to ad hoc boxes and lines.
Most systems need two C4 diagrams: one system context diagram and one container diagram, which the official site calls sufficient for most teams. Add a component diagram for a container that’s complex or changes often. When a diagram gets crowded, split it into several diagrams at the same level instead of squeezing everything onto one.
Any diagramming tool can draw C4 diagrams, because the model doesn’t depend on a notation or a tool. Teams that want diagrams as code use Structurizr, C4-PlantUML, Mermaid or D2 and keep the source next to their code. Teams that want to draw use a diagramming app or a whiteboard. Choose by who edits the diagrams and how long they need to last.
Start from the example
Copy the clinic booking system's container diagram and rename the boxes for your own system.
Make a free copy of the example