liveBook · Manning

C4 model

As explained in AI-Powered Developer: Build software with ChatGPT and Copilot

The C4 model is a hierarchical diagramming model for visualizing and documenting software architecture at context, container, component, and code levels.

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

How AI-Powered Developer: Build software with ChatGPT and Copilot covers it

How deep it goes
Defines all four levels from system context through code elements, without detailing diagram notation or construction rules.
Examples
Illustrates an IT asset management system through Mermaid context, container, component, and code diagrams.
What you can do after
Apply it via ChatGPT to generate layered architecture diagrams for an application.
How it connects
Connects software architecture with class diagrams, hexagonal architecture, SOLID principles, and the Visitor pattern.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Developer: Build software with ChatGPT and Copilot. The section links point to the parts of the book it draws on.