A Quick Guide to the C4 Architecture Model

Nara Bagi
3 min readDec 21, 2020
Source

In this short article, we will explore what the C4 model is, what its different levels are and how one can apply it in practice.

C4 is an abstraction-based model for a diagrammatic depiction of the software architecture.

It consists of four main levels (diagrams):

  • Context,
  • Container,
  • Component,
  • Code.

So, according to this model, any software system is deemed to:

  • exist within a specific context,
  • consist of one or more containers (mobile apps, web apps, etc.),
  • with each container containing one or more components,
  • each component being implemented by some code elements (classes, functions, etc.)

Level 1 of the C4 model is the Context diagram.

At this stage, your software is depicted as a box in the center of the diagram that has interactions with some specific users and/or other systems. Technical details are hidden away so that a clear message of what the system does and how it interacts with the “outside world” can be sent to non-technical people.

Although it is the simplest of all diagrams, it is the most crucial one at the same time. Often, people making decisions on whether to proceed with a given project or not and how much money/how many resources to allocate to it are top-level executives/managers who need not know the intricacies of technical implementation. All they need is a clear understanding of the system and its benefits or risks.

Click on the underlined word in this section to see a sample diagram.

Level 2 of the C4 model is the Container diagram.

A container can be a mobile app, a web application, a file system, etc. Usually, it is a separately deployable unit executing code or storing some data.

This diagram shows how the software architecture works on a high-level and how different containers interact with one another (e.g. interactions between a web application and a database).

Click on the underlined word in this section to see a sample diagram.

Level 3 of the C4 model is the Component diagram.

This diagram depicts what components each container consists of, how they interact (if at all), what their technical implementation details are and what each component effectively does.

A component can be thought of as a collection of implementation classes behind an interface (Source). Components are contained within Containers and are not separately deployable on their own.

Examples can include E-mail components, Security components, Password Re-setting components, etc.

Click on the underlined word in this section to see a sample diagram.

Level 4 of the C4 model is the Code diagram.

This diagram contains the details of how each component is implemented as code — e.g. what the different classes are, how they interact, how exceptions are handled and so on. UML diagrams can be used here to convey the message.

You should be careful about what to include in this diagram — lower-level details sometimes might not be of enough importance and can obscure the bigger picture.

Click on the underlined word in this section to see a sample diagram.

--

--