Skip to content
Mapyra, home Start free

Blog · Architecture

C4 diagram: context, containers and components explained

Mapyra team · · 7 min read

Quick answer

The C4 model, created by Simon Brown, describes software architecture in four zoom levels: context, containers, components and code. You start with the widest view and go deeper only where the audience needs it, using a few shapes and a clear legend.

UserBooking systemWeb applicationAPIDatabasePayment gateway
Figure: C4 container diagram: the user uses the web application, which calls the API, which writes to the database and integrates with a payment gateway.

A C4 diagram is a way to draw software architecture at several zoom levels, like a map you zoom into step by step. The model was created by Simon Brown and takes its name from the four levels: Context, Containers, Components and Code.

What is the C4 model?

Many architecture diagrams fail because they try to show everything at once: users, servers, modules and classes on the same screen. C4 solves this by splitting the drawing into levels. Each level has its own audience and its own question, and you only go down to the next one when you need to.

The four levels

  1. Level 1, System context. Shows your system as a single box, the people who use it and the other systems it talks to. Question: what is this and who relates to it? It works for anyone, technical or not.
  2. Level 2, Containers. Opens the system box and shows the parts that run: web application, API, mobile app, database, queue. Here "container" means a unit that runs code or stores data, not necessarily a Docker container. Question: what is it made of and how do the parts talk? This is the level used most day to day.
  3. Level 3, Components. Opens one container and shows its inner blocks: controllers, services, modules. Question: how is this container organized? It serves the development team.
  4. Level 4, Code. Class or entity diagrams. In practice, they almost always come from the IDE and are rarely worth drawing by hand.

When to use each level

  • Presentation to a client or management: level 1.
  • Developer onboarding and design review: levels 1 and 2.
  • Discussing the internal structure of a complex service: level 3 for that service only.
  • Lean documentation: levels 1 and 2 for the whole system, level 3 only where there is risk.

How to draw it in 5 steps

  1. Pick the level and the audience. Write the level and the system name in the title.
  2. Start with people and external systems. Who uses it? What does it integrate with? Put them at the edge.
  3. Draw the boxes for that level. Each box gets a name, a type and one sentence on its responsibility, for example "API, Node.js, order rules".
  4. Connect with labeled arrows. Each arrow has a verb and, at level 2, the protocol: "reads orders (HTTPS/JSON)".
  5. Add a legend. Say what each shape and color means. Without a legend, the reader guesses.

Example: a booking app

At level 1: the customer uses the booking system, which sends reminders through a messaging service and charges through a payment gateway. At level 2: the system opens into a web application, an API, a database and a reminder queue; the API writes to the database, publishes to the queue and calls the gateway. At level 3, only if the team needs it, you open the API and show the scheduling, billing and notification modules.

Common mistakes

  • Unlabeled arrows. "Uses" says nothing. Say what travels and over which protocol.
  • Mixing levels on one screen. If a database appears next to a class, the drawing lost its focus.
  • Forgetting the external system. Payment, email and third-party login are part of the context.
  • Drawing everything at level 3. Too much detail goes stale within weeks. Keep levels 1 and 2 current first.

C4 pairs well with other drawings: to see how services are split, read about microservices architecture; for an overview of diagram types, see the guide to the software architecture diagram.

How to keep the drawing current

C4 only helps if it keeps pace with the system. Put the diagram review into your delivery routine: when a new container appears or an integration changes, the drawing changes the same day. Keep a clear title on each board with the level, the system and the date of the last review, and always use the same legend. That way, whoever opens the drawing months later knows what they are looking at and how far to trust it.

How to do this in Mapyra

Mapyra has ready-made templates for the first two levels: C4 nível 1: contexto do sistema and C4 nível 2: contêineres. Start with the containers one, swap the names for your system's, add pieces with icons and connect them with labeled arrows. Open a board in Mapyra and share the link so the team can review it together.

Frequently asked questions

Is C4 an official notation like UML?

No, it is not a rigid notation. C4 defines abstraction levels and good legend practices, but leaves shapes and colors free. That is why it works in any drawing tool, and what matters is staying consistent and keeping a visible legend.

Is a C4 container the same as a Docker container?

Not necessarily. In C4, a container is any unit that runs code or stores data: a web app, an API, a mobile app, a database. It may run on Docker, but the level describes the logical structure, not how it is deployed.

Do I need to draw all four levels?

No. Most teams document well with levels 1 and 2, and use level 3 only for complex parts. Level 4 is usually generated from the code. Draw the level that answers your audience question.

More articles

Create free account