C4 Container Diagram Generator
Generate C4 Container diagrams following Simon Brown's C4 model standard, exported as editable .drawio XML files that open directly in draw.io (desktop or web).
When to Use
Explicit triggers:
- User asks for a C4 diagram, container diagram, or architecture diagram
- User says "draw the architecture", "system diagram", "show me the components"
- User needs to visualize system architecture for documentation or a presentation
- User mentions draw.io, drawio, or wants an editable diagram
Proactive triggers:
- Explaining a system with 3+ interacting components
- Discussing microservices, APIs, databases, and their relationships
- Reviewing or designing system architecture
Skip when:
- User wants a simple flowchart (use Mermaid instead)
- User wants UI wireframes or mockups
- The system has fewer than 3 components
Process
Step 1: Gather Requirements
Identify from the conversation or ask the user:
- What system are we diagramming?
- Who are the users/actors (Person)?
- What containers exist (apps, services, databases, queues, file storage)?
- What external systems does it interact with?
- What are the key data flows and protocols?
If the user provides a spec, codebase description, or architecture overview, extract elements automatically and confirm before generating.
Step 2: Classify Elements
Map every element to a C4 category:
| Category |
Color |
Shape |
Description |
| Person |
#08427B (dark blue) |
shape=actor + text label |
Users, actors, roles |
| Container |
#438DD5 (blue) |
Rounded rectangle |
Applications, services, APIs |
| Database |
#438DD5 (blue) |
Cylinder |
Any data store (SQL, NoSQL, files) |
| Queue/Broker |
#438DD5 (blue) |
Rounded rectangle with label |
Message queues, event buses |
| External System |
#999999 (grey) |
Rounded rectangle |
Third-party services, APIs |
| System Boundary |
none (transparent) |
Dashed rectangle |
Groups internal containers |
Reference: references/element-templates.md for exact draw.io XML templates.
Step 3: Plan Layout
Apply strict layered layout (top to bottom):
Layer 1 (y ≈ 20): Person elements (actors)
Layer 2 (y ≈ 250): System Boundary containing internal Containers
Layer 3 (y ≈ 700+): External Systems
Layout rules:
- Every element gets explicit x, y coordinates (no auto-layout)
- Minimum 200px horizontal gap between elements in the same layer
- Minimum 200px vertical gap between layers
- System boundary = dashed rectangle enclosing all internal containers with 40px padding
- Order elements left-to-right following the primary data flow direction
- Group related containers within sub-boundaries if the system has distinct subsystems
- Keep the diagram width under 1600px for readability
- Center elements horizontally within their layer
Minimizing line crossings:
- Place elements that communicate frequently adjacent to each other
- Route connections vertically when possible
- Avoid diagonal lines crossing other elements
- No arrows through unrelated containers: if A connects to C, the arrow must NOT pass through B. Fix by: (a) placing A and C adjacent, (b) using explicit exit/entry points, or (c) reorganizing the layout
- Arrow labels must not overlap container text: use
labelBackgroundColor=#ffffff on all edges, and use perpendicular offset (y in mxGeometry) to push labels away from containers
Step 4: Define Connections
For each connection, specify:
- Source and target element
- Label: action + protocol (e.g., "Reads/writes [SQL/TCP]", "Sends events [AMQP]")
- Style: solid line = synchronous call, dashed line = asynchronous (events, queues, webhooks)
- Direction: always source → target (follow data flow)
Connection rules:
- Every arrow must have a label (no unlabeled connections) — if a label overlaps, fix the layout or offset, never remove the label
- Always include
labelBackgroundColor=#ffffff in connection styles
- Use
[Protocol] suffix: [REST/JSON], [gRPC], [SQL], [AMQP], [WebSocket]
- Bidirectional flows: use two separate arrows with distinct labels
- Self-referencing: avoid (restructure the diagram instead)
Step 5: Generate .drawio XML
Use the XML structure from references/drawio-template.md as the base.
Build the XML following these rules:
- Start with the
<mxfile> wrapper and <mxGraphModel> with proper dimensions
- Add the root cells (id="0" and id="1")
- Add system boundary rectangles first (they are parents for contained elements)
- Add all elements with explicit geometry (x, y, width, height)
- Add all connections with source/target references
- Add the legend in the bottom-right corner
Element sizing:
- Person: 40 × 60px actor + 220 × 60px text label below
- Container: 240 × 120px
- Database (cylinder): 240 × 120px
- External System: 240 × 120px
- System Boundary: calculated to enclose children + 40px padding on each side
Step 6: Add Legend
Every diagram must include a legend. Place it in the bottom-right corner.
The legend must show:
- Person = dark blue stickman (#08427B)
- Container = blue rounded rect (#438DD5)
- Database = blue cylinder (#438DD5)
- External System = grey rounded rect (#999999)
- Solid arrow = synchronous flow
- Dashed arrow = asynchronous flow
Reference: references/legend-template.md for the exact XML.
Step 7: Save and Validate
Save to the path requested by the user, or default to ./c4_[system_name].drawio.
Validation checklist:
C4 Model Rules
Follow Simon Brown's C4 model constraints:
- Container diagram shows the high-level technology choices and how containers communicate
- Each container is a separately deployable/runnable unit (not a class or module)
- Do not mix C4 levels: this skill generates Container level only
- For Component-level detail inside a container, create a separate diagram
- Person elements represent roles, not individual people
- External systems are anything outside the system boundary that the team does not own
Anti-patterns
- NO auto-layout — always use explicit x, y coordinates for predictable results
- NO unlabeled arrows — every connection needs an action and protocol
- NO missing legend — legend is mandatory on every diagram
- NO cramped layout — maintain minimum gaps between elements
- NO mixed C4 levels — Container level only (no classes, no infrastructure)
- NO invisible text — ensure font color contrasts with background
- NO hardcoded dimensions — calculate system boundary size from children
- NO
mxgraph.c4.* shapes — they require the C4 shape library which is NOT loaded by default in draw.io. Use built-in shapes: shape=actor for persons, shape=cylinder3 for databases
- NO arrows crossing unrelated containers — rearrange layout so every arrow has a clear path between source and target
- NO labels without
labelBackgroundColor=#ffffff — naked labels become unreadable when crossing other elements
- NO stripping labels to fix overlap — if a label overlaps a container, fix the layout or offset, never remove information
1---2name: c4-diagram3description: Generate C4 Container diagrams (Simon Brown standard) as editable .drawio XML files. Use when the user asks for architecture diagrams, system diagrams, C4 diagrams, container diagrams, or wants to visualize system architecture. Also use proactively when explaining systems with 3+ components where a visual would clarify the architecture.4---56# C4 Container Diagram Generator78Generate C4 Container diagrams following Simon Brown's C4 model standard, exported as editable .drawio XML files that open directly in draw.io (desktop or web).910## When to Use1112**Explicit triggers:**13- User asks for a C4 diagram, container diagram, or architecture diagram14- User says "draw the architecture", "system diagram", "show me the components"15- User needs to visualize system architecture for documentation or a presentation16- User mentions draw.io, drawio, or wants an editable diagram1718**Proactive triggers:**19- Explaining a system with 3+ interacting components20- Discussing microservices, APIs, databases, and their relationships21- Reviewing or designing system architecture2223**Skip when:**24- User wants a simple flowchart (use Mermaid instead)25- User wants UI wireframes or mockups26- The system has fewer than 3 components2728## Process2930### Step 1: Gather Requirements3132Identify from the conversation or ask the user:33- What system are we diagramming?34- Who are the users/actors (Person)?35- What containers exist (apps, services, databases, queues, file storage)?36- What external systems does it interact with?37- What are the key data flows and protocols?3839If the user provides a spec, codebase description, or architecture overview, extract elements automatically and confirm before generating.4041### Step 2: Classify Elements4243Map every element to a C4 category:4445| Category | Color | Shape | Description |46|----------|-------|-------|-------------|47| Person | `#08427B` (dark blue) | `shape=actor` + text label | Users, actors, roles |48| Container | `#438DD5` (blue) | Rounded rectangle | Applications, services, APIs |49| Database | `#438DD5` (blue) | Cylinder | Any data store (SQL, NoSQL, files) |50| Queue/Broker | `#438DD5` (blue) | Rounded rectangle with label | Message queues, event buses |51| External System | `#999999` (grey) | Rounded rectangle | Third-party services, APIs |52| System Boundary | none (transparent) | Dashed rectangle | Groups internal containers |5354Reference: `references/element-templates.md` for exact draw.io XML templates.5556### Step 3: Plan Layout5758Apply **strict layered layout** (top to bottom):5960```61Layer 1 (y ≈ 20): Person elements (actors)62Layer 2 (y ≈ 250): System Boundary containing internal Containers63Layer 3 (y ≈ 700+): External Systems64```6566**Layout rules:**67- Every element gets explicit x, y coordinates (no auto-layout)68- Minimum **200px horizontal gap** between elements in the same layer69- Minimum **200px vertical gap** between layers70- System boundary = dashed rectangle enclosing all internal containers with 40px padding71- Order elements left-to-right following the primary data flow direction72- Group related containers within sub-boundaries if the system has distinct subsystems73- Keep the diagram width under 1600px for readability74- Center elements horizontally within their layer7576**Minimizing line crossings:**77- Place elements that communicate frequently adjacent to each other78- Route connections vertically when possible79- Avoid diagonal lines crossing other elements80- **No arrows through unrelated containers**: if A connects to C, the arrow must NOT pass through B. Fix by: (a) placing A and C adjacent, (b) using explicit exit/entry points, or (c) reorganizing the layout81- **Arrow labels must not overlap container text**: use `labelBackgroundColor=#ffffff` on all edges, and use perpendicular offset (`y` in mxGeometry) to push labels away from containers8283### Step 4: Define Connections8485For each connection, specify:86- Source and target element87- Label: action + protocol (e.g., "Reads/writes [SQL/TCP]", "Sends events [AMQP]")88- Style: **solid line** = synchronous call, **dashed line** = asynchronous (events, queues, webhooks)89- Direction: always source → target (follow data flow)9091**Connection rules:**92- Every arrow must have a label (no unlabeled connections) — if a label overlaps, fix the layout or offset, never remove the label93- Always include `labelBackgroundColor=#ffffff` in connection styles94- Use `[Protocol]` suffix: `[REST/JSON]`, `[gRPC]`, `[SQL]`, `[AMQP]`, `[WebSocket]`95- Bidirectional flows: use two separate arrows with distinct labels96- Self-referencing: avoid (restructure the diagram instead)9798### Step 5: Generate .drawio XML99100Use the XML structure from `references/drawio-template.md` as the base.101102Build the XML following these rules:1031. Start with the `<mxfile>` wrapper and `<mxGraphModel>` with proper dimensions1042. Add the root cells (id="0" and id="1")1053. Add system boundary rectangles first (they are parents for contained elements)1064. Add all elements with explicit geometry (x, y, width, height)1075. Add all connections with source/target references1086. Add the legend in the bottom-right corner109110**Element sizing:**111- Person: 40 × 60px actor + 220 × 60px text label below112- Container: 240 × 120px113- Database (cylinder): 240 × 120px114- External System: 240 × 120px115- System Boundary: calculated to enclose children + 40px padding on each side116117### Step 6: Add Legend118119**Every diagram must include a legend.** Place it in the bottom-right corner.120121The legend must show:122- Person = dark blue stickman (#08427B)123- Container = blue rounded rect (#438DD5)124- Database = blue cylinder (#438DD5)125- External System = grey rounded rect (#999999)126- Solid arrow = synchronous flow127- Dashed arrow = asynchronous flow128129Reference: `references/legend-template.md` for the exact XML.130131### Step 7: Save and Validate132133Save to the path requested by the user, or default to `./c4_[system_name].drawio`.134135**Validation checklist:**136- [ ] All elements have explicit x, y coordinates137- [ ] Layers are top-to-bottom: Person → System Boundary → External138- [ ] System boundary encloses all internal containers139- [ ] Legend is present in bottom-right140- [ ] No overlapping elements (check coordinates + dimensions)141- [ ] Minimal line crossings142- [ ] Every connection has a label with protocol143- [ ] Solid lines = synchronous, dashed lines = asynchronous144- [ ] Font colors are white (#ffffff) on colored backgrounds145- [ ] File opens correctly in draw.io (valid XML structure)146147## C4 Model Rules148149Follow Simon Brown's C4 model constraints:150- **Container diagram** shows the high-level technology choices and how containers communicate151- Each container is a separately deployable/runnable unit (not a class or module)152- Do not mix C4 levels: this skill generates Container level only153- For Component-level detail inside a container, create a separate diagram154- Person elements represent roles, not individual people155- External systems are anything outside the system boundary that the team does not own156157## Anti-patterns158159- **NO auto-layout** — always use explicit x, y coordinates for predictable results160- **NO unlabeled arrows** — every connection needs an action and protocol161- **NO missing legend** — legend is mandatory on every diagram162- **NO cramped layout** — maintain minimum gaps between elements163- **NO mixed C4 levels** — Container level only (no classes, no infrastructure)164- **NO invisible text** — ensure font color contrasts with background165- **NO hardcoded dimensions** — calculate system boundary size from children166- **NO `mxgraph.c4.*` shapes** — they require the C4 shape library which is NOT loaded by default in draw.io. Use built-in shapes: `shape=actor` for persons, `shape=cylinder3` for databases167- **NO arrows crossing unrelated containers** — rearrange layout so every arrow has a clear path between source and target168- **NO labels without `labelBackgroundColor=#ffffff`** — naked labels become unreadable when crossing other elements169- **NO stripping labels to fix overlap** — if a label overlaps a container, fix the layout or offset, never remove information