C4 architecture c4 architecture

From Zidong-LLC/BIBLIOTECA · View interactive version

C4 architecture c4 architecture is an AI agent skill from the GitHub repository Zidong-LLC/BIBLIOTECA. Generate comprehensive C4 architecture documentation for an existing repository/codebase using a bottom-up analysis approach.

How to use this skill

Skill file

C4 Architecture Documentation Workflow

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

Do not use this skill when

Instructions

Overview

This workflow creates comprehensive C4 architecture documentation following the official C4 model by:

  1. Code Level: Analyzing every subdirectory bottom-up to create code-level documentation
  2. Component Level: Synthesizing code documentation into logical components within containers
  3. Container Level: Mapping components to deployment containers with API documentation (shows high-level technology choices)
  4. 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.

All documentation is written to a new C4-Documentation/ directory in the repository root.

Phase 1: Code-Level Documentation (Bottom-Up Analysis)

1.1 Discover All Subdirectories

1.2 Process Each Directory (Bottom-Up)

For each directory, starting from the deepest:

Analyze the code in directory: [directory_path]

Create comprehensive C4 Code-level documentation following this structure:

1. Overview Section:

2. Code Elements Section:

3. Dependencies Section:

4. Relationships Section:

Save the output as: C4-Documentation/c4-code-[directory-name].md

Use a sanitized directory name (replace / with -, remove special chars) for the filename.

Ensure the documentation includes:

Repeat for every subdirectory until all directories have corresponding c4-code-\*.md files.

Phase 2: Component-Level Synthesis

2.1 Analyze All Code-Level Documentation

2.2 Create Component Documentation

For each identified component:

Synthesize the following C4 Code-level documentation files into a logical component:

Code files to analyze:

[List of c4-code-*.md file paths]

Create comprehensive C4 Component-level documentation following this structure:

1. Overview Section:

2. Purpose Section:

3. Software Features Section:

4. Code Elements Section:

5. Interfaces Section:

6. Dependencies Section:

7. Component Diagram:

Save the output as: C4-Documentation/c4-component-[component-name].md

Use a sanitized component name for the filename.

2.3 Create Master Component Index

Create a master component index that lists all components in the system.

Based on all c4-component-\*.md files created, generate:

1. System Components Section:

2. Component Relationships Diagram:

Save the output as: C4-Documentation/c4-component.md

Phase 3: Container-Level Synthesis

3.1 Analyze Components and Deployment Definitions

3.2 Map Components to Containers

Synthesize components into containers based on deployment definitions.

Component documentation:

[List of all c4-component-*.md file paths]

Deployment definitions found:

[List of deployment config files: Dockerfiles, K8s manifests, etc.]

Create comprehensive C4 Container-level documentation following this structure:

1. Containers Section (for each container):

2. Purpose Section (for each container):

3. Components Section (for each container):

4. Interfaces Section (for each container):

5. API Specifications:

6. Dependencies Section (for each container):

7. Infrastructure Section (for each container):

8. Container Diagram:

Save the output as: C4-Documentation/c4-container.md

Phase 4: Context-Level Documentation

4.1 Analyze System Documentation

4.2 Create Context Documentation

Create comprehensive C4 Context-level documentation for the system.

Container documentation: C4-Documentation/c4-container.md

Component documentation: C4-Documentation/c4-component.md

System documentation: [List of README, architecture docs, requirements, etc.]

Test files: [List of test files that show system behavior]

Create comprehensive C4 Context-level documentation following this structure:

1. System Overview Section:

2. Personas Section:

3. System Features Section:

4. User Journeys Section:

1. [Step 1]: [Description]

2. [Step 2]: [Description]

...

5. External Systems and Dependencies Section:

6. System Context Diagram:

7. Related Documentation Section:

Save the output as: C4-Documentation/c4-context.md

Ensure the documentation is:

Configuration Options

Success Criteria

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

Example Usage

/c4-architecture:c4-architecture

This will:

  1. Walk through all subdirectories bottom-up
  2. Create c4-code-\*.md for each directory
  3. Synthesize into components
  4. Map to containers with API docs
  5. Create system context with personas and journeys

All documentation written to: C4-Documentation/

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.