C4 model: Container diagrams
简介 / Introduction
The C4 model provides a layered approach to describing software architecture — Context, Container, Component, and Code — with Container diagrams focusing on the key application processes and data stores inside a system’s boundary. This article renders the same Container diagram using both PlantUML (stdlib) and Mermaid (built-in C4 extension).
PlantUML 版
PlantUML uses !include <C4> to load the C4 stdlib, declares containers with Container(...), uses ContainerDb for data stores, and System_Boundary to group components:
1 | !include <C4/C4_Container> |
Mermaid 版
Mermaid’s C4 syntax uses the c4Context diagram type with Container/ContainerDb/System nodes:
1 | c4Context |
对比 / Side-by-side
| Feature | PlantUML | Mermaid |
|---|---|---|
| Diagram type declaration | !include <C4/C4_Container> + diagram type |
c4Context |
| Container node | Container(id, name, tech, desc) |
Container(id, name, tech, desc) |
| Database node | ContainerDb(id, name, tech, desc) |
ContainerDb(id, name, tech, desc) |
| System boundary | System_Boundary(name) { ... } |
System_Boundary(name) |
| External system | System(name, desc) |
System(name, desc) |
| Relationship arrow | Rel(source, target, label) |
Rel(source, target, label) |
| Stdlib required | Yes (plantuml-stdlib) |
No (C4 built into Mermaid) |
小结 / Wrap-up
PlantUML’s C4 stdlib is semantically complete and feature-rich, ideal for formal architecture documentation that strictly follows the C4 spec — but it requires the stdlib to be installed on the backend. Mermaid ships C4 syntax natively, making it frictionless for quick prototypes and internal docs. Both export to SVG; when embedding in Confluence or Notion, consider injecting xmlns:xlink to ensure images render correctly.
- Title: C4 model: Container diagrams
- Author: puml.online
- Created at : 2026-09-27 09:00:00
- Updated at : 2026-09-29 01:06:38
- Link: https://puml.online/blog/c4-diagram-container-en/
- License: This work is licensed under CC BY-NC-SA 4.0.