C4 level3 component
π Professional Multi-Agent Skills
npx -y skills add kinhluan/skills --skill c4-level3-componentAssembled 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
Specialized in Component diagrams (Level 3) with folder structure mapping. Use this skill when the user needs to zoom into a single container to identify internal components, their responsibilities, and how they map to actual code folders (src/services, internal/).
SKILL.md
16.2 KB, as published. Nobody here has run it
C4 Level 3: Component Diagram & Folder Mapping
Level 3 focuses on the internal architecture of a single container, bridging the gap between high-level containers and low-level code. This is where architecture patterns (Clean, Hexagonal, Onion, Vertical Slice) become visible.
"A component is a grouping of related functionality behind a well-defined interface." β Simon Brown
π― Stakeholder Focus
| Stakeholder | What they need from L3 | Questions they ask |
|---|---|---|
| Developers | Module boundaries, where to add new code | "Where does the payment logic go?" |
| Tech Leads | Layering, Separation of Concerns | "Is our dependency direction correct?" |
| Architects | Design consistency, pattern adherence | "Are we following Clean Architecture?" |
| New Hires | Onboarding, codebase navigation | "How is this container organized?" |
ποΈ Architecture Patterns & Component Mapping
Pattern 1: Layered Architecture (Traditional)
βββββββββββββββββββββββββββββββββββββββββββ
β Presentation Layer β
β ββ Controller/Handler β
β ββ DTO/ViewModel β
βββββββββββββββββββββββββββββββββββββββββββ€
β Business Logic Layer β
β ββ Service β
β ββ Domain Model (Entity, VO) β
βββββββββββββββββββββββββββββββββββββββββββ€
β Data Access Layer β
β ββ Repository β
β ββ ORM/Data Mapper β
βββββββββββββββββββββββββββββββββββββββββββ
Folder Mapping:
src/
βββ api/ β Presentation (controllers, handlers)
βββ services/ β Business Logic (application services)
βββ domain/ β Domain Model (entities, value objects)
βββ repositories/ β Data Access (repository interfaces + implementations)
βββ dto/ β Data Transfer Objects
Pattern 2: Clean Architecture (Robert C. Martin)
βββββββββββββββ
β Frameworks β β Outer: UI, DB, External APIs
β & Drivers β
ββββββββ¬βββββββ
β depends on
ββββββββ΄βββββββ
β Interface β β Adapters: Controllers, Presenters, Gateways
β Adapters β
ββββββββ¬βββββββ
β depends on
ββββββββ΄βββββββ
β Use Cases β β Application Business Rules
β (Services) β
ββββββββ¬βββββββ
β depends on
ββββββββ΄βββββββ
β Entities β β Enterprise Business Rules (innermost)
βββββββββββββββ
Dependency Rule: Dependencies point INWARD only. Inner circles know nothing about outer circles.
Folder Mapping (Go example):
internal/
βββ domain/ β Entities (pure business logic, no dependencies)
β βββ order.go
β βββ value_objects.go
βββ usecase/ β Use Cases (application services)
β βββ place_order.go
β βββ cancel_order.go
βββ interface/ β Adapters (driven + driving)
β βββ controller/ β HTTP handlers
β βββ presenter/ β Response formatters
β βββ gateway/ β External API clients
βββ infrastructure/ β Frameworks (DB, cache, message queue)
βββ repository/ β DB implementations
βββ messaging/ β Event publishers
Pattern 3: Hexagonal Architecture (Ports & Adapters)
ββββββββββββββββ
βββββββββββ Driving βββββββββββ
β β Adapters β β
β HTTP β (Primary) β CLI β
β Handler β β Tool β
ββββββ¬βββββ΄βββββββββββββββ΄βββββ¬βββββ
β β
β ββββββββββββββββ β
βββββΆβ Application ββββββ
β Core (Domain)β
β β
βββββΆβ Ports ββββββ
β ββββββββββββββββ β
ββββββ΄βββββ¬βββββββββββββββ¬βββββ΄βββββ
β DB β External β Message β
β Adapter β API Client β Queue β
β(Driven) β (Driven) βAdapter β
βββββββββββ΄βββββββββββββββ΄ββββββββββ
Driven Adapters (Secondary)
Key Concepts:
- Port: Interface defining what the application needs (driven) or provides (driving)
- Adapter: Implementation of a port for a specific technology
- Domain: Pure business logic, zero external dependencies
Folder Mapping:
src/
βββ application/ β Use cases, domain services
β βββ port/
β β βββ in/ β Driving ports (interfaces app exposes)
β β βββ out/ β Driven ports (interfaces app needs)
β βββ service/
βββ domain/ β Entities, value objects, domain events
βββ adapter/
βββ in/ β Driving adapters (HTTP, CLI, messaging)
β βββ web/
β βββ cli/
βββ out/ β Driven adapters (DB, external APIs)
βββ persistence/
βββ external/
Pattern 4: Vertical Slice Architecture
src/
βββ features/
β βββ place_order/ β One folder per feature
β β βββ handler.go β HTTP handler
β β βββ command.go β CQRS command
β β βββ validator.go β Input validation
β β βββ service.go β Business logic
β β βββ repository.go β Data access
β β βββ dto.go β Request/response types
β β
β βββ cancel_order/
β β βββ handler.go
β β βββ command.go
β β βββ ...
β β
β βββ list_orders/
β βββ handler.go
β βββ query.go β CQRS query
β βββ ...
β
βββ shared/ β Cross-cutting concerns
βββ middleware/
βββ auth/
βββ logging/
Principle: Each feature is self-contained. No horizontal layers. Changes to "Place Order" only touch features/place_order/.
π Mermaid Templates
Template A: Layered Architecture (API Service)
C4Component
title Component Diagram for API Service
Container(spa, "Web App", "React/TS", "Customer SPA")
Container_Boundary(api, "API Service") {
Component(auth_ctrl, "Auth Controller", "Go Handler", "Handles login, registration, token refresh.")
Component(order_ctrl, "Order Controller", "Go Handler", "Handles order CRUD operations.")
Component(auth_svc, "Auth Service", "Go", "Validates credentials, generates JWTs.")
Component(order_svc, "Order Service", "Go", "Business logic for order lifecycle.")
Component(payment_svc, "Payment Service", "Go", "Orchestrates payment processing.")
Component(auth_repo, "Auth Repository", "SQL Client", "User persistence.")
Component(order_repo, "Order Repository", "SQL Client", "Order persistence.")
Component(payment_client, "Payment Client", "HTTP Client", "Stripe API integration.")
Component(jwt_util, "JWT Utility", "Go", "Token generation and validation.")
Component(event_pub, "Event Publisher", "Go", "Publishes domain events.")
}
ContainerDb(db, "Database", "PostgreSQL", "Primary data store.")
System_Ext(stripe, "Stripe", "Payment processing.")
Rel(spa, auth_ctrl, "POST /login", "JSON/HTTPS")
Rel(spa, order_ctrl, "POST /orders", "JSON/HTTPS")
Rel(auth_ctrl, auth_svc, "Calls", "Method call")
Rel(order_ctrl, order_svc, "Calls", "Method call")
Rel(auth_svc, auth_repo, "Uses", "Method call")
Rel(auth_svc, jwt_util, "Uses", "Method call")
Rel(order_svc, order_repo, "Uses", "Method call")
Rel(order_svc, payment_svc, "Uses", "Method call")
Rel(payment_svc, payment_client, "Uses", "Method call")
Rel(order_svc, event_pub, "Uses", "Method call")
Rel(auth_repo, db, "Reads/Writes", "SQL/TCP")
Rel(order_repo, db, "Reads/Writes", "SQL/TCP")
Rel(payment_client, stripe, "API calls", "REST/HTTPS")
Template B: Clean Architecture (Go)
C4Component
title Component Diagram β Clean Architecture (Order Service)
Container(spa, "Web App", "React", "Customer UI")
Container_Boundary(order_service, "Order Service (Clean Arch)") {
Component(handler, "HTTP Handler", "Go", "Adapter: converts HTTP to use case input.")
Component(presenter, "JSON Presenter", "Go", "Adapter: formats use case output.")
Component(place_order_uc, "Place Order Use Case", "Go", "Application: orchestrates order creation.")
Component(cancel_order_uc, "Cancel Order Use Case", "Go", "Application: handles cancellation.")
Component(order_entity, "Order Entity", "Go", "Domain: order business rules.")
Component(order_repo_intf, "Order Repository (Interface)", "Go", "Domain: port for persistence.")
Component(payment_intf, "Payment Gateway (Interface)", "Go", "Domain: port for payments.")
Component(order_repo_impl, "Order Repository (Impl)", "Go + SQL", "Infrastructure: PostgreSQL adapter.")
Component(stripe_adapter, "Stripe Adapter", "Go + HTTP", "Infrastructure: Stripe API adapter.")
}
ContainerDb(db, "Order DB", "PostgreSQL")
System_Ext(stripe, "Stripe API")
Rel(spa, handler, "POST /orders", "JSON/HTTPS")
Rel(handler, place_order_uc, "Invokes", "Method call")
Rel(place_order_uc, order_entity, "Creates", "Method call")
Rel(place_order_uc, order_repo_intf, "Saves via", "Interface")
Rel(place_order_uc, payment_intf, "Charges via", "Interface")
Rel(order_repo_intf, order_repo_impl, "Implemented by", "Dependency Injection")
Rel(payment_intf, stripe_adapter, "Implemented by", "Dependency Injection")
Rel(order_repo_impl, db, "SQL queries", "TCP")
Rel(stripe_adapter, stripe, "API calls", "HTTPS")
π Folder Structure Mapping by Language
Go (Clean Architecture)
internal/
βββ domain/
β βββ entity/
β β βββ order.go
β βββ valueobject/
β β βββ money.go
β βββ event/
β βββ order_placed.go
βββ usecase/
β βββ place_order.go
β βββ cancel_order.go
βββ adapter/
β βββ in/
β β βββ http/
β β βββ order_handler.go
β βββ out/
β βββ persistence/
β β βββ order_repository.go
β βββ payment/
β βββ stripe_adapter.go
βββ config/
βββ app.go
Python (Hexagonal / FastAPI)
src/
βββ domain/
β βββ models/
β β βββ order.py
β βββ value_objects/
β β βββ money.py
β βββ events/
β βββ order_placed.py
βββ application/
β βββ ports/
β β βββ in/
β β β βββ order_use_case.py
β β βββ out/
β β βββ order_repository.py
β β βββ payment_gateway.py
β βββ services/
β βββ order_service.py
βββ adapters/
β βββ in/
β β βββ web/
β β βββ order_router.py
β βββ out/
β βββ persistence/
β β βββ sqlalchemy_order_repo.py
β βββ payment/
β βββ stripe_client.py
βββ main.py
TypeScript (Vertical Slice / NestJS-style)
src/
βββ features/
β βββ orders/
β β βββ orders.module.ts
β β βββ place-order/
β β β βββ place-order.handler.ts
β β β βββ place-order.command.ts
β β β βββ place-order.dto.ts
β β βββ cancel-order/
β β β βββ ...
β β βββ list-orders/
β β βββ ...
β βββ payments/
β βββ ...
βββ shared/
β βββ decorators/
β βββ filters/
β βββ guards/
βββ main.ts
π« Anti-Patterns to Guard (Level 3)
| Anti-Pattern | Symptom | Fix |
|---|---|---|
| Over-Detailing | Every class drawn | Only major logical groupings (5-15 components) |
| Mixing Containers | Components from multiple containers | Focus on ONE container per diagram |
| Circular Dependencies | AβBβCβA cycle | Refactor: extract shared interface, merge, or restructure |
| Anemic Components | Component with no clear responsibility | Rename to reflect single responsibility |
| Layer Violation | Domain imports infrastructure | In Clean/Hexagonal: domain must have zero external deps |
| God Component | One component handles everything | Split by responsibility or feature |
π Codebase Scanning (L3 Synthesis)
# Identify component boundaries by folder structure
find src -type d -maxdepth 2 | sort
# Look for architecture patterns
grep -r "interface\|abstract class\|port\|adapter" src/ --include="*.go" --include="*.ts" --include="*.py"
# Check dependency direction (domain should not import infrastructure)
# In Go: check go.mod or import paths
grep -r "infrastructure\|adapter\|external" internal/domain/ || echo "β
Clean: domain has no infra imports"
# Find circular dependencies
# Go: use golang.org/x/tools/cmd/depgraph or go mod graph
# Python: use pipdeptree or import-linter
# TypeScript: use madge
β Level 3 Success Criteria
- Does the diagram map directly to the container's folder structure?
- Are internal interactions (method calls/internal events) clearly labeled?
- Is it clear how each component contributes to the container's responsibility?
- STRICT: Does it focus only on the zoomed-in container?
- STRICT: Are there β€15 components?
- Does the dependency direction follow the chosen architecture pattern?
- Are circular dependencies identified and resolved?
π From L3 to L4
| L3 Signal | L4 Action |
|---|---|
| "This component has complex internal logic" | UML class diagram |
| "The data model is hard to understand" | ERD (Entity Relationship Diagram) |
| "New developers struggle with this module" | Document key classes and their relationships |
| "We need to refactor this component" | L4 reveals exact coupling points |
Next: Use c4-level4-code for implementation details.
π References
- C4 Model β Component Diagram β Simon Brown
- Clean Architecture β Robert C. Martin
- Hexagonal Architecture β Alistair Cockburn
- Vertical Slice Architecture β Jimmy Bogard