C4 Model: Visualizing Software Architecture
The C4 model provides a structured approach to architecture diagrams. After using C4 in production, here’s how to document architecture effectively.
C4 Model Levels
Level 1: System Context
Shows:
- System and users
- External systems
- High-level view
┌─────────┐
│ Users │
└────┬────┘
│
┌────▼────────────┐
│ E-Commerce │
│ System │
└────┬────────────┘
│
┌────▼────┐ ┌─────┐
│Payment │ │Email│
│Gateway │ │Svc │
└─────────┘ └─────┘
Level 2: Container Diagram
Shows:
- Applications
- Databases
- File systems
┌─────────────┐
│ Web App │
└──────┬──────┘
│
┌───┴───┬────────┬────────┐
│ │ │ │
┌──▼──┐ ┌──▼──┐ ┌──▼──┐ ┌───▼──┐
│ API │ │Auth │ │Order│ │Email │
│ Svc │ │ Svc │ │ Svc │ │ Svc │
└──┬──┘ └──┬──┘ └──┬──┘ └──┬───┘
│ │ │ │
┌──▼──┐ ┌──▼──┐ ┌──▼──┐
│Postg│ │Redis│ │SQS │
│res │ │ │ │ │
└─────┘ └─────┘ └─────┘
Level 3: Component Diagram
Shows:
- Components within container
- Relationships
- Technologies
Level 4: Code Diagram
Shows:
- Classes
- Functions
- Implementation details
Best Practices
- Start with context - System context first
- Use consistent notation - Standard symbols
- Keep it simple - Don’t over-complicate
- Update regularly - Keep current
- Use tools - Structurizr, Draw.io
- Document decisions - Link to ADRs
- Multiple views - Different perspectives
- Team collaboration - Shared understanding
Conclusion
The C4 model enables:
- Clear documentation
- Multiple abstraction levels
- Team alignment
- Maintainable diagrams
Start with system context, then drill down. The model shown here documents production architectures effectively.
C4 Model from January 2022, covering architecture visualization.