The C4 model is a hierarchy of diagrams for visualizing and documenting software architecture. Its four levels—context, containers, components, and code—move from a system’s external environment to its implementation details. This layered view lets developers, architects, and stakeholders discuss the same design at an appropriate level of abstraction. section 3.3
Use each level to answer a different architectural question:
- Context shows the system, its users, and the external systems it interacts with. section 3.3
- Containers show the primary building blocks, such as web applications, databases, and microservices, plus their interactions. section 3.3
- Components decompose a container into services, libraries, and modules, including their dependencies. section 3.3
- Code records the classes, interfaces, and functions that make up components. section 3.3
Start broad and drill inward only when the audience needs more detail. A context diagram establishes boundaries; container and component diagrams explain structure and collaboration; a code diagram connects the architecture to the object model. The model supports both documentation and design conversations because each diagram preserves a clear scope. section 3.3 section 3.4
IT asset management system
For an IT asset management application, a context diagram can show interactions inside and outside the system. A container diagram then identifies the application’s major parts and relationships, while component and code diagrams expose progressively more detailed interactions and relevant classes. Generate Mermaid diagrams from a precise request, then inspect whether the depicted elements and relationships match the intended design. section 3.3 section 3.3
C4 diagrams can be generated alongside other design artifacts, including class diagrams and business requirements documentation. The diagrams are most useful when prompts name the desired system elements and when the resulting architecture remains open to discussion and refinement rather than being accepted as a final design automatically. section 3.3 section 3.4
