C4 Architecture Diagrams — Complete Reference
Load this file when the user requests C4 diagrams or system architecture documentation. The C4 model provides four levels of abstraction.CRITICAL: Mandatory Rules
Every C4 diagram MUST follow these rules. Without them, Mermaid renders harsh black lines that overlap elements and make the diagram unreadable.- Max 6
Rel()per diagram. More relationships cause Dagre to route arrows through nodes, creating unreadable spaghetti. Split complex systems into multiple focused diagrams. - Always style all relationships. Apply
UpdateRelStyleto everyRel()with soft line colors (see template below). - Max 6-8 elements per diagram. Tree-shaped topology (1 in, 1-2 out per node) renders best. Avoid mesh connections.
- Do NOT set
fontFamily. Mermaid’s default font works everywhere. Settingsystem-uiorSegoe UIwill render as Times New Roman in headless Chromium.
Template: Add This to Every C4 Diagram
When Labels Overlap Elements
Add$offsetX and $offsetY to push labels away from elements:
Highlighting Important Relationships
Use accent colors for critical paths while keeping other lines soft:C4 Levels — When to Use Each
| Level | Diagram | Audience | Purpose |
|---|---|---|---|
| 1 | C4Context | Everyone | System boundaries and external actors |
| 2 | C4Container | Technical team | Applications, databases, services |
| 3 | C4Component | Developers | Internal module structure |
| 4 | C4Deployment | DevOps/SRE | Infrastructure and deployment nodes |
| — | C4Dynamic | Technical team | Numbered request flows |
Audience-Appropriate Recommendations
- Executives/PMs: Context only
- Architects: Context + Container
- Developers: Context + Container + Components for their area
- DevOps/SRE: Container + Deployment
Element Syntax
People and Systems
Containers
Components
Boundaries
Relationships
Rel_D, Rel_R, etc.) to force arrows in a specific direction. This is the most effective way to avoid overlapping lines.
Deployment Nodes
Complete Examples (All With Mandatory Styling)
Level 1 — System Context
Level 2 — Container
Keep container diagrams focused: max 6-8 elements and 6 Rel(). For complex systems, split into multiple diagrams (one per bounded context or service area).Level 3 — Component (Order Service)
C4 Dynamic — Request Flow
C4 Deployment
Styling and Layout
Layout Configuration
Element Styling
Relationship Styling
Use$offsetX and $offsetY to fix overlapping labels:
Professional Color Palette for Custom Element Styles
| Purpose | bgColor | fontColor | borderColor | When to use |
|---|---|---|---|---|
| Primary emphasis | #4f46e5 | #ffffff | #3730a3 | Core systems, main service |
| Success / Data store | #059669 | #ffffff | #047857 | Databases, completed states |
| Warning / External | #d97706 | #ffffff | #b45309 | External systems, risky paths |
| Error / Critical | #dc2626 | #ffffff | #b91c1c | Error states ONLY |
| Neutral / Secondary | #64748b | #ffffff | #475569 | Supporting services, background |
| Info / Highlight | #0284c7 | #ffffff | #0369a1 | Informational annotations |
Microservices Patterns
Single-Team Ownership
When one team owns all services, model each as a container:Multi-Team Ownership
When separate teams own services, promote them to systems:Event-Driven Architecture
Show individual topics/queues as containers — NOT a single “Kafka” box:Essential Rules
- Every element must have: Name, Type, Technology (where applicable), Description
- Use unidirectional arrows — bidirectional creates ambiguity
- Label arrows with action verbs — “Sends email using”, not just “uses”
- Include technology labels — “JSON/HTTPS”, “SQL”, “gRPC”
- Under 15 elements per diagram — split if more (elegance > completeness)
- Always include a title
- Meaningful aliases —
orderServicenots1 - ALWAYS add UpdateRelStyle — soft line colors are mandatory
- ALWAYS add UpdateLayoutConfig — prevents element crowding
Common Mistakes
| Mistake | Why it’s wrong | Fix |
|---|---|---|
| Shared lib as Container | Containers are deployable units | Model as Component |
| Single “Kafka” container | Hides topic structure | Show individual topics |
| ”Subcomponents” level | Not a C4 concept | Use Component or Class |
| Removing type labels | Loses information | Always show type/tech |
| Bidirectional arrows | Ambiguous flow direction | Use unidirectional |
| No technology labels | Can’t assess architecture | Add protocol/tech |
| No UpdateRelStyle | Harsh black lines | Add soft colors to ALL relationships |
| No UpdateLayoutConfig | Elements crowd together | Add layout config at end |
| No offset on overlap | Labels hidden behind elements | Add offsetY to fix |