c4-level2-container
C4 Level 2: Container Diagram & Infrastructure Mapping
The Container diagram represents the high-level technical architecture (web apps, mobile apps, databases, background jobs).
🎯 Stakeholder Focus
- Architects: High-level tech decisions and API boundaries.
- Developers: High-level system structure and cross-app communication.
- Ops/DevOps: Deployment strategy and infrastructure mapping.
🛠 Infrastructure Mapping
Level 2 should ideally map to actual infrastructure components:
- Web App/Mobile App: Maps to a build artifact or deployment.
- API/Service: Maps to a Docker container or K8s deployment.
- Database: Maps to a managed cloud DB or persistent container.
- Message Broker: Maps to Kafka, RabbitMQ, or Pub/Sub.
🚫 Anti-Patterns to Guard (Level 2)
- NOT A FLOWCHART: Avoid modeling complex business logic; use a sequence diagram for that.
- NO LIBRARIES: Shared libraries (DLL, JAR, NuGet) are NOT containers.
- READABILITY: If the system has >10 containers, consider multiple Level 2 views (e.g., "Customer View", "Admin View").
🔍 Codebase Scanning (L2 Synthesis)
To identify containers in an existing codebase, scan for:
- Build manifests:
package.json,pom.xml,go.mod,requirements.txt. - Docker files:
Dockerfile,docker-compose.yml. - Infrastructure:
Terraformfiles,k8s/manifests.
Mermaid Template (Enhanced C4Container)
C4Container
title [System Name] - Container Diagram
Person(customer, "User", "Uses the system to browse products.")
System_Boundary(my_system, "System Name") {
Container(web_app, "Web App", "React/TypeScript", "User interface for browsing products.")
Container(api_svc, "API Service", "Go/gRPC", "Main business logic and API gateway.")
ContainerDb(user_db, "User DB", "PostgreSQL", "Stores user profiles and history.")
Container(worker, "Order Processor", "NodeJS/TS", "Processes background order tasks.")
}
System_Ext(bank, "Bank API", "REST API")
Rel(customer, web_app, "Uses", "HTTPS")
Rel(web_app, api_svc, "Calls API", "JSON/HTTPS")
Rel(api_svc, user_db, "Reads/Writes", "gRPC/TCP")
Rel(api_svc, worker, "Triggers processing", "Pub/Sub")
Rel(worker, bank, "Finalizes payment", "HTTPS/REST")
Level 2 Success Criteria
- Are all containers separately deployable units?
- Are all cross-container protocols (JSON, SQL, gRPC) specified?
- Is the diagram readable and clearly bounded?
- SMART: Do the containers match build/deployment artifacts in the code?
More from kinhluan/skills
scheduling-algorithms
Job scheduling algorithms for parallel and distributed systems
5ddd-core
Professional Strategic Domain-Driven Design (DDD) Hub. Use this skill for Event Storming, identifying Subdomains, defining Bounded Contexts, and mapping Domain Models to the heart of your architecture.
4c4-model
Professional C4 model architecture hub for "Design-to-Code Sync". Use this skill to navigate the C4 hierarchy, map diagrams to stakeholders, avoid architectural anti-patterns, and choose the right level for designing or documenting existing codebases.
4ddd-tactical
Tactical Domain-Driven Design (DDD) with Scoring Rubric. Use this skill when designing internal domain models or performing architectural reviews to ensure domain logic is isolated and rich.
4ddd-patterns
Advanced Domain-Driven Design (DDD) Integration Patterns. Use this skill for implementing CQRS, Event Sourcing, the Outbox Pattern, and Anti-Corruption Layers (ACL) in distributed systems.
4c4-level4-code
Specialized in Code diagrams (Level 4) of the C4 model. Use this skill when the user needs to describe the internal implementation of a component using UML class diagrams or database ER diagrams.
4