C4 model

On this page 7

The C4 model is a hierarchical approach to visualizing software architecture that describes a system through four levels of diagrams: context, containers, components and code. Created by software architect Simon Brown, it gives teams a shared vocabulary of a few core abstractions and lets readers zoom from a high-level picture into technical detail, much like moving between maps of different scales.

The C4 model is deliberately notation independent and tooling independent. It does not prescribe shapes or colors; instead, it defines what each diagram should show and for whom, which makes it popular for documentation, onboarding and architecture reviews in teams that find full UML too heavy.

Core abstractions of the C4 model

Every C4 diagram is built from a small set of well-defined building blocks. Consistent use of these terms is what makes diagrams comparable across teams, because a box labeled as a container always means the same kind of thing.

The table defines each abstraction and gives typical examples.

AbstractionMeaningExamples
PersonA human user or roleCustomer, support agent
Software systemThe highest-level unit that delivers valueOnline banking system, email service
ContainerA separately runnable or deployable unitWeb application, mobile app, database
ComponentA grouping of related functionality inside a containerPayment controller, notification module
Code elementClasses, functions or tablesOrderService class, users table
Building blocks used in C4 diagrams

A frequent misunderstanding concerns the word container. In the C4 model, it means any runtime boundary that executes code or stores data, such as a single-page application, a serverless function or a schema. It is not limited to Docker containers, although a Docker container can be one.

The four diagram levels

The C4 model organizes diagrams as zoom levels, each aimed at a different audience and answering a different question. Most teams find that the first two levels deliver most of the value, while the lower levels are drawn selectively.

LevelQuestion answeredPrimary audience
1. System contextWhat does the system do and who uses itEveryone, including non-technical staff
2. ContainerWhat runnable parts exist and how they communicateDevelopers, operations, architects
3. ComponentHow one container is structured internallyDevelopers of that container
4. CodeHow a component is implementedDevelopers, usually generated by tools
C4 diagram levels and their audiences

Beyond the four core levels, the C4 model defines supplementary diagrams. A system landscape diagram shows all systems in an organization, a dynamic diagram shows the runtime sequence of a use case, and a deployment diagram maps containers onto infrastructure such as clusters, regions or servers.

How the C4 model differs from other approaches

The C4 model sits between informal whiteboard sketches and formal modeling languages. It adds structure and consistent terminology to sketches, while avoiding the steep learning curve of complete UML specifications.

ApproachFocusTypical trade-off
C4 modelHierarchical structural viewsEasy to learn, limited behavioral detail
UMLFormal notation for structure and behaviorExpressive, but heavy and often inconsistent in practice
4+1 view modelMultiple stakeholder viewsComprehensive, but abstract to apply
arc42Documentation templateComplements C4 diagrams rather than replacing them
Ad hoc box diagramsQuick communicationAmbiguous boxes and arrows
C4 model compared with related approaches

The C4 model also combines well with other practices in software architecture. Diagrams can illustrate decisions recorded in an architecture decision record, document the boundaries of microservices or a modular monolith, and show how an event-driven architecture routes messages between containers.

Creating effective C4 diagrams

Good C4 diagrams are self-explanatory without a presenter. Each one should carry a title, a key or legend, and labeled relationships that say what flows and how, for example JSON over HTTPS or asynchronous messages through a broker.

  • Label every element with name, type and responsibility, such as Web API, container, Java and Spring Boot, handles orders.
  • Make every arrow unidirectional and labeled with intent and protocol, never a bare line.
  • Keep each diagram to one level of abstraction and avoid mixing components with external systems in confusing ways.
  • Include a legend explaining shapes, colors and line styles.
  • Limit the element count: roughly 20 elements is a practical upper bound for readability.

Many teams use diagrams as code, where a text model generates all views. Tools based on the Structurizr DSL or C4 extensions for PlantUML and Mermaid keep the model and views consistent, allow review in version control and reduce drift when the architecture changes.

Limitations and common mistakes

The C4 model describes static structure first, so it is not a full specification method. Behavior, data models, security controls and non-functional requirements need complementary documentation, such as sequence diagrams, threat models or quality attribute scenarios.

MistakeConsequenceFix
Drawing the code level by handDiagrams go stale quicklyGenerate from code or skip it
Mixing abstraction levelsReaders lose orientationSplit into separate diagrams
Unlabeled arrowsDependencies remain ambiguousAdd intent and technology
Treating containers as Docker onlyMissing databases and clientsUse the C4 definition
Never updating diagramsDocumentation loses trustKeep models in version control
Typical C4 mistakes and how to fix them

The most important warning is about maintenance. Diagrams that no longer match the running system mislead more than they help, so teams should draw only the views they will keep up to date as part of normal delivery work. A small set of accurate, current diagrams is worth more than a complete but outdated collection.

The simple explanation

The C4 model is a way to draw software like a set of maps. The first map shows the whole country: the system and the people who use it. The next maps zoom into cities, neighborhoods and finally single streets.

Each map uses the same few kinds of boxes, so anyone can read them. A manager can stop at the first picture, while a developer can zoom in as far as needed.

How it is used in practice

A team of twelve developers maintains an insurance claims platform and keeps losing time explaining it to new hires. The lead architect introduces the C4 model and writes the views in a text-based DSL stored in the same repository as the code.

The system context diagram shows policyholders, claims handlers, a payment provider and a document archive. The container diagram shows a React web app, a mobile app, a claims API, a rules engine, a PostgreSQL database and a message broker, with every arrow labeled by protocol. Component diagrams exist only for the claims API, the most complex container.

Within two months, new developers report that they understand the platform in their first week instead of the first month, and architecture reviews start from the container diagram rather than from improvised whiteboard sketches.