C4 Model
The C4 model for software architecture is a framework that allows software professionals to describe and communicate software architectures with diagrams. It was created by Simon Brown and is composed of four levels: Context, Containers, Components, and Code. Each level zooms in on the software system, providing a more detailed view. This guide covers the high-level concepts of the C4 model and includes examples based on a fictitional online bank.
Overview
- Context: Focuses on the high-level view of the system; shows how the software system fits into the real-world environment, including external systems and users.
- Containers: Delves into the system, showcasing the high-level technology choices, how containers communicate, and their responsibilities.
- Components: Further breaks down the containers into individual components, illustrating how a specific container is composed and how components interact.
- Code: The most granular level of the model, focusing on the code level inside the components.
Context
High-Level Concepts
- Purpose: Understand how your system interacts with external entities and fits into the larger environment.
- Elements: Include your system, users, and external systems your system interacts with.
- Scope: Keep the details minimal; the goal is to understand the overall interactions.
Example
A context diagram for the Internet Banking System might include:
- "Personal Banking Customer" as the user
- "Internet Banking System" for customer interactions
- "Mainframe Banking System" for core banking functionalities
- "Email System" for communication
Container
High-Level Concepts
- Purpose: A closer look at the high-level internal structure of the system and how containers (applications, databases, etc.) within the system interact.
- Elements: Applications, data stores, databases, and more, along with the technology used (e.g., WebSockets, HTTP, relational database).
- Scope: High-level; avoid delving into component details.
Example
A container diagram for the Internet Banking System might include:
- "Web Application" for user interaction, using HTML/JavaScript.
- "Single-Page Application" for a more responsive user interface.
- "Mobile App" for banking on the go.
- "API" for application-system interaction.
Component
High-Level Concepts
- Purpose: Breaks down the internal structure of a specific container.
- Elements: Components/services and their interactions.
- Scope: Detailed; showcases the functionality of each component inside a container.
Example
A component diagram for the facade might include:
- "MainframeBankingSystemFacadeImpl" for creating and parsing requests/responses.
- "BankingSystemConnection" for sending/receiving data.
Code
High-Level Concepts
-Purpose: Focus on the code-level view of a component. -Elements: Classes, interfaces, entities, and their relationships. -Scope: Very detailed; suitable for developers needing to understand the code structure.
Example
Given the "MainframeBankingSystemFacadeImpl" component, a code diagram might show:
- Specific methods for creating/parsing requests.
- Handlers for sending/receiving data.
- Interfaces for data transmission.
Conclusion
The C4 model provides a multi-level, hierarchical approach for diagramming software architectures, moving from broad system interactions to detailed code structures. It helps diverse stakeholders understand the system at various depths, promoting clarity and reducing confusion.