1---2name: viz-c4-diagram3description: Generate C4 architecture diagrams using Mermaid syntax. Use when the user says "draw a C4 diagram", "architecture diagram", "system context diagram", "container diagram", "component diagram", or "visualize the architecture".4---5
6# Generate C4 Diagrams
7
8## Path Resolution
9
101. Read `workflow.json` in the project root
112. If it exists and `docsRepo` is `"."`: this IS the docs repo — use local paths
123. If it exists and `docsRepo` is a repo name: resolve via `pwsh .claude/skills/tool-worktree/scripts/resolve-repo.ps1 <docsRepo>` to get the docs root path. Templates at `<resolved>/templates/`, output to `<resolved>/architecture/`
134. If no `workflow.json`: templates at `templates/`, output to `docs/architecture/`
14
15## Instructions
16
171. **Resolve paths** (see Path Resolution above)
182. **Read the template** at `<templates>/c4-diagrams.md` for Mermaid C4 syntax reference
192. **Determine the scope**:
20 - What system or subsystem to diagram?
21 - What level(s)? (Context, Container, Component, Code)
22 - If not specified, start with Context + Container
233. **Analyze the codebase** if diagramming an existing system:
24 - Read project structure and key files
25 - Identify external dependencies and integrations
26 - Map internal components and their relationships
274. **Generate diagrams** using Mermaid C4 syntax:
28 - **Level 1 — Context**: `C4Context` — system and its environment
29 - **Level 2 — Container**: `C4Container` — high-level tech building blocks
30 - **Level 3 — Component**: `C4Component` — internals of a container
31 - **Level 4 — Code**: `classDiagram` — class/interface relationships
325. **Save** to the appropriate location:
33 - Standalone: `<output>/[system]-c4.md`
34 - As part of a design doc: embed in the design doc directly
35
36## C4 Level Guide
37
38### Level 1: System Context
39- **Audience**: Everyone (tech and non-tech)
40- **Shows**: The system as a box, users, and external systems
41- **Elements**: `Person`, `System`, `System_Ext`, `Rel`
42
43### Level 2: Container
44- **Audience**: Technical people
45- **Shows**: Applications, databases, message queues, file systems
46- **Elements**: `Container`, `ContainerDb`, `ContainerQueue`, `System_Ext`, `System_Boundary`
47
48### Level 3: Component
49- **Audience**: Developers
50- **Shows**: Components inside a container (services, repositories, controllers)
51- **Elements**: `Component`, `Container_Boundary`, `ContainerDb`
52
53### Level 4: Code
54- **Audience**: Developers working on the component
55- **Shows**: Classes, interfaces, relationships
56- **Use**: Standard Mermaid `classDiagram` (not C4 syntax)
57
58## Quality Checklist
59
60- [ ] Each diagram has a descriptive title
61- [ ] Relationships have labels describing what flows between elements
62- [ ] External systems are clearly distinguished (`_Ext` suffix)
63- [ ] Technology choices are annotated (e.g., "ASP.NET Core", "PostgreSQL")
64- [ ] Diagrams zoom in logically (Context → Container → Component)
65- [ ] No diagram has more than ~15 elements (split if larger)
66
67## Tips
68
69- Start broad (Context) and zoom in — don't jump to Component level
70- Every relationship arrow should have a verb ("Calls", "Reads from", "Publishes to")
71- Include the technology in element descriptions ("Angular", "REST/JSON", "gRPC")
72- For deployment diagrams, use `C4Deployment` with `Deployment_Node`