C4 model
π Professional Multi-Agent Skills
npx -y skills add kinhluan/skills --skill c4-modelAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
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.
SKILL.md
12.5 KB, as published. Nobody here has run it
C4 Model: Design-to-Code Sync Hub
The C4 model, created by Simon Brown, is a hierarchical approach to describing software architecture through four levels of abstraction. This skill focuses on Design-to-Code Sync: ensuring diagrams reflect actual code reality and code follows intended design.
"The C4 model is a simple way to bring consistency to how you and your team describe and diagram software architecture." β Simon Brown
π― The 4-Level Hierarchy
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β L1: SYSTEM CONTEXT β
β "Who uses the system and what external things does it β
β interact with?" β
β Audience: Executives, PMs, non-technical stakeholders β
β Scope: People + Systems (internal & external) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β L2: CONTAINERS β
β "What are the high-level technology building blocks?" β
β Audience: Architects, developers, ops β
β Scope: Apps, databases, message brokers, file systems β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β L3: COMPONENTS β
β "What are the logical building blocks inside each β
β container?" β
β Audience: Developers, tech leads β
β Scope: Controllers, services, repositories, gateways β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β L4: CODE (optional) β
β "How is a component implemented?" β
β Audience: Developers working on the component β
β Scope: Classes, interfaces, database schemas β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key principle: Each level zooms into the previous one. You cannot draw L3 without first having L2.
π§ When to Use Which Level
| Situation | Start With | Why |
|---|---|---|
| New project, no existing diagrams | L1 System Context | Establish scope and stakeholders first |
| Existing monolith, planning microservices | L2 Container | Identify deployable boundaries |
| Code review reveals tight coupling | L3 Component | Find circular dependencies |
| Complex domain model needs documentation | L4 Code | UML class diagram or ERD |
| Onboarding new developer | L1 β L2 β L3 | Progressive disclosure |
| Pitching to investors | L1 only | Business value, not technology |
π The C4 Workflow
Phase 1: DISCOVER Phase 2: MODEL Phase 3: SYNC
ββββββββββββββββββββ ββββββββββββββββββββ ββββββββββββββββββββ
β Interview β β Draw L1 Context β β Scan codebase β
β stakeholders βββββββΆβ (Mermaid/ ββββββΆβ for drift β
β Identify users β β Structurizr) β β Update diagrams β
β List external β β β β β
β systems β β Draw L2 Containerβ β Verify L2 maps β
ββββββββββββββββββββ β (tech stack) β β to Dockerfile/ β
β β β docker-compose β
β Draw L3 Componentβ β β
β (per container) β β Verify L3 maps β
β β β to folder struct β
β L4: Optional β β β
β (complex only) β β ADR for major β
ββββββββββββββββββββ β decisions β
ββββββββββββββββββββ
π« Architectural Anti-Patterns (The "Don'ts")
1. The "Spaghetti" Diagram
Symptom: More than 20 elements in one diagram.
Solution: Break into multiple views (e.g., "Customer Journey View", "Admin View").
Reference: Simon Brown recommends 5-15 elements per diagram for readability.
2. Tech Leakage in L1
Symptom: Mentioning "React", "PostgreSQL", "Kafka" in System Context.
Solution: L1 focuses on "What", not "How". Use "Product Catalog" not "PostgreSQL".
Rule: If a non-technical stakeholder wouldn't understand it, it doesn't belong in L1.
3. Missing Descriptions
Symptom: Boxes with only names.
Solution: Every element needs a one-sentence responsibility description.
Template: [Name] β [What it does] for [Who].
4. Ambiguous Arrows
Symptom: Labels like "Uses", "Sends", "Connects".
Solution: Use action verbs: "Authenticates user via", "Publishes order event to", "Queries inventory from".
5. Phantom Containers
Symptom: Modeling a shared library (e.g., "utils.jar") as a container.
Solution: Libraries are components (L3), not containers (L2). Containers must be independently deployable/runnable.
6. The "Everything Diagram"
Symptom: Trying to show L1, L2, and L3 in one diagram.
Solution: One diagram per level. Use hyperlinks or navigation to connect them.
7. Stale Diagrams
Symptom: Diagrams don't match the code.
Solution: Use "Design-to-Code Sync" β scan codebase on every major refactor. Store diagrams as code (Mermaid/Structurizr DSL) in version control.
π Tooling: Mermaid vs Structurizr DSL
| Aspect | Mermaid | Structurizr DSL |
|---|---|---|
| Format | Markdown code block | .dsl text file |
| Rendering | GitHub, GitLab, docs | Structurizr Lite/Cloud |
| Model reuse | Each diagram standalone | Single model β multiple views |
| C4 compliance | Manual (C4Context, C4Container plugins) | Enforced by DSL |
| AI-friendly | Good | Excellent (text-based, structured) |
| Best for | Quick docs, READMEs | Serious architecture, CI/CD |
Recommendation: Use Mermaid for quick sketches and READMEs. Use Structurizr DSL for project architecture that lives in version control.
Structurizr DSL Quick Example
workspace {
model {
user = person "Customer" "A registered user of the platform."
ecommerce = softwareSystem "E-Commerce Platform" "Allows customers to browse and purchase products." {
webapp = container "Web Application" "React/TypeScript" "Customer-facing UI."
api = container "API Service" "Go/gRPC" "Business logic and API gateway."
db = container "Database" "PostgreSQL" "Stores products, orders, users."
}
payment = softwareSystem "Payment Gateway" "External" "Processes payments."
user -> webapp "Browses and purchases"
webapp -> api "Calls API"
api -> db "Reads/Writes"
api -> payment "Processes payment"
}
views {
systemContext ecommerce "SystemContext" {
include *
autolayout lr
}
container ecommerce "Containers" {
include *
autolayout lr
}
theme default
}
}
π¦ Standard Artifacts
Every C4 modeling session should produce:
docs/architecture/
βββ workspace.dsl # Structurizr DSL (single source of truth)
βββ L1-system-context.md # Mermaid for README/docs
βββ L2-containers.md
βββ L3-components/
β βββ api-service.md
β βββ web-app.md
βββ architecture-decisions.md # ADRs for major tech choices
βββ README.md # Index + navigation
π C4 + DDD + Clean Architecture Integration Matrix
| C4 Level | DDD Concept | Clean Architecture | Mapping |
|---|---|---|---|
| L1 System Context | Bounded Contexts (high-level) | System Boundary | Each system in L1 β one Bounded Context |
| L2 Container | Subdomains | Deployable Units | Containers map to Core/Supporting/Generic subdomains |
| L2 Container | Context Map | Container Dependencies | Relationships between containers = Upstream/Downstream |
| L3 Component | Aggregate Roots / Domain Services | Package by Component | Self-contained packages: Entities + Use Cases + Adapters |
| L4 Code | Entities, Value Objects | Entities, Use Cases, Ports | Classes in UML/class diagrams |
Workflow: Use ddd-core to discover Bounded Contexts β map to L1/L2 β use clean-architecture to structure L3 components β verify with ddd-tactical scoring rubric.
C4 + Clean Architecture: Simon Brown's Contribution
Simon Brown (creator of C4 Model) wrote "The Missing Chapter" for Robert C. Martin's Clean Architecture book (2017). Key insight:
Package by Component, not by Layer. Each C4 L3 Component should be a self-contained package with its own Entities, Use Cases, and Adapters β exposing only a minimal public API.
C4 L3 Component = Clean Architecture "Package by Component"
order/ β C4 L3 Component
index.ts β Public API (what others can use)
internal/
entity/Order.ts β Entities (inner circle)
usecase/SubmitOrder.ts β Use Cases (middle circle)
adapter/OrderController.ts β Interface Adapters (outer circle)
adapter/PostgresOrderRepo.ts
For detailed Clean Architecture principles (Dependency Rule, Ports & Adapters, testing strategy), use the clean-architecture skill.
π¦ DORA: Loosely Coupled Architecture
DORA research identifies Loosely Coupled Architecture as the #1 predictor of high Deployment Frequency. C4 decisions directly affect delivery:
- C4 L2 containers should be independently deployable β each owns its data
- Conway's Law: Tightly coupled teams β tightly coupled architecture β Low DORA tier
- Anti-pattern: Shared database between containers = coordinated deployments
For DORA metrics assessment, use dora-core skill.
π Smart Synthesis (Design-to-Code)
When documenting an existing project, scan the codebase first:
| C4 Level | Scan For | Maps To |
|---|---|---|
| L2 | package.json, pom.xml, go.mod, requirements.txt | Container tech stack |
| L2 | Dockerfile, docker-compose.yml, k8s/ | Deployment mapping |
| L2 | terraform/, CloudFormation | Infrastructure components |
| L3 | src/services/, internal/, pkg/ | Component boundaries |
| L3 | *_test.go, *.test.ts | Component responsibilities (test names reveal intent) |
| L4 | Domain classes, DB migrations | UML classes, ERD tables |
π References
- C4 Model Official β Simon Brown
- Structurizr DSL β Reference implementation
- Software Architecture for Developers β Simon Brown's book
- The C4 Model on ThoughtWorks Tech Radar
- Clean Architecture β Robert C. Martin (2017). Contains "The Missing Chapter" by Simon Brown on Package by Component.
- Package by Component β Simon Brown