How To Diagram Systems

Dr Milan Milovic provides a brilliant description for The C4 Model. Letโ€™s take a look.

The C4 Model

When developing software, it is important to have a clear plan and understand how different components of the system will work together. Documentation and diagramming help us to achieve this by providing a ๐˜ƒ๐—ถ๐˜€๐˜‚๐—ฎ๐—น ๐—ฟ๐—ฒ๐—ฝ๐—ฟ๐—ฒ๐˜€๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ผ๐—ณ ๐˜๐—ต๐—ฒ ๐˜€๐—ผ๐—ณ๐˜๐˜„๐—ฎ๐—ฟ๐—ฒ ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ. This helps different stakeholders, like developers, testers, and clients, to have a common understanding of the software design.

One of the preferred ways to visualize the software architecture is ๐˜๐—ต๐—ฒ ๐—–๐Ÿฐ ๐—บ๐—ผ๐—ฑ๐—ฒ๐—น, developed by Simon Brown, a software architect, and author. The C4 model examines a software systemโ€™s static structures containers, components, and code. And individuals use the software programs we create.

The C4 model consists of ๐—ณ๐—ผ๐˜‚๐—ฟ ๐—น๐—ฒ๐˜ƒ๐—ฒ๐—น๐˜€ ๐—ผ๐—ณ ๐—ฎ๐—ฏ๐˜€๐˜๐—ฟ๐—ฎ๐—ฐ๐˜๐—ถ๐—ผ๐—ป, which are represented by four different types of diagrams:

๐Ÿ”น ๐—–๐—ผ๐—ป๐˜๐—ฒ๐˜…๐˜ (๐—Ÿ๐—ฒ๐˜ƒ๐—ฒ๐—น ๐Ÿญ): System Context diagram - This diagram shows the system in context, providing an overview of the system and its environment. The system here is the highest level of abstraction and it shows the system under consideration as a box in the center, surrounded by its users and other systems that interact with it. These diagrams help provide a big-picture overview.

๐Ÿ”น ๐—–๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ๐˜€ (๐—Ÿ๐—ฒ๐˜ƒ๐—ฒ๐—น ๐Ÿฎ): Container diagram - This diagram shows the high-level components or services within the system and how they are connected. It shows each component as a box with its internal details abstracted away, which are separately deployable or executable. Containers can represent APIs, databases, file systems, etc.

๐Ÿ”น ๐—–๐—ผ๐—บ๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐˜€ (๐—Ÿ๐—ฒ๐˜ƒ๐—ฒ๐—น ๐Ÿฏ): Component diagram - This diagram shows the internal components of a container and how they interact with each other. Here we can visualize abstractions in our codebase. E.g. in C#, it is an implementation class behind some interface.

๐Ÿ”น ๐—–๐—ผ๐—ฑ๐—ฒ (๐—Ÿ๐—ฒ๐˜ƒ๐—ฒ๐—น ๐Ÿฐ): Code diagram - This diagram shows the detailed structure of a single component or module, including its classes and their relationships.

Most teams should at the very least produce and keep up-to-date ๐—ฐ๐—ผ๐—ป๐˜๐—ฒ๐˜…๐˜ ๐—ฎ๐—ป๐—ฑ ๐—ฐ๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ ๐—ฑ๐—ถ๐—ฎ๐—ด๐—ฟ๐—ฎ๐—บ๐˜€ for their software system. If they are useful, component diagrams can be made, but for long-term documentation needs, youโ€™ll need to figure out how to automate changes to these diagrams.

Image source: c4model. com.