C4 model: the four levels of C4 architecture diagrams

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.

Diagram of the four C4 levels stacked from system context down to code, with the note that most teams need only levels 1 and 2 highlighted. The levels are listed in the text version below.

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.

What is the C4 model?Copied!Link to this section

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).

What are the four levels of the C4 model?Copied!Link to this section

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).

C4 model example: a clinic booking systemCopied!Link to this section

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.

What is a C4 system context diagram?Copied!Link to this section

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).

System context diagram of a clinic booking system with a patient, a receptionist and two external systems, with the clinic booking system highlighted. The elements and relationships are listed in the text version below.

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.

What is a C4 container diagram?Copied!Link to this section

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).

Container diagram of the clinic booking system with a booking website, an API application, a database and a reminder worker inside the system boundary, with the API application highlighted. The elements and relationships are listed in the text version below.

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.

What is a C4 component diagram?Copied!Link to this section

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).

Component diagram of the API application with a bookings controller, a calendar service, a booking repository and a practice system client, with the practice system client highlighted. The elements and relationships are listed in the text version below.

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.

What is a C4 code diagram?Copied!Link to this section

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).

What notation does a C4 diagram use?Copied!Link to this section

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).

  • Person: a user, role or persona, such as the patient.
  • Software system: something that delivers value to its users, yours or one you depend on, such as the SMS gateway.
  • Container: an application or data store that has to run, such as the database.
  • Component: a part inside one container behind a clear interface, such as the calendar service.

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.

How do you draw C4 diagrams?Copied!Link to this section

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.

Start with the system contextCopied!Link to this section

  1. Name the system in scope and write one sentence on what it does.
  2. Add each kind of user as a person, and each system yours talks to.
  3. Label every line with what it does, in the direction it points.

Zoom into containersCopied!Link to this section

  1. List each app and data store that has to be running for the system to work.
  2. Give each one its technology and a one-line responsibility.
  3. Draw the system’s boundary around them, with people and external systems outside it.
  4. Label lines between containers with their protocol, such as JSON/HTTPS or SQL.

Go deeper only where it helpsCopied!Link to this section

  1. Draw a component diagram for a container that’s complex or changes often.
  2. Skip the code level, or generate it from your IDE when someone asks.
  3. Give every diagram a title and a key, then check each box against the code.

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.

How do you make a C4 diagram from Mermaid code?Copied!Link to this section

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:

C4Container title Container diagram: clinic booking system Person(patient, "Patient", "Books, moves and cancels dental appointments.") System_Boundary(booking, "Clinic booking system") { Container(web, "Booking website", "React", "Lets patients find a free slot and book it.") Container(api, "API application", "Node.js", "Checks free slots and takes bookings.") ContainerDb(db, "Database", "PostgreSQL", "Stores bookings and reminder settings.") Container(worker, "Reminder worker", "Node.js", "Texts patients the day before.") } System_Ext(pms, "Practice management system") System_Ext(sms, "SMS gateway") Rel(patient, web, "Books using", "HTTPS") Rel(web, api, "Makes API calls to", "JSON/HTTPS") Rel(api, db, "Reads and writes", "SQL") Rel(api, pms, "Reads calendars, writes appointments", "REST/HTTPS") Rel(worker, db, "Reads tomorrow's bookings", "SQL") Rel(worker, sms, "Sends texts through", "HTTPS")

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.

How is the C4 model different from UML and other architecture diagrams?Copied!Link to this section

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.

Can AI draw C4 diagrams?Copied!Link to this section

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:

Read this repository and draw its C4 container diagram on a new Whimsical board, as Mermaid C4Container code. Put the system boundary around every application and data store that has to run, each with its technology and a one-line responsibility. Show the people who use the system and the external systems it calls outside the boundary. Label every relationship with what it does and its protocol, never just "Uses". Give the diagram a title. If you can't tell from the code whether something runs on its own, list it as an open question instead of guessing.

Frequently asked questionsCopied!Link to this section

What does C4 stand for?

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.

Is a container in the C4 model a Docker container?

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.

Is the C4 model good?

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.

Does the C4 model replace UML?

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.

How many C4 diagrams does a system need?

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.

What tools can you use to draw C4 diagrams?

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

Related articles