agentsclimarketplace

C4 level3 component

Skill kinhluan/skills/.agent-skills/c4-level3-component

πŸš€ Professional Multi-Agent Skills

Install
npx -y skills add kinhluan/skills --skill c4-level3-component

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

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

StakeholderWhat they need from L3Questions they ask
DevelopersModule boundaries, where to add new code"Where does the payment logic go?"
Tech LeadsLayering, Separation of Concerns"Is our dependency direction correct?"
ArchitectsDesign consistency, pattern adherence"Are we following Clean Architecture?"
New HiresOnboarding, 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-PatternSymptomFix
Over-DetailingEvery class drawnOnly major logical groupings (5-15 components)
Mixing ContainersComponents from multiple containersFocus on ONE container per diagram
Circular DependenciesA→B→C→A cycleRefactor: extract shared interface, merge, or restructure
Anemic ComponentsComponent with no clear responsibilityRename to reflect single responsibility
Layer ViolationDomain imports infrastructureIn Clean/Hexagonal: domain must have zero external deps
God ComponentOne component handles everythingSplit 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 SignalL4 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

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.