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.
Every diagram MUST follow these principles. They are not optional — they define the difference between a mediocre diagram and a gold-standard one.
NEVER create a diagram without an %%{init} directive or frontmatter config. The default Mermaid theme produces harsh black lines and generic colors. Always apply a curated palette.
For general diagrams (flowchart, sequence, state, class, ERD):
%%{init: {'theme': 'base', 'themeVariables': {
'primaryColor': '#4f46e5', 'primaryTextColor': '#ffffff',
'primaryBorderColor': '#3730a3', 'lineColor': '#94a3b8',
'secondaryColor': '#10b981', 'tertiaryColor': '#f59e0b',
'background': '#ffffff', 'mainBkg': '#f8fafc',
'nodeBorder': '#cbd5e1', 'clusterBkg': '#f1f5f9',
'clusterBorder': '#e2e8f0', 'titleColor': '#1e293b',
'edgeLabelBackground': '#ffffff', 'textColor': '#334155'
}}}%%
⚠️ Font Warning: Do NOT set fontFamily in theme variables. The Mermaid default font (trebuchet ms, verdana, arial, sans-serif) works everywhere. Setting system-ui, Segoe UI, or -apple-system will render as Times New Roman in headless Chromium (used by mmdc).
For C4 diagrams — see the dedicated C4 styling section below.
For architecture-beta diagrams — see the dedicated AWS/Architecture section below.
The single biggest visual improvement is using lineColor: '#94a3b8' (slate-400) instead of the default black. This creates a modern, breathable diagram. For dark themes, use lineColor: '#64748b' (slate-500).
subgraph or boundaries to create whitespace and visual groupingA ~~~ B) to add spacing when the layout is crampedorderService, not s1 or os)[Order Service])"Sends order via gRPC")"Handles order lifecycle")Use max 3-4 colors per diagram. Map colors to meaning:
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.
Before writing any Mermaid code, determine:
base theme with curated palette| 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.
Load reference files ONLY when needed for the specific diagram type:
references/c4-architecture.md BEFORE writing codereferences/aws-architecture.md BEFORE writing codereferences/code-to-diagram.md BEFORE analyzingreferences/themes.md when user requests custom themesreferences/troubleshooting.md when validation failsreferences/diagram-types.md for comprehensive syntaxFollow these principles in order of priority:
%% Diagram: [Purpose] | Author: [auto] | Date: [auto]
%%{init: {'theme': 'base', 'themeVariables': { ... }}}%%
[diagramType]
[content]
CRITICAL: The %%{init} directive MUST go on the very first non-comment line, BEFORE the diagram type declaration. Alternatively, use YAML frontmatter at the absolute start of the file.
Naming conventions:
orderService, not s1)[Order Service])"Sends order to", "Reads from")Layout best practices:
TD (top-down) for hierarchical flows and processesLR (left-right) for timelines, pipelines, and sequential processesRL for right-to-left reading contextssubgraph to group related nodes; name subgraphs meaningfullydirection inside subgraphs when needed for different flowFlowchart (with professional styling):
%%{init: {'theme': 'base', 'themeVariables': {
'primaryColor': '#4f46e5', 'primaryTextColor': '#fff',
'primaryBorderColor': '#3730a3', 'lineColor': '#94a3b8',
'secondaryColor': '#10b981', 'tertiaryColor': '#f59e0b',
'background': '#ffffff', 'mainBkg': '#f8fafc',
'nodeBorder': '#cbd5e1', 'clusterBkg': '#f1f5f9',
'clusterBorder': '#e2e8f0', 'titleColor': '#1e293b',
'edgeLabelBackground': '#ffffff'
}}}%%
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])
For sequence diagram and ERD styling examples, read references/themes.md.
C4 Context (with MANDATORY elegant styling):
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")
UpdateRelStyle(customer, platform, $textColor="#475569", $lineColor="#94a3b8")
UpdateRelStyle(platform, payment, $textColor="#475569", $lineColor="#94a3b8")
UpdateRelStyle(platform, email, $textColor="#475569", $lineColor="#94a3b8")
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")
Architecture (AWS with Iconify icons):
architecture-beta
group vpc(logos:aws-vpc)[VPC]
service api(logos:aws-api-gateway)[API Gateway] in vpc
service lambda(logos:aws-lambda)[Lambda] in vpc
service db(logos:aws-dynamodb)[DynamoDB] in vpc
service s3(logos:aws-s3)[S3 Bucket]
api:R --> L:lambda
lambda:R --> L:db
lambda:B --> T:s3
IMPORTANT: Architecture-beta diagrams with logos:* icons require icon pack registration. When rendering with the render script, use the --icons logos flag. If rendering in a markdown viewer that doesn't support icon packs, use the built-in icons (cloud, database, disk, server, internet) as fallback. Read references/aws-architecture.md for the complete icon catalog and rendering instructions.
For comprehensive syntax of ALL diagram types, read references/diagram-types.md.
C4 diagrams have fixed element styling (blue boxes for systems, gray for persons, etc.), but their relationship lines default to harsh black which creates visual noise. You MUST apply these styling rules:
Every C4 diagram MUST include these directives at the end:
%% === MANDATORY STYLING ===
%% Apply soft line colors to ALL relationships
UpdateRelStyle(fromAlias, toAlias, $textColor="#475569", $lineColor="#94a3b8")
%% Repeat for each Rel() in the diagram
%% Optimize layout spacing
UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")
| Purpose | Color | Hex | Notes |
|---|---|---|---|
| Soft line color | Slate-400 | #94a3b8 |
Replaces harsh default black |
| Line text color | Slate-600 | #475569 |
Readable but not dominant |
| Accent line | Blue-400 | #60a5fa |
For highlighted or primary relationships |
| Warning line | Amber-500 | #f59e0b |
For external/risky connections |
| Custom element bg | Emerald | #10b981 |
For data stores or success highlights |
| Custom element bg | Indigo | #4f46e5 |
For primary system emphasis |
CRITICAL — Maximum 6 Rel() per diagram. More than 6 relationships causes Dagre to route arrows through nodes, creating unreadable spaghetti. If your system needs more connections, split it into multiple focused diagrams.
$c4ShapeInRow="3" for most diagrams (prevents horizontal crowding)$c4ShapeInRow="2" for diagrams with long labels$c4BoundaryInRow="1" always (stacks boundaries vertically for clarity)$offsetY="-10" to UpdateRelStyle when labels overlap with elementsContainer() declarations affects layoutRel_D, Rel_R, etc. only as a last resort when auto-layout creates overlappingFor comprehensive C4 syntax, examples, and patterns, read references/c4-architecture.md.
Before rendering, ALWAYS validate the Mermaid syntax:
node $SKILL_DIR/scripts/validate.mjs <file.mmd>
If validation fails:
references/troubleshooting.md for common fixesbash $SKILL_DIR/scripts/setup.sh
This auto-installs both rendering engines and icon pack dependencies. Run once per environment.
# SVG (default — best quality)
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg
# PNG (for documents/presentations)
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.png --width 1200
# ASCII (for terminals/READMEs)
node $SKILL_DIR/scripts/render-ascii.mjs -i diagram.mmd
# With icon packs (architecture-beta with AWS/tech icons)
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg --icons logos,fa
The --icons flag registers Iconify packs before rendering. Packs: logos (AWS/tech), fa (Font Awesome). Use logos for AWS.
For multiple diagrams at once:
node $SKILL_DIR/scripts/batch.mjs \
--input-dir ./diagrams \
--output-dir ./rendered \
--format svg \
--theme default \
--workers 4
beautiful-mermaid (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 (5): default | forest | dark | neutral | base
Custom theme: --theme base --config '{"theme":"base","themeVariables":{"primaryColor":"#4f46e5","lineColor":"#94a3b8"}}'
For the full theme catalog, read references/themes.md. The render script auto-selects the best engine (mmdc primary, beautiful-mermaid fallback, Puppeteer for icon packs).
When the user asks to visualize existing code or architecture:
references/code-to-diagram.md for the analysis methodology| 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 |
| Lines too dark/thick | No init directive | Add %%{init} with lineColor: '#94a3b8' |
| C4 lines overlapping | No styling applied | Add UpdateRelStyle with offsets to each Rel |
| AWS icons not showing | No icon pack | Use --icons logos flag or fallback to built-in icons |
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.
{purpose}-{type}.mmd (e.g., auth-flow-sequence.mmd)