The C4 model, devised by Simon Brown, offers a hierarchical approach for visualizing and documenting the architecture of software systems. It breaks down the system into four levels of granularity, Context (high-level system interactions), Containers (applications and services within the system), Components (inner parts of those containers), and Code (detailed internals of components). This structure ensures that the system’s architecture is comprehensible to various audiences, from non-technical stakeholders to developers. In practice (as also in the ArchiLab courses like DDD), often only level 1 and 2 of the C4 model are used.
The C4 model notation is no way connected to DDD as a design concept framework. However, if you use C4 in a DDD context, it is useful to understand the following DDD concepts.
The C4 model is a hierarchical approach for visualizing and documenting the architecture of software systems. It is based on the observation that a highly formalized specification language like UML is often not really used by teams “in the field”, and that practical architecture work usually just happens by sketching boxes and arrows on a whiteboard or piece of paper.
Of course, the Unified Modeling Language (UML), a standardised notation for communicating the design of software systems, still lives on. However, while you can argue about whether UML offers an effective way to communicate software architecture or not, that’s often irrelevant because many teams have already thrown out UML or simply don’t know it. Such teams typically favour informal “boxes and arrows” sketches instead, but often these diagrams don’t make much sense unless they are accompanied by a detailed narrative.
Therefore, the C4 model is intended as a “middle ground” between completely informal sketches (where important context information is easily lost over time) and highly formalized notations like UML (where such information is also lost, but for completely different reasons). C4 provides a simple, consistent way to visualize the architecture of software systems at different levels of detail.
This has made C4 the “undeclared standard notation” for software architecture diagrams in the industry. The following benefits might explain its popularity:
As the name indicates, the C4 model consists of four levels of diagrams, each providing a different level of detail about the system. The author of the C4 model himself, Simon Brown, suggests that in practice (as also in the ArchiLab courses like DDD), often only level 1 and 2 of the C4 model are used.
The level 1 diagram is usually created first, as a “Big Picture” overview of the system and its environment.
A system context diagram is a good starting point for diagramming and documenting a software system, allowing you to step back and see the big picture. Draw a diagram showing your system as a box in the centre, surrounded by its users and the other systems that it interacts with.
A system context diagram helps you to answer the following questions:
- What is the software system that we are building (or have built)?
- Who is using it, and what are they doing?
- How does it fit in with the existing environment?
Level 2 diagrams really contain the essence of a C4 model. They show the high-level building blocks of the system, how they are deployed, and how they interact with each other. Usually, the main Level 1 diagram is decomposed into several Level 2 diagrams, each focusing on a subdomain or bounded context.
The container diagram shows the high-level shape of the software architecture and how responsibilities are distributed across applications and data stores. It also shows the primary technology choices, how they are used, and how containers communicate with each other. It’s a high-level technology focussed diagram that is useful for software developers and support/operations staff alike. A container diagram helps you answer the following questions:
- What is the overall shape of the software system?
- What are the high-level technology decisions?
- How are responsibilities distributed across the applications and data stores?
- How do applications and data stores communicate with one another?
- As a developer, where do I need to write code in order to implement features?
The term “Container” in C4 does not refer to a specific technology (like Docker containers), but rather to an application or service that runs in its own process and has its own data store. C4 offers a dedicated deployment diagram type for showing how containers are deployed to infrastructure. However, as a first approximation, in a service-oriented architecture like a microservice landscape, the C4 container can be read as the physical Docker container (if Docker is used). Each service then maps to one or more containers.
In a monolithic (yet DDD-structured) architecture like e.g. in Spring Modulith, you would map the container concept to the modules your system (even if they are not deployed separately). Here, the container is really more of a logical concept.
The level 3 and 4 diagrams are more detailed and technical. Simon Brown himself suggests that they only should be created if there is a real need for them, as they have a strong redundancy with the actual code base, and can to some extent be auto-generated from the code base by modern IDEs and tools.
We will (for these reasons) not use them in the ArchiLab DDD course.
This section contains advice for student teams responsible for this topic in the DDD course.
The moderators as well as the participants require some familiarity with the methods. Therefore,
plan some time to read and discuss in your preperation team. Plan also a retrospective,
where you analyse what went well and what could be improved. Before workshop, you need to do the following:
In the DDD commented literature list, there is a section with C4 model sources.