Excalidraw Diagram Generator
Generate architecture diagrams as
files directly from codebase analysis.
Quick Start
User just asks:
"Generate an architecture diagram for this project"
"Create an excalidraw diagram of the system"
"Visualize this codebase as an excalidraw file"
Claude Code will:
- Analyze the codebase (any language/framework)
- Identify components, services, databases, APIs
- Map relationships and data flows
- Generate valid JSON with dynamic IDs and labels
No prerequisites: Works without existing diagrams, Terraform, or specific file types.
Critical Rules
1. NEVER Use Diamond Shapes
Diamond arrow connections are broken in raw Excalidraw JSON. Use styled rectangles instead:
| Semantic Meaning | Rectangle Style |
|---|
| Orchestrator/Hub | Coral (/) + strokeWidth: 3 |
| Decision Point | Orange (/) + dashed stroke |
2. Labels Require TWO Elements
The
property does NOT work in raw JSON. Every labeled shape needs:
json
// 1. Shape with boundElements reference
{
"id": "my-box",
"type": "rectangle",
"boundElements": [{ "type": "text", "id": "my-box-text" }]
}
// 2. Separate text element with containerId
{
"id": "my-box-text",
"type": "text",
"containerId": "my-box",
"text": "My Label"
}
3. Elbow Arrows Need Three Properties
For 90-degree corners (not curved):
json
{
"type": "arrow",
"roughness": 0, // Clean lines
"roundness": null, // Sharp corners
"elbowed": true // 90-degree mode
}
4. Arrow Edge Calculations
Arrows must start/end at shape edges, not centers:
| Edge | Formula |
|---|
| Top | |
| Bottom | (x + width/2, y + height)
|
| Left | |
| Right | (x + width, y + height/2)
|
Detailed arrow routing: See
Element Types
| Type | Use For |
|---|
| Services, databases, containers, orchestrators |
| Users, external systems, start/end points |
| Labels inside shapes, titles, annotations |
| Data flow, connections, dependencies |
| Grouping boundaries, separators |
Full JSON format: See
references/json-format.md
Workflow
Step 1: Analyze Codebase
Discover components by looking for:
| Codebase Type | What to Look For |
|---|
| Monorepo | , workspace configs |
| Microservices | , k8s manifests |
| IaC | Terraform/Pulumi resource definitions |
| Backend API | Route definitions, controllers, DB models |
| Frontend | Component hierarchy, API calls |
Use tools:
- → , ,
- → , ,
- → README, config files, entry points
Step 2: Plan Layout
Vertical flow (most common):
Row 1: Users/Entry points (y: 100)
Row 2: Frontend/Gateway (y: 230)
Row 3: Orchestration (y: 380)
Row 4: Services (y: 530)
Row 5: Data layer (y: 680)
Columns: x = 100, 300, 500, 700, 900
Element size: 160-200px x 80-90px
Step 3: Generate Elements
For each component:
- Create shape with unique
- Add referencing text
- Create text with
- Choose color based on type
Step 4: Add Connections
For each relationship:
- Calculate source edge point
- Plan elbow route (avoid overlaps)
- Create arrow with array
- Match stroke color to destination type
Step 5: Add Grouping (Optional)
For logical groupings:
- Large transparent rectangle with
- Standalone text label at top-left
Step 6: Validate and Write
Run validation before writing. Save to
or user-specified path.
Validation checklist: See
Quick Arrow Reference
Straight down:
json
{ "points": [[0, 0], [0, 110]], "x": 590, "y": 290 }
L-shape (left then down):
json
{ "points": [[0, 0], [-325, 0], [-325, 125]], "x": 525, "y": 420 }
U-turn (callback):
json
{ "points": [[0, 0], [50, 0], [50, -125], [20, -125]], "x": 710, "y": 440 }
Arrow width/height = bounding box of points:
points [[0,0], [-440,0], [-440,70]] → width=440, height=70
Multiple arrows from same edge - stagger positions:
5 arrows: 20%, 35%, 50%, 65%, 80% across edge width
Default Color Palette
| Component | Background | Stroke |
|---|
| Frontend | | |
| Backend/API | | |
| Database | | |
| Storage | | |
| AI/ML | | |
| External APIs | | |
| Orchestration | | |
| Message Queue | | |
| Cache | | |
| Users | | |
Cloud-specific palettes: See
Quick Validation Checklist
Before writing file:
Full validation algorithm: See
Common Issues
| Issue | Fix |
|---|
| Labels don't appear | Use TWO elements (shape + text), not property |
| Arrows curved | Add , , |
| Arrows floating | Calculate x,y from shape edge, not center |
| Arrows overlapping | Stagger start positions across edge |
Reference Files
| File | Contents |
|---|
references/json-format.md
| Element types, required properties, text bindings |
| Routing algorithm, patterns, bindings, staggering |
| Default, AWS, Azure, GCP, K8s palettes |
| Complete JSON examples, layout patterns |
| Checklists, validation algorithm, bug fixes |
Output
- Location: or user-specified
- Filename: Descriptive, e.g.,
system-architecture.excalidraw
- Testing: Open in https://excalidraw.com or VS Code extension