Mermaid Diagram Skill
This skill helps you create, validate, and render Mermaid diagrams from natural language descriptions, code analysis, or by editing existing diagrams.
Core Workflow
Follow these steps for every diagram creation/modification:
1. Understand the Request
- Identify the diagram type needed (flowchart, sequence, class, etc.)
- Extract key elements: entities, relationships, flow, hierarchy
- Determine if creating new, editing existing, or generating from code
2. Generate Mermaid Code
- Create syntactically correct Mermaid diagram code
- Use appropriate diagram type syntax
- Apply consistent naming and styling
- Refer to
examples/ directory for type-specific syntax (load on-demand)
3. Save to File
- Write code to
.mmd file
- Generate meaningful filename based on diagram purpose (e.g.,
user-authentication-flow.mmd, database-schema.mmd)
- Use kebab-case for filenames
4. Validate with CLI
- ALWAYS validate using:
mmdc -i <filename>.mmd
- Check for syntax errors and warnings
- If validation fails, proceed to step 5
5. Auto-Correct Errors
- Analyze error messages from
mmdc
- Common issues:
- Invalid syntax or keywords
- Missing quotes around labels with spaces
- Incorrect arrow syntax
- Malformed node definitions
- Automatically fix the code
- Re-save and re-validate
- Repeat until validation succeeds
6. Render on Request
- Default format: SVG
- Command:
mmdc -i <filename>.mmd -o <filename>.svg
- Alternative formats: PNG (
-o <filename>.png), PDF (-o <filename>.pdf)
- Only render when user explicitly requests a preview/image
Supported Diagram Types
Load examples from examples/ directory as needed:
Basic Diagrams:
- Flowchart (
examples/flowchart.md)
- Sequence Diagram (
examples/sequence.md)
- Class Diagram (
examples/class.md)
- State Diagram (
examples/state.md)
- Entity Relationship (
examples/er.md)
Planning & Management:
- Gantt Chart (
examples/gantt.md)
- User Journey (
examples/journey.md)
- Timeline (
examples/timeline.md)
- Kanban (
examples/kanban.md)
Data Visualization:
- Pie Chart (
examples/pie.md)
- XY Chart (
examples/xy-chart.md)
- Quadrant Chart (
examples/quadrant.md)
- Sankey (
examples/sankey.md)
- Radar (
examples/radar.md)
- Treemap (
examples/treemap.md)
Technical Diagrams:
- Git Graph (
examples/git.md)
- C4 Diagram (
examples/c4.md)
- Requirement Diagram (
examples/requirement.md)
- Architecture (
examples/architecture.md)
- Block Diagram (
examples/block.md)
- Packet (
examples/packet.md)
Organizational:
- Mindmap (
examples/mindmap.md)
- ZenUML (
examples/zenuml.md)
Code Analysis → Diagram
When analyzing code to create diagrams:
Class Diagrams:
- Extract classes, methods, properties, inheritance, interfaces
- Show relationships: inheritance, composition, aggregation
Sequence Diagrams:
- Track function calls, async operations, API interactions
- Show actors, lifelines, activation boxes
Flowcharts:
- Map control flow, conditionals, loops
- Show function entry/exit points
State Diagrams:
- Identify states from enums, state machines, status fields
- Map transitions and events
Templates
Common patterns available in templates/common-patterns.md (load on-demand):
- Standard flowchart structures
- API sequence patterns
- Database ER patterns
- Microservice architecture layouts
- State machine templates
Best Practices
Styling:
- Use meaningful node IDs
- Add clear, concise labels
- Apply subgraphs for grouping related elements
- Use classDefs for visual consistency
Readability:
- Keep diagrams focused (split large diagrams into smaller ones)
- Use top-to-bottom or left-to-right orientation consistently
- Add comments in code for complex sections
Validation:
- NEVER skip validation step
- Always fix errors before presenting to user
- Test rendered output when in doubt
Error Handling
If mmdc validation fails:
- Read error message carefully
- Identify line number and issue
- Apply fix (common fixes in examples)
- Re-validate
- Inform user only if repeated attempts fail
Output Format
Present to user:
Created: <filename>.mmd
<Show the mermaid code in a code block>
✓ Validated successfully with mermaid-cli
If rendered:
Created: <filename>.mmd
Rendered: <filename>.svg
[Show file paths]
Notes
- Assume
mmdc (mermaid-cli) is installed and available
- Default output format: SVG
- Always validate before presenting
- Fix errors autonomously
- Only load example files when needed for specific diagram type
1---2name: mermaid3description: Guide for creating mermaid diagrams. This skill should be used when users want to create a mermaid diagram (or update an existing diagram).4---56# Mermaid Diagram Skill78This skill helps you create, validate, and render Mermaid diagrams from natural language descriptions, code analysis, or by editing existing diagrams.910## Core Workflow1112Follow these steps for every diagram creation/modification:1314### 1. Understand the Request15- Identify the diagram type needed (flowchart, sequence, class, etc.)16- Extract key elements: entities, relationships, flow, hierarchy17- Determine if creating new, editing existing, or generating from code1819### 2. Generate Mermaid Code20- Create syntactically correct Mermaid diagram code21- Use appropriate diagram type syntax22- Apply consistent naming and styling23- Refer to `examples/` directory for type-specific syntax (load on-demand)2425### 3. Save to File26- Write code to `.mmd` file27- Generate meaningful filename based on diagram purpose (e.g., `user-authentication-flow.mmd`, `database-schema.mmd`)28- Use kebab-case for filenames2930### 4. Validate with CLI31- **ALWAYS** validate using: `mmdc -i <filename>.mmd`32- Check for syntax errors and warnings33- If validation fails, proceed to step 53435### 5. Auto-Correct Errors36- Analyze error messages from `mmdc`37- Common issues:38 - Invalid syntax or keywords39 - Missing quotes around labels with spaces40 - Incorrect arrow syntax41 - Malformed node definitions42- Automatically fix the code43- Re-save and re-validate44- Repeat until validation succeeds4546### 6. Render on Request47- Default format: **SVG**48- Command: `mmdc -i <filename>.mmd -o <filename>.svg`49- Alternative formats: PNG (`-o <filename>.png`), PDF (`-o <filename>.pdf`)50- Only render when user explicitly requests a preview/image5152## Supported Diagram Types5354Load examples from `examples/` directory as needed:5556**Basic Diagrams:**57- Flowchart (`examples/flowchart.md`)58- Sequence Diagram (`examples/sequence.md`)59- Class Diagram (`examples/class.md`)60- State Diagram (`examples/state.md`)61- Entity Relationship (`examples/er.md`)6263**Planning & Management:**64- Gantt Chart (`examples/gantt.md`)65- User Journey (`examples/journey.md`)66- Timeline (`examples/timeline.md`)67- Kanban (`examples/kanban.md`)6869**Data Visualization:**70- Pie Chart (`examples/pie.md`)71- XY Chart (`examples/xy-chart.md`)72- Quadrant Chart (`examples/quadrant.md`)73- Sankey (`examples/sankey.md`)74- Radar (`examples/radar.md`)75- Treemap (`examples/treemap.md`)7677**Technical Diagrams:**78- Git Graph (`examples/git.md`)79- C4 Diagram (`examples/c4.md`)80- Requirement Diagram (`examples/requirement.md`)81- Architecture (`examples/architecture.md`)82- Block Diagram (`examples/block.md`)83- Packet (`examples/packet.md`)8485**Organizational:**86- Mindmap (`examples/mindmap.md`)87- ZenUML (`examples/zenuml.md`)8889## Code Analysis → Diagram9091When analyzing code to create diagrams:9293**Class Diagrams:**94- Extract classes, methods, properties, inheritance, interfaces95- Show relationships: inheritance, composition, aggregation9697**Sequence Diagrams:**98- Track function calls, async operations, API interactions99- Show actors, lifelines, activation boxes100101**Flowcharts:**102- Map control flow, conditionals, loops103- Show function entry/exit points104105**State Diagrams:**106- Identify states from enums, state machines, status fields107- Map transitions and events108109## Templates110111Common patterns available in `templates/common-patterns.md` (load on-demand):112- Standard flowchart structures113- API sequence patterns114- Database ER patterns115- Microservice architecture layouts116- State machine templates117118## Best Practices119120**Styling:**121- Use meaningful node IDs122- Add clear, concise labels123- Apply subgraphs for grouping related elements124- Use classDefs for visual consistency125126**Readability:**127- Keep diagrams focused (split large diagrams into smaller ones)128- Use top-to-bottom or left-to-right orientation consistently129- Add comments in code for complex sections130131**Validation:**132- NEVER skip validation step133- Always fix errors before presenting to user134- Test rendered output when in doubt135136## Error Handling137138If `mmdc` validation fails:1391. Read error message carefully1402. Identify line number and issue1413. Apply fix (common fixes in examples)1424. Re-validate1435. Inform user only if repeated attempts fail144145## Output Format146147Present to user:148```149Created: <filename>.mmd150151<Show the mermaid code in a code block>152153✓ Validated successfully with mermaid-cli154```155156If rendered:157```158Created: <filename>.mmd159Rendered: <filename>.svg160161[Show file paths]162```163164## Notes165166- Assume `mmdc` (mermaid-cli) is installed and available167- Default output format: SVG168- Always validate before presenting169- Fix errors autonomously170- Only load example files when needed for specific diagram type