Generate comprehensive C4 architecture documentation for an existing repository/codebase using a bottom-up analysis approach.
[Extended thinking: This workflow implements a complete C4 architecture documentation process following the C4 model (Context, Container, Component, Code). It uses a bottom-up approach, starting from the deepest code directories and working upward, ensuring every code element is documented before synthesizing into higher-level abstractions. The workflow coordinates four specialized C4 agents (Code, Component, Container, Context) to create a complete architectural documentation set that serves both technical and non-technical stakeholders.]
Use this skill when
Working on c4 architecture documentation workflow tasks or workflows
Needing guidance, best practices, or checklists for c4 architecture documentation workflow
Do not use this skill when
The task is unrelated to c4 architecture documentation workflow
You need a different domain or tool outside this scope
Instructions
Clarify goals, constraints, and required inputs.
Apply relevant best practices and validate outcomes.
Provide actionable steps and verification.
If detailed examples are required, open
resources/implementation-playbook.md
.
Overview
This workflow creates comprehensive C4 architecture documentation following the
official C4 model
by:
Code Level
Analyzing every subdirectory bottom-up to create code-level documentation
Component Level
Synthesizing code documentation into logical components within containers
Container Level
Mapping components to deployment containers with API documentation (shows high-level technology choices)
Context Level
Creating high-level system context with personas and user journeys (focuses on people and software systems, not technologies)
Note
According to the
C4 model
, you don't need to use all 4 levels of diagram - the system context and container diagrams are sufficient for most software development teams. This workflow generates all levels for completeness, but teams can choose which levels to use.
Type (Database, API, Service, Message Queue, etc.)
Description (what it provides)
Integration type (API, Events, File Transfer, etc.)
Purpose (why the system depends on this)
System Context Diagram
:
Mermaid C4Context diagram showing:
The system (as a box in the center)
All personas (users) around it
All external systems around it
Relationships and data flows
Use C4Context notation for proper C4 diagram
Related Documentation Section
:
Links to container documentation
Links to component documentation
Save the output as: C4-Documentation/c4-context.md
Ensure the documentation is:
Understandable by non-technical stakeholders
Focuses on system purpose, users, and external relationships
Includes comprehensive user journey maps
Identifies all external systems and dependencies
Expected output: c4-context.md with complete system context
Context: All container, component, and system documentation
Configuration Options
target_directory
Root directory to analyze (default: current repository root)
exclude_patterns
Patterns to exclude (default: node_modules, .git, build, dist, etc.)
output_directory
Where to write C4 documentation (default: C4-Documentation/)
include_tests
Whether to analyze test files for context (default: true)
api_format
Format for API specs (default: openapi)
Success Criteria
✅ Every subdirectory has a corresponding c4-code-*.md file
✅ All code-level documentation includes complete function signatures
✅ Components are logically grouped with clear boundaries
✅ All components have interface documentation
✅ Master component index created with relationship diagram
✅ Containers map to actual deployment units
✅ All container APIs documented with OpenAPI/Swagger specs
✅ Container diagram shows deployment architecture
✅ System context includes all personas (human and programmatic)
✅ User journeys documented for all key features
✅ All external systems and dependencies identified
✅ Context diagram shows system, users, and external systems
✅ Documentation is organized in C4-Documentation/ directory
Output Structure
C4-Documentation/
├── c4-code-*.md # Code-level docs (one per directory)
├── c4-component-*.md # Component-level docs (one per component)
├── c4-component.md # Master component index
├── c4-container.md # Container-level docs
├── c4-context.md # Context-level docs
└── apis/ # API specifications
├── [container]-api.yaml # OpenAPI specs for each container
└── ...
Coordination Notes
Bottom-up processing
Process directories from deepest to shallowest
Incremental synthesis
Each level builds on the previous level's documentation
Complete coverage
Every directory must have code-level documentation before synthesis
Link consistency
All documentation files link to each other appropriately
API documentation
Container APIs must have OpenAPI/Swagger specifications
Stakeholder-friendly
Context documentation should be understandable by non-technical stakeholders
Mermaid diagrams
Use proper C4 Mermaid notation for all diagrams
Example Usage
/c4-architecture:c4-architecture
This will:
Walk through all subdirectories bottom-up
Create c4-code-*.md for each directory
Synthesize into components
Map to containers with API docs
Create system context with personas and journeys
All documentation written to: C4-Documentation/