# Create Diagram - Workflow Instructions
```xml
The workflow execution engine is governed by: {project_root}/.bmad/core/tasks/workflow.xml
You MUST have already loaded and processed: {installed_path}/workflow.yaml
This workflow creates system architecture diagrams, ERDs, UML diagrams, or general technical diagrams in Excalidraw format.
Review user's request and extract: diagram type, components/entities, relationships, notation preferences
Skip to Step 5
Only ask about missing info in Steps 1-2
Ask: "What type of technical diagram do you need?"
Present options:
1. System Architecture
2. Entity-Relationship Diagram (ERD)
3. UML Class Diagram
4. UML Sequence Diagram
5. UML Use Case Diagram
6. Network Diagram
7. Other
WAIT for selection
Ask: "Describe the components/entities and their relationships"
Ask: "What notation standard? (Standard/Simplified/Strict UML-ERD)"
WAIT for user input
Summarize what will be included and confirm with user
Check if theme.json exists at output location
Ask to use it, load if yes, else proceed to Step 4
Proceed to Step 4
Ask: "Choose a color scheme for your diagram:"
Present numbered options:
1. Professional
- Component: #e3f2fd (light blue)
- Database: #e8f5e9 (light green)
- Service: #fff3e0 (light orange)
- Border: #1976d2 (blue)
2. Colorful
- Component: #e1bee7 (light purple)
- Database: #c5e1a5 (light lime)
- Service: #ffccbc (light coral)
- Border: #7b1fa2 (purple)
3. Minimal
- Component: #f5f5f5 (light gray)
- Database: #eeeeee (gray)
- Service: #e0e0e0 (medium gray)
- Border: #616161 (dark gray)
4. Custom - Define your own colors
WAIT for selection
Create theme.json based on selection
Show preview and confirm
List all components/entities
Map all relationships
Show planned layout
Ask: "Structure looks correct? (yes/no)"
Adjust and repeat
Load {{templates}} and extract `diagram` section
Load {{library}}
Load theme.json and merge with template
Load {{helpers}} for guidelines
Follow {{helpers}} for proper element creation
For Each Component:
- Generate unique IDs (component-id, text-id, group-id)
- Create shape with groupIds
- Calculate text width
- Create text with containerId and matching groupIds
- Add boundElements
For Each Connection:
- Determine arrow type (straight/elbow)
- Create with startBinding and endBinding
- Update boundElements on both components
Build Order by Type:
- Architecture: Services → Databases → Connections → Labels
- ERD: Entities → Attributes → Relationships → Cardinality
- UML Class: Classes → Attributes → Methods → Relationships
- UML Sequence: Actors → Lifelines → Messages → Returns
- UML Use Case: Actors → Use Cases → Relationships
Alignment:
- Snap to 20px grid
- Space: 40px between components, 60px between sections
Strip unused elements and elements with isDeleted: true
Save to {{default_output_file}}
NEVER delete the file if validation fails - always fix syntax errors
Run: node -e "JSON.parse(require('fs').readFileSync('{{default_output_file}}', 'utf8')); console.log('✓ Valid JSON')"
Read the error message carefully - it shows the syntax error and position
Open the file and navigate to the error location
Fix the syntax error (add missing comma, bracket, or quote as indicated)
Save the file
Re-run validation with the same command
Repeat until validation passes
Once validation passes, confirm: "Diagram created at {{default_output_file}}. Open to view?"
Validate against {{validation}} using {.bmad}/core/tasks/validate-workflow.xml
```