agentsclimarketplace

C4 model

Skill kinhluan/skills/.agent-skills/c4-model

πŸš€ Professional Multi-Agent Skills

Install
npx -y skills add kinhluan/skills --skill c4-model

Assembled 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

SituationStart WithWhy
New project, no existing diagramsL1 System ContextEstablish scope and stakeholders first
Existing monolith, planning microservicesL2 ContainerIdentify deployable boundaries
Code review reveals tight couplingL3 ComponentFind circular dependencies
Complex domain model needs documentationL4 CodeUML class diagram or ERD
Onboarding new developerL1 β†’ L2 β†’ L3Progressive disclosure
Pitching to investorsL1 onlyBusiness 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

AspectMermaidStructurizr DSL
FormatMarkdown code block.dsl text file
RenderingGitHub, GitLab, docsStructurizr Lite/Cloud
Model reuseEach diagram standaloneSingle model β†’ multiple views
C4 complianceManual (C4Context, C4Container plugins)Enforced by DSL
AI-friendlyGoodExcellent (text-based, structured)
Best forQuick docs, READMEsSerious 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 LevelDDD ConceptClean ArchitectureMapping
L1 System ContextBounded Contexts (high-level)System BoundaryEach system in L1 β‰ˆ one Bounded Context
L2 ContainerSubdomainsDeployable UnitsContainers map to Core/Supporting/Generic subdomains
L2 ContainerContext MapContainer DependenciesRelationships between containers = Upstream/Downstream
L3 ComponentAggregate Roots / Domain ServicesPackage by ComponentSelf-contained packages: Entities + Use Cases + Adapters
L4 CodeEntities, Value ObjectsEntities, Use Cases, PortsClasses 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 LevelScan ForMaps To
L2package.json, pom.xml, go.mod, requirements.txtContainer tech stack
L2Dockerfile, docker-compose.yml, k8s/Deployment mapping
L2terraform/, CloudFormationInfrastructure components
L3src/services/, internal/, pkg/Component boundaries
L3*_test.go, *.test.tsComponent responsibilities (test names reveal intent)
L4Domain classes, DB migrationsUML classes, ERD tables

πŸ“š References

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.