June 21, 2021

What is a C4 Model? How to Make C4 Software Architecture Diagrams

Diagrams for Software Engineering
Software Development

What is C4 Modeling?

A C4 Model describes or defines software architecture at different levels of detail. A C4 Model is a set of diagrams representing the context, containers, components, and code of a piece of software. The hierarchy of these diagrams allows different audiences to understand the software architecture at the level of detail they need.

You can use a C4 model for microservices, to show how you’re planning to build a system, to describe an existing system, or visualize your enterprise cloud strategy. C4 diagrams are an alternative, simplified framework compared to UML diagrams and can describe multiple systems, unlike more specific AWS architecture diagrams, GCP architecture diagrams, or Azure architecture diagrams.

The C4 Model was created by Software Architecture for Developers author, Simon Brown.

To diagram your software architecture directly alongside your documentation, you can sign up for a free trial of Gliffy for Confluence today/

Four Levels of C4 Models

There are four types of C4 models, each one for a different audience and containing a different level of detail. These are the context, container, components, and code diagrams that make up your C4 model.

Level 1: Context Diagrams

Context diagrams are the most general description of what your system does, who will use it, and what other systems it will interact with. A context diagram will help you describe the scope of your project and help you pinpoint who the user is and what problem you’re going to solve.

Level 2: Container Diagrams

The container diagram takes the first step into describing the software system and shows the APIs, applications, databases, and microservices that the system will use. Each of these applications or services is represented with a container and the interactions between them are shown at a high level.

Level 3: Component Diagrams

One step deeper than the container diagram, the component diagram details groups of code within a single container. These components represent abstractions of your codebase.

This diagram type is comparable to a UML component diagram, but follows a less-strict set of “rules” in order to create the software architecture diagram.

Level 4: Representing Code with Class Diagrams

The last level requires lots of detail to show how the code of a single component is actually implemented. To do this, you would want to make a UML class diagram or entity relationship diagram that describes the component.

Representing Software with All Four Levels

Depending on your project and the containers or components you need to describe, you’ll end up having a set of four or more diagrams that represent your C4 model. If you make a C4 model in Gliffy, you can use links directly on shapes in your diagrams to allow users to double-click into deeper levels of your model.

How to Make a C4 Model with Gliffy

Step 1: Drag & Drop Shapes for the Context Diagram

In Gliffy, you’ll open a new diagram and use basic shapes to build your C4 Model. Drag and drop the shapes that represent your software system, including your user or persona and any software systems connected to the one you’re diagramming. As you drag and drop shapes, type to add text that labels or describes the components in your diagram.

Each shape in C4 Models usually includes:

  • The name of an element in your diagram
  • A brief description of the role of a system, database, component, or container
  • The type of technology you’re describing (ie: JSON component, XML component)
  • Arrows with descriptions that describe how elements interact with one another
Step 1 for making a C4 Model

 

Step 2: Create a Key that Clarifies Your Context Diagrams

While working on your context diagram, consider setting style rules that will dictate how you draw the additional diagrams of a C4 model. For example, you could choose to put the system you’re describing in a darker blue color than the systems it interacts with. Your users or personas could be a different color as well. External elements should always be the same color.

These rules will create visual consistency that allows viewers to quickly read and understand all four diagrams in relation to one another.

Step 2 for C4 modeling: create a color key

 

Step 3: Draw Connections Between the Components in Your Diagram

Using the connector tool in the Gliffy toolbar, drag and drop lines between the elements in your context diagram. You can select a line and type to give it a label.

To re-style the line, click the line and then click on the dark grey line icon that appears alongside it. Here, you can change the color, stroke, and style of the connector or add arrowheads to indicate the directions data flows throughout your system.

C4 Model Step 3: draw connections between components

 

Step 4: Create a New Layers for the Next Diagram in the Model

In the upper right side of Gliffy’s toolbar, click the layer button to open the layers panel.

Double-click to rename your current layer, giving it a clear name like “Context Diagram.” Then, click the duplicate layer button to quickly copy this layer. Rename your copy for the next level of the C4 model, the container diagram.

You can toggle the visibility of these layers by hovering over the layer name and then clicking the eye icon that appears to the right. You can also lock the additional layers to prevent accidental editing.

C4 Model Step 4: Add layers for each level of the model

 

Step 5: Repeat Steps 1-4 for the Container Diagram

Select your new container diagram layer and rearrange the shapes and information you included in your context diagram to drill one level deeper into the details.

You can drag out an additional shape or rectangle to create a boundary for the elements in the container you’re describing. To make sure this shape doesn’t get in the way of the additional elements, use the Send to Back option in the toolbar to set it behind everything else on your container diagram layer.

When you get to Step 4, duplicate your Container Diagram layer so that you can use it as a base or template for the Component Diagram.

C4 Model Step 5: Create the container diagram

 

Step 6: Repeat Steps 1-4 for the Component Diagram

Your component diagram will detail the code inside the container you described in the previous diagram. Just follow the same steps, moving the existing diagram elements to make space for more details.

C4 Model Step 6: Create the Component Diagram

 

Step 7: Repeat Steps 1-4 for the Code or Class Diagram

Your last diagram in the C4 model will detail the code included in your system — but this level of detail isn’t always required to create an effective description of your architecture. It’s common to make a UML class diagram to describe this code, if you decide it’s necessary.

Step 8: Add Layer Links to Show Each Layer

You can use Gliffy’s dynamic layer linking feature to create “buttons” that allow your diagram viewers to toggle through the layers of your C4 model. This functionality is not available for free trial accounts.

If you’d like to make it possible for a viewer to toggle through the layers of your C4 model, you can add a new layer and name it something like “Layer View,” then draw out four shapes to act as buttons to toggle through each layer.

Open the layers panel and click on the shape you’d like to use to show the Context Diagram layer. Then, click the layer link icon on the lower right side of the layers panel. From here, simply select the layers you want to display when a diagram viewer clicks on this button. Click save to lock in your changes. You’ll see a small eye icon appear next to the shape.

Repeat for the additional buttons in your C4 Model.

Step 8: Add links to each layer in your C4 model

 

When you’re done, save your diagram and generate a link by clicking the “Share” button. Using that new share link, you can double-check that your buttons work to toggle through the layers as expected.

Step 9: Export, Embed, or Share Your C4 Model

While C4 models are useful to have in your back pocket as a reference, they’re more useful when it comes to keeping everyone on a team on the same page. In addition to sharing your C4 model via a link, you can also export and embed your diagram. Here are the other ways to share your final C4 Model:

▶️  Video resource: Exporting from Gliffy

🔎  Guide: Embedding Diagrams with Gliffy

Share your final C4 model with a link

Make a C4 Model with Gliffy

For basic C4 modeling, you can use Gliffy to describe your architecture. Gliffy also supports drawing and diagramming for other types of software architecture diagrams or software engineering diagrams, likeUML diagramsEntity-Relationship diagrams, and cloud architecture diagrams.

If you haven’t yet, be sure to sign up for a free trial to try it yourself.

TRY GLIFFY FOR CONFLUENCE  TRY GLIFFY ONLINE