C4 Model. My experience + Example

Itza Reyes
6 min readNov 5, 2022

--

Para leer en Español clic aquí.

I have always looked for a way to communicate and visualise architectures in a way that is clear to everyone so that anyone who comes to the documentation can understand the general idea, but at the same time, if they want to go deeper into what I can do. That’s why when I got to Simon Brown’s talk “Visualising software architecture with the C4 model”, my eyes lit up 🤩

What is C4Model? ❓

The C4 Model was created as a way to help software development teams describe and communicate software architecture, both during initial design sessions and when retrospectively documenting an existing code base.

Why I loved this Model? 🤩

It’s a way of creating maps of the code, at various levels of detail, much like Google Maps, where you can zoom in and out of an area of interest.
By making the diagrams, I better understood the architecture of my system and detected the points I needed to know.
The diagram can be made navigable, deepened and returned as many times as desired.
You can communicate architecture decisions with all roles, and each person decides how deep they want to go.

Let’s dive into C4 Model 👀

Abstractions

To create these maps of your code, we first need a standard set of abstractions to create a ubiquitous language that we can use to describe the static structure of a software system.

The C4 Model considers the static structures of a Software System in terms of containers, components and code. And person uses the software systems we build.

Person: A person represents one of the human users of your software system (for example, actors, roles, characters, etc.)

Software System: A software system is the highest level of abstraction and describes something that offers value to its users, whether human or not. This includes the Software System you are modelling and the other Software Systems your software system depends on (or vice versa). Often, a software system is “owned by” a single software development team.

Container: (applications and data stores) Not Docker! In the C4 Model, a container represents an application or a data store. A container must be running for the Software System to work. In real terms, a container is something like a Server-side web application, Client-side web application, Client-side desktop application, Mobile app, Server-side console application, Serverless function, Database, File system, Shell script, etc.

Component: In the C4 Model, a component is a grouping of related functions encapsulated behind a well-defined interface. If you’re using a language like Java or C#, the easiest way to think of a component is that it’s a collection of implementing classes behind an interface.

Core diagrams 💎

Level 1 | Context: A big picture

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.

The details are unimportant here, as this is your zoomed-out view showing a big picture of the system landscape. The focus should be on people and software systems rather than technologies, protocols, and other low-level details.

Context Diagram — Elements, scope and audience

Level 2 | Container: High-level responsibilities of a system

The container diagram shows the high-level form of the software architecture and how responsibilities are distributed across it. It also shows the main technological options and how the containers communicate with each other. It is a simple technology-focused diagram.

A container is a separate executable/deployable unit (for example, a separate process space) that executes code or stores data.

Container Diagram — Elements, scope and audience

Level 3 | Components: The basic components and interactions of an application

You can then zoom in and break down each container further to identify the main structural building blocks and their interactions.

The component diagram shows how a container comprises many “components”, what each of those components is, their responsibilities, and the technology/implementation details.

Component Diagram — Elements, Scope and Audience

Level 4 | Code: The implementation detail

Finally, you can expand each component to show how it is implemented as code, using UML class diagrams, entity relationship diagrams or similar.

This is an optional level of detail and is often available on demand from tools like the IDE. Ideally, this diagram would be generated automatically using tools, and you should consider showing only those attributes and methods that allow you to tell the story you want to tell.

Code Diagram — Reach and Audience

My learnings ✨

  • Using all four levels of the diagram is unnecessary; only those that add value.
  • Titles and what each representation means (e.g. shapes, colours, border styles, line types, arrowheads, etc.) should be noted on the diagram for everyone to understand.
  • You have to show it to the business, product, stakeholders, etc., to validate that it is understandable. Don’t just focus on technical profiles.
  • Oblique language must be used.
  • Each element must have a brief description.
  • In my case, naming each line made a big difference since it led me to analyse the interaction between each component.
  • Each line must represent a one-way relationship.

In what tool can it be done? ⚒️

There are several tools that offer compatibility with the C4 Model; as I am one of the people who does not focus so much on the tool, I adapted the one we use in the company where I work, which is free and, from my point of view easy to use and there I made my diagrams, at the end I leave the example with diagrams.net, but anyway I share a list so you can use the one you like the most.

Text-based modelling tools

Visual modelling tools

Text-based diagramming tools

Visual diagramming tool

An example in Draw.io/diagramas.net 🧭

In some of the components, you can click on them to navigate in the diagram, and also use the breadcrumbs to go in or out, depending on what you are looking for.

Here you can view it, and an editing option will appear, creating a copy for you to edit. Enjoy it!

Thank you for reading
If you have any comments, suggestions or ideas, I will be happy to read you and collaborate to grow together ❤️

Disclaimer: I am improving my English so the article may have some grammar and writing errors. I’ll keep getting better I promise.

Visit http://www.itzareyes.mx/

--

--

Itza Reyes

Me encanta trabajar con personas, resolver problemas y crear software asombroso. | Tech Lead @Creditas | https://www.itzareyes.mx/