The C4 model, developed by Simon Brown, is a framework for visualizing software architecture at various levels of detail. It emphasizes the use of hierarchical diagrams to represent different aspects and views of a system, providing a comprehensive understanding for various stakeholders. The model’s name, C4, stands for Context, Containers, Components, and Code, each representing a different level of architectural abstraction.
Levels of the C4 Model
1. Context (Level 1)
Purpose: To provide a high-level overview of the system and its environment.
- The System Context diagram is a high-level view of your software system.
- It shows your software system as the central part, and any external systems and users that your system interacts with.
- It should be technology agnostic, and the focus on the people and software systems instead of low-level details.
- The intended audience for the System Context Diagram is everybody. If you can show it to non-technical people and they are able to understand it, then you know you’re on the right track.
Key Elements:
- System: The primary system under consideration.
- External Systems: Other systems that the primary system interacts with.
- Users: Human actors or roles that interact with the system.
Diagram Features:
- Scope: Shows the scope and boundaries of the system within its environment.
- Relationships: Illustrates relationships between the system, external systems, and users.
- Simplification: Focuses on high-level interactions, ignoring internal details.

Example: An online banking system context diagram might show:
- The banking system itself.
- External systems like payment gateways, credit scoring agencies, and notification services.
- Users such as customers, bank employees, and administrators.
More Extensive Detail:
- Primary System: Represents the main application or service being documented.
- Boundaries: Defines the limits of what the system covers.
- Purpose: Describes the main functionality and goals of the system.
- External Systems: Systems outside the primary system that interact with it.
- Dependencies: Systems that the primary system relies on for specific functionalities (e.g., third-party APIs, external databases).
- Interdependencies: Systems that rely on the primary system (e.g., partner applications).
- Users: Different types of users who interact with the system.
- Roles: Specific roles that users may have, such as Admin, Customer, Support Agent.
- Interactions: The nature of interactions users have with the system (e.g., login, data entry, report generation).
2. Containers (Level 2)
When you zoom into one software system, you get to the Container diagram.
Purpose: To break down the system into its major containers, showing their interactions.
- Your software system is comprised of multiple running parts – containers.
- A container can be a:
- Web application
- Single-page application
- Database
- File system
- Object store
- Message broker
- You can look at a container as a deployment unit that executes code or stores data.
- The Container diagram shows the high-level view of the software architecture and the major technology choices.
- The Container diagram is intended for technical people inside and outside of the software development team:
- Operations/support staff
- Software architects
- Developers
Key Elements:
- Containers: Executable units or deployable artifacts (e.g., web applications, databases, microservices).
- Interactions: Communication and data flow between containers and external systems.
Diagram Features:
- Runtime Environment: Depicts the containers and their runtime environments.
- Technology Choices: Shows the technology stacks and platforms used by each container.
- Responsibilities: Describes the responsibilities of each container within the system.

Example: For the online banking system:
- Containers could include a web application, a mobile application, a backend API, and a database.
- The web application might interact with the backend API for business logic and the database for data storage.
- The mobile application might use a different API optimized for mobile clients.
More Extensive Detail:
- Web Application:
- Technology Stack: Frontend framework (e.g., Angular, React), backend language (e.g., Node.js, Java).
- Responsibilities: User interface, handling user requests, client-side validation.
- Mobile Application:
- Technology Stack: Native (e.g., Swift for iOS, Kotlin for Android) or cross-platform (e.g., React Native, Flutter).
- Responsibilities: User interface, handling user interactions, offline capabilities.
- Backend API:
- Technology Stack: Server-side framework (e.g., Spring Boot, Express.js), programming language (e.g., Java, Node.js).
- Responsibilities: Business logic, data processing, integrating with external services.
- Database:
- Technology Stack: Type of database (e.g., SQL, NoSQL), specific technology (e.g., PostgreSQL, MongoDB).
- Responsibilities: Data storage, data retrieval, ensuring data consistency and integrity.
3. Components (Level 3)
Next you can zoom into an individual container to decompose it into its building blocks.
Purpose: To further decompose each container into its key components and their interactions.
- The Component diagram show the individual components that make up a container:
- What each of the components are
- The technology and implementation details
- The Component diagram is intended for software architects and developers.
Key Elements:
- Components: Logical units within a container, such as services, modules, libraries, or APIs.
- Interactions: How these components interact within the container.
Diagram Features:
- Internal Structure: Shows the internal structure and organization of each container.
- Detailed Responsibilities: Describes the roles and responsibilities of each component.
- Interaction Details: Illustrates the detailed interaction between components.

Example: For the backend API container of the online banking system:
- Components might include an authentication service, an account management module, a transaction processing service, and a notification handler.
- The authentication service handles user login and security.
- The account management module deals with account-related operations.
- The transaction processing service manages financial transactions.
- The notification handler sends alerts and notifications to users.
More Extensive Detail:
- Authentication Service:
- Responsibilities: User authentication, token generation, session management.
- Interactions: Interfaces with the user interface components, interacts with the database for user data.
- Account Management Module:
- Responsibilities: Managing user accounts, updating account information, retrieving account details.
- Interactions: Interfaces with the authentication service for user validation, interacts with the transaction processing service.
- Transaction Processing Service:
- Responsibilities: Handling financial transactions, validating transactions, updating account balances.
- Interactions: Interfaces with the account management module, interacts with external payment gateways.
- Notification Handler:
- Responsibilities: Sending notifications (e.g., emails, SMS) to users, managing notification templates.
- Interactions: Interfaces with the transaction processing service to send transaction alerts, interacts with external notification services.
4. Code (Level 4)
Finally, you can zoom into each component to show how it is implemented with code, typically using a UML class diagram or an ER diagram.
Purpose: To provide detailed views of the codebase, focusing on specific components or classes.
- This level is rarely used as it goes into too much technical detail for most use cases. However, there are supplementary diagrams that can be useful to fill in missing information by showcasing:
- Sequence of events
- Deployment information
- How systems interact at a higher level
- It’s only recommended for the most important or complex components.
- Of course, the target audience are software architects and developers.
Key Elements:
- Classes: Individual classes, methods, or functions within a component.
- Relationships: Detailed relationships like inheritance, composition, method calls, or data flows.
Diagram Features:
- Detailed Code Analysis: Offers a deep dive into the code structure and logic.
- Code-Level Relationships: Illustrates how classes and methods interact at a code level.
- Implementation Details: Shows specific implementation details and design patterns used.

Example: For the transaction processing service in the backend API container:
- Classes might include
Transaction,TransactionProcessor,Account, andNotificationService. - The
TransactionProcessorclass might have methods for initiating, validating, and completing transactions. - Relationships such as
TransactionProcessorcalling methods on theAccountclass to debit or credit funds.
More Extensive Detail:
- Transaction Class:
- Attributes:
transactionId,amount,timestamp,status. - Methods:
validate(),execute(),rollback(). - Responsibilities: Representing a financial transaction, ensuring data integrity.
- Attributes:
- TransactionProcessor Class:
- Attributes:
transactionQueue,auditLog. - Methods:
processTransaction(transaction),validateTransaction(transaction),completeTransaction(transaction). - Responsibilities: Processing transactions, managing transaction flow, logging transactions.
- Attributes:
- Account Class:
- Attributes:
accountId,balance,accountHolder. - Methods:
debit(amount),credit(amount),getBalance(). - Responsibilities: Managing account data, updating balances, providing account information.
- Attributes:
- NotificationService Class:
- Attributes:
notificationQueue,emailTemplate,smsTemplate. - Methods:
sendEmailNotification(recipient, message),sendSMSNotification(recipient, message). - Responsibilities: Sending notifications to users, managing notification templates, handling notification queues.
- Attributes:
Benefits of the C4 Model
- Clarity and Focus:
- Provides a clear separation of concerns by breaking down the system into different levels of abstraction.
- Each diagram focuses on a specific aspect, avoiding information overload.
- Consistency and Standardization:
- Offers a standardized approach to documenting architecture, making it easier to maintain consistency across diagrams.
- Facilitates comparison and review of different systems using the same visual language.
- Enhanced Communication:
- Improves communication within development teams and with external stakeholders by providing clear, concise, and visually appealing diagrams.
- Helps in onboarding new team members by offering an easy-to-understand representation of the system.
- Comprehensive Documentation:
- Ensures comprehensive documentation of the system architecture, covering different levels of detail.
- Supports various documentation needs, from high-level overviews to detailed technical specifications.
Practical Usage of the C4 Model
- Starting with Context:
- Begin with a high-level context diagram to understand the system’s scope, external interactions, and primary users.
- Use this diagram to set the stage for more detailed diagrams.
- Defining Containers:
- Break down the system into its major containers, showing how they interact and are deployed.
- Highlight the technology choices and responsibilities of each container.
- Detailing Components:
- For each container, create a component diagram to illustrate the internal structure and interactions.
- Focus on how functionality is divided among components and how they collaborate.
- Exploring Code:
- If needed, delve into the code level for specific components to provide detailed documentation and analysis.
- Use class or sequence diagrams to show detailed code-level relationships and logic.
Example Scenario: Online Banking System
Context Diagram:
- System: Online Banking System
- External Systems: Payment Gateway, Credit Scoring Agency, Notification Service
- Users: Customers, Bank Employees, Administrators
- Description: Shows how customers interact with the banking system, which in turn interacts with external systems for payment processing, credit scoring, and notifications.
Containers Diagram:
- Containers: Web Application, Mobile Application, Backend API, Database
- Interactions: The web application and mobile application interact with the backend API. The backend API communicates with the database and external systems.
- Technology Stack: The web application might be built with Angular, the mobile application with React Native, the backend API with Spring Boot, and the database with PostgreSQL.
Components Diagram:
- Web Application Components: Authentication Service, User Dashboard, Transaction Module
- Backend API Components: Authentication Service, Account Management Module, Transaction Processing Service, Notification Handler
- Interactions: The Authentication Service in both the web application and backend API handles user authentication and security. The Transaction Module in the web application interacts with the Transaction Processing Service in the backend API.
Code Diagram:
- Classes: Transaction, TransactionProcessor, Account, NotificationService
- Methods: The
TransactionProcessorclass has methods for initiating, validating, and completing transactions. TheNotificationServiceclass has methods for sending notifications. - Relationships: The
TransactionProcessorcalls methods on theAccountclass to debit or credit funds. It also calls theNotificationServiceto send transaction alerts.
Conclusion
The C4 model is a powerful tool for visualising and documenting software architecture. By providing multiple levels of abstraction, it ensures that stakeholders at different levels of the organisation can understand the system. From high-level overviews to detailed code analysis, the C4 model facilitates clear communication, consistent documentation, and comprehensive understanding of complex software systems.
