The C4 Model

22 Mar 2021 - Alfie J.

Definition

The C4 model provides a way for software development teams to efficiently and effectively communicate their software architecture, at different levels of detail, telling different stories to different types of audience, when doing up front design or retrospectively documenting an existing codebase.

The C4 model is an "abstraction-first" approach to diagramming software architecture, based upon abstractions that reflect how software architects and developers think about and build software. The small set of abstractions and diagram types makes the C4 model easy to learn and put to use.

Abstraction Levels

Level 1 being the most abstract, and level 4 being the least abstract:

  • Level 1 - Context
  • Level 2 - Container
  • Level 3 - Component
  • Level 4 - Code

c4abs From c4model.com: A software system is made up of one or more containers (web apps, mobile apps, desktop apps, databases, file systems, etc.), each of which contains one or more components, which in turn are implemented by one or more code elements (e.g. classes, interfaces, objects, functions, etc.).

Diagrams
Context

Context diagrams provide a high-level starting point, showing how the software system in scope fits into the world around it.

Container

Container diagrams are used to "zoom" into the software system in scope, showing the high-level technical building blocks.

Component

Component diagrams are used to "zoom" into an individual container, showing the components inside it.

Code

Code diagrams are used to "zoom" into an individual component, showing how the specific component is implemented. Code diagrams of various complexity exist, some much more granular than others and aim to provide enough information to understand the core flow or purpose of the component.

Notation

Levels 1-3 use five basic diagramming elements:

  • Persons
  • Software Systems
  • Containers
  • Components
  • Relationships

Level 4 relies on existing notations, such as UML diagrams, ERD, and system diagrams generated directly by an IDE.

References