mermaid-studio
npx skills add https://github.com/tech-leads-club/agent-skills --skill mermaid-studio
Agent 安装分布
Skill 文档
Mermaid Studio
Expert-level Mermaid diagram creation, validation, and multi-format rendering. Creates diagrams from descriptions or code analysis, validates syntax, and renders to SVG, PNG, or ASCII with professional theming.
Modes of Operation
This skill operates in three modes based on user intent:
| Mode | Trigger | What happens |
|---|---|---|
| Create | “draw a diagram of…”, “visualize my…” | Generates .mmd code only |
| Render | “render this mermaid”, “convert to SVG/PNG/ASCII” | Renders existing .mmd |
| Full | “create and render…”, ambiguous requests | Create â Validate â Render |
Default to Full mode when intent is unclear.
Step 1: Understand the Request
Before writing any Mermaid code, determine:
- What to diagram â system, flow, schema, architecture, code structure?
- Which diagram type â use the Decision Matrix below
- Output format â code only, SVG, PNG, or ASCII?
- Theme preference â ask only if rendering; default to
defaulttheme
Diagram Type Decision Matrix
| User describes… | Diagram Type | Syntax keyword |
|---|---|---|
| Process, algorithm, decision tree, workflow | Flowchart | flowchart TD/LR |
| API calls, message passing, request/response | Sequence | sequenceDiagram |
| Database schema, table relationships | ERD | erDiagram |
| OOP classes, domain model, interfaces | Class | classDiagram |
| State machine, lifecycle, transitions | State | stateDiagram-v2 |
| High-level system overview (C4 Level 1) | C4 Context | C4Context |
| Applications, databases, services (C4 Level 2) | C4 Container | C4Container |
| Internal components (C4 Level 3) | C4 Component | C4Component |
| Request flows with numbered steps | C4 Dynamic | C4Dynamic |
| Infrastructure, cloud deployment | C4 Deployment | C4Deployment |
| Cloud services with icons (AWS/GCP/Azure) | Architecture | architecture-beta |
| Project timeline, scheduling | Gantt | gantt |
| Proportional data, percentages | Pie | pie |
| Brainstorming, hierarchical ideas | Mindmap | mindmap |
| Historical events, chronology | Timeline | timeline |
| Branching strategy, git history | Git Graph | gitGraph |
| Flow quantities, resource distribution | Sankey | sankey-beta |
| X/Y data visualization | XY Chart | xychart-beta |
| Priority matrix, strategic positioning | Quadrant | quadrantChart |
| Layout control, grid positioning | Block | block-beta |
| Network packets, protocol headers | Packet | packet-beta |
| Task boards, kanban workflow | Kanban | kanban |
| User experience, satisfaction scoring | User Journey | journey |
| System requirements traceability | Requirement | requirementDiagram |
If the user’s description doesn’t clearly map to one type, suggest 2-3 options with a brief rationale for each, then let them choose.
When to Load References
Load reference files ONLY when needed for the specific diagram type:
- C4 diagrams â Read
references/c4-architecture.mdBEFORE writing code - AWS/Cloud architecture â Read
references/aws-architecture.mdBEFORE writing code - Code-to-diagram â Read
references/code-to-diagram.mdBEFORE analyzing - Theming/styling â Read
references/themes.mdwhen user requests custom themes - Syntax errors â Read
references/troubleshooting.mdwhen validation fails - Any diagram type details â Read
references/diagram-types.mdfor comprehensive syntax
Step 2: Create the Diagram
2.1 â Write Mermaid Code
Follow these principles in order of priority:
- Correctness first â valid syntax that renders without errors
- Clarity â meaningful labels, logical flow direction, clear relationships
- Simplicity â under 20 nodes per diagram; split complex systems into multiple
- Consistency â uniform naming (camelCase for IDs, descriptive labels in brackets)
2.2 â Structure Rules
%% Always include a descriptive comment at the top
%% Diagram: [Purpose] | Author: [auto] | Date: [auto]
[diagramType]
[content]
Naming conventions:
- Node IDs: camelCase, descriptive (
orderService, nots1) - Labels: natural language in brackets (
[Order Service]) - Relationships: action verbs (
"Sends order to","Reads from")
Layout best practices:
TD(top-down) for hierarchical flows and processesLR(left-right) for timelines and sequential processesRLfor right-to-left reading contexts- Use
subgraphto group related nodes; name subgraphs meaningfully - Add
directioninside subgraphs when needed for different flow
2.3 â Quick Reference Examples
Flowchart:
flowchart TD
Start([Start]) --> Input[/User Input/]
Input --> Validate{Valid?}
Validate -->|Yes| Process[Process Data]
Validate -->|No| Error[Show Error]
Error --> Input
Process --> Save[(Save to DB)]
Save --> End([End])
Sequence:
sequenceDiagram
participant Client
participant API
participant DB
Client->>+API: POST /orders
API->>+DB: INSERT order
DB-->>-API: order_id
API-->>-Client: 201 Created
ERD:
erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : includes
USER {
uuid id PK
string email UK
string name
}
C4 Context:
C4Context
title System Context - E-Commerce Platform
Person(customer, "Customer", "Places orders online")
System(platform, "E-Commerce Platform", "Handles orders and payments")
System_Ext(payment, "Payment Gateway", "Processes transactions")
System_Ext(email, "Email Service", "Sends notifications")
Rel(customer, platform, "Uses", "HTTPS")
Rel(platform, payment, "Processes payments", "API")
Rel(platform, email, "Sends emails", "SMTP")
Architecture (AWS):
architecture-beta
group vpc(cloud)[VPC]
service api(server)[API Gateway] in vpc
service lambda(server)[Lambda] in vpc
service db(database)[DynamoDB] in vpc
service s3(disk)[S3 Bucket]
api:R --> L:lambda
lambda:R --> L:db
lambda:B --> T:s3
For comprehensive syntax of ALL diagram types, read references/diagram-types.md.
Step 3: Validate
Before rendering, ALWAYS validate the Mermaid syntax:
node $SKILL_DIR/scripts/validate.mjs <file.mmd>
If validation fails:
- Read the error message carefully
- Consult
references/troubleshooting.mdfor common fixes - Fix the syntax and re-validate
- Maximum 3 fix attempts before asking the user for clarification
Step 4: Render
4.1 â Setup (First Run Only)
bash $SKILL_DIR/scripts/setup.sh
This auto-installs both rendering engines. Run once per environment.
4.2 â Single Diagram Rendering
SVG (default â best quality):
node $SKILL_DIR/scripts/render.mjs \
--input diagram.mmd \
--output diagram.svg \
--format svg \
--theme default
PNG (for documents and presentations):
node $SKILL_DIR/scripts/render.mjs \
--input diagram.mmd \
--output diagram.png \
--format png \
--theme default \
--width 1200
ASCII (for terminals and READMEs):
node $SKILL_DIR/scripts/render-ascii.mjs \
--input diagram.mmd
4.3 â Batch Rendering
For multiple diagrams at once:
node $SKILL_DIR/scripts/batch.mjs \
--input-dir ./diagrams \
--output-dir ./rendered \
--format svg \
--theme default \
--workers 4
4.4 â Available Themes
beautiful-mermaid themes (15):
tokyo-night | tokyo-night-storm | tokyo-night-light | dracula | nord | nord-light | catppuccin-mocha | catppuccin-latte | github-dark | github-light | solarized-dark | solarized-light | one-dark | zinc-dark | zinc-light
mermaid-cli native themes (5):
default | forest | dark | neutral | base
Custom theme (via mermaid-cli):
node $SKILL_DIR/scripts/render.mjs \
--input diagram.mmd \
--output diagram.svg \
--format svg \
--theme base \
--config '{"theme":"base","themeVariables":{"primaryColor":"#ff6b6b","secondaryColor":"#4ecdc4"}}'
For the full theme catalog with previews, read references/themes.md.
4.5 â Render Engine Selection
The render script uses dual-engine fallback:
- Primary: @mermaid-js/mermaid-cli â most stable, supports ALL diagram types, PNG/SVG/PDF output, custom configs
- Fallback: beautiful-mermaid â better visual themes, SVG + ASCII output, supports flowchart/sequence/state/class/ER
If the primary engine fails, the script automatically tries the fallback. ASCII rendering always uses beautiful-mermaid exclusively.
Step 5: Code-to-Diagram (When Requested)
When the user asks to visualize existing code or architecture:
- Read
references/code-to-diagram.mdfor the analysis methodology - Analyze the codebase to identify the right diagram type:
- Module dependencies â Flowchart or Class diagram
- API routes and handlers â Sequence diagram
- Database models/schemas â ERD
- Service architecture â C4 Container or Architecture diagram
- State machines in code â State diagram
- Generate the .mmd file
- Validate and render as usual
Common Patterns
Error Handling Flow
flowchart TD
Request[Incoming Request] --> Validate{Valid?}
Validate -->|No| ValidationError[400 Bad Request]
Validate -->|Yes| Process[Process Request]
Process --> DBResult{DB Success?}
DBResult -->|No| DBError[500 Internal Error]
DBResult -->|Yes| Success[200 OK]
ValidationError & DBError --> Logger[Log Error]
Microservice Communication
sequenceDiagram
participant GW as API Gateway
participant Auth as Auth Service
participant Order as Order Service
participant Queue as Message Queue
participant Notif as Notification Service
GW->>Auth: Verify token
Auth-->>GW: Token valid
GW->>Order: Create order
Order->>Queue: Publish OrderCreated
Queue-->>Notif: Consume event
Notif-->>Notif: Send email
Authentication State Machine
stateDiagram-v2
[*] --> Anonymous
Anonymous --> Authenticating : Login attempt
Authenticating --> Authenticated : Credentials valid
Authenticating --> Failed : Credentials invalid
Failed --> Authenticating : Retry
Failed --> Locked : Max attempts reached
Authenticated --> Anonymous : Logout
Authenticated --> TokenRefresh : Token expiring
TokenRefresh --> Authenticated : Refresh success
TokenRefresh --> Anonymous : Refresh failed
Locked --> Anonymous : Timeout elapsed
Troubleshooting Quick Reference
| Symptom | Likely Cause | Fix |
|---|---|---|
| Diagram won’t render | Syntax error | Run validate.mjs, check brackets/quotes |
| Labels cut off | Text too long | Shorten labels or use line breaks <br/> |
| Layout looks wrong | Wrong direction | Try different TD/LR/BT/RL |
| Nodes overlap | Too many nodes | Split into subgraphs or multiple diagrams |
mmdc not found |
Not installed | Run setup.sh |
| Theme not applied | Wrong engine | beautiful-mermaid themes only work with that engine |
For comprehensive troubleshooting, read references/troubleshooting.md.
Output Conventions
- Save .mmd source files alongside rendered outputs
- Naming:
{purpose}-{type}.mmd(e.g.,auth-flow-sequence.mmd) - For batch: maintain input filename, change extension
- Always provide both the .mmd source and rendered file to the user