mermaid-studio

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Mermaid Studio

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.
专业级Mermaid图表创建、验证与多格式渲染工具。可根据描述或代码分析生成图表,验证语法,并通过专业主题渲染为SVG、PNG或ASCII格式。

Golden Rules — Elegant Diagrams by Default

黄金准则——默认生成优雅图表

Every diagram MUST follow these principles. They are not optional — they define the difference between a mediocre diagram and a gold-standard one.
所有图表必须遵循以下原则,这些原则是区分普通图表与高标准图表的核心,不可省略。

Rule 1: Always Use an Init Directive for Professional Styling

规则1:始终使用Init指令实现专业样式

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.
绝对不要在没有
%%{init}
指令或前置配置的情况下创建图表。Mermaid默认主题线条生硬、颜色通用,务必使用精心调配的调色板。
通用图表(流程图、时序图、状态图、类图、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'
}}}%%
⚠️ 字体警告: 不要在主题变量中设置
fontFamily
。Mermaid默认字体(
trebuchet ms, verdana, arial, sans-serif
)可在所有环境正常显示。若设置
system-ui
Segoe UI
-apple-system
,在
mmdc
使用的无头Chromium环境中会渲染为Times New Roman字体。
C4图表——请参考下方专门的C4样式章节。
architecture-beta图表——请参考下方专门的AWS/架构章节。

Rule 2: Soft Lines, Never Harsh Black

规则2:使用柔和线条,避免生硬黑色

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).
提升视觉效果最关键的一点是使用
lineColor: '#94a3b8'
(石板灰-400)替代默认黑色,打造现代感、透气感的图表。深色主题下使用
lineColor: '#64748b'
(石板灰-500)。

Rule 3: Limit Density — Breathe

规则3:控制密度,留足留白

  • Maximum 15 nodes per diagram (not 20 — fewer is more elegant)
  • Use
    subgraph
    or boundaries to create whitespace and visual grouping
  • Prefer LR (left-right) for process flows — it reads more naturally
  • Use invisible links (
    A ~~~ B
    ) to add spacing when the layout is cramped
  • 每张图最多15个节点(而非20个——越少越优雅)
  • 使用
    subgraph
    或边界创建留白与视觉分组
  • 流程类图表优先使用LR(从左到右)方向,更符合阅读习惯
  • 布局拥挤时,使用隐形链接(
    A ~~~ B
    )增加间距

Rule 4: Meaningful Labels and Consistent Style

规则4:标签表意清晰,风格保持一致

  • Node IDs: camelCase (
    orderService
    , not
    s1
    or
    os
    )
  • Labels: short, clear natural language (
    [Order Service]
    )
  • Arrows: action verbs with protocol info (
    "Sends order via gRPC"
    )
  • Descriptions: one-line, role-focused (
    "Handles order lifecycle"
    )
  • 节点ID:采用驼峰命名法(
    orderService
    ,而非
    s1
    os
  • 标签:简短、清晰的自然语言(
    [订单服务]
  • 箭头:带协议信息的动作动词(
    "通过gRPC发送订单"
  • 描述:单行、聚焦角色(
    "处理订单生命周期"

Rule 5: Color Harmony Over Color Variety

规则5:色彩和谐优先于色彩多样

Use max 3-4 colors per diagram. Map colors to meaning:
  • Blue tones (#4f46e5, #3b82f6) → primary systems, internal services
  • Green tones (#10b981, #059669) → success states, data stores
  • Amber tones (#f59e0b, #d97706) → external systems, warnings
  • Slate tones (#64748b, #94a3b8) → lines, borders, secondary elements
  • Red tones (#ef4444) → errors ONLY, never as decoration
每张图最多使用3-4种颜色,为颜色赋予明确含义:
  • 蓝色调(#4f46e5、#3b82f6)→ 核心系统、内部服务
  • 绿色调(#10b981、#059669)→ 成功状态、数据存储
  • 琥珀色调(#f59e0b、#d97706)→ 外部系统、警告
  • 石板色调(#64748b、#94a3b8)→ 线条、边框、次要元素
  • 红色调(#ef4444)→ 仅用于错误提示,绝不作为装饰

Modes of Operation

运行模式

This skill operates in three modes based on user intent:
ModeTriggerWhat 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 requestsCreate → Validate → Render
Default to Full mode when intent is unclear.
本工具根据用户意图分为三种运行模式:
模式触发关键词执行操作
创建"绘制...的图表"、"可视化我的..."仅生成.mmd代码
渲染"渲染这个Mermaid图表"、"转换为SVG/PNG/ASCII"渲染已有的.mmd文件
完整"创建并渲染..."、意图不明确的请求创建 → 验证 → 渲染
当用户意图不明确时,默认使用完整模式。

Step 1: Understand the Request

步骤1:理解需求

Before writing any Mermaid code, determine:
  1. What to diagram — system, flow, schema, architecture, code structure?
  2. Which diagram type — use the Decision Matrix below
  3. Output format — code only, SVG, PNG, or ASCII?
  4. Theme preference — ask only if rendering; default to
    base
    theme with curated palette
在编写任何Mermaid代码前,需明确:
  1. 图表内容 —— 系统、流程、 schema、架构、代码结构?
  2. 图表类型 —— 使用下方的决策矩阵选择
  3. 输出格式 —— 仅代码、SVG、PNG还是ASCII?
  4. 主题偏好 —— 仅在渲染时询问;默认使用
    base
    主题及精心调配的调色板

Diagram Type Decision Matrix

图表类型决策矩阵

User describes...Diagram TypeSyntax keyword
Process, algorithm, decision tree, workflowFlowchart
flowchart TD/LR
API calls, message passing, request/responseSequence
sequenceDiagram
Database schema, table relationshipsERD
erDiagram
OOP classes, domain model, interfacesClass
classDiagram
State machine, lifecycle, transitionsState
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 stepsC4 Dynamic
C4Dynamic
Infrastructure, cloud deploymentC4 Deployment
C4Deployment
Cloud services with icons (AWS/GCP/Azure)Architecture
architecture-beta
Project timeline, schedulingGantt
gantt
Proportional data, percentagesPie
pie
Brainstorming, hierarchical ideasMindmap
mindmap
Historical events, chronologyTimeline
timeline
Branching strategy, git historyGit Graph
gitGraph
Flow quantities, resource distributionSankey
sankey-beta
X/Y data visualizationXY Chart
xychart-beta
Priority matrix, strategic positioningQuadrant
quadrantChart
Layout control, grid positioningBlock
block-beta
Network packets, protocol headersPacket
packet-beta
Task boards, kanban workflowKanban
kanban
User experience, satisfaction scoringUser Journey
journey
System requirements traceabilityRequirement
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.
用户描述内容图表类型语法关键字
流程、算法、决策树、工作流流程图
flowchart TD/LR
API调用、消息传递、请求/响应时序图
sequenceDiagram
数据库schema、表关系ERD图
erDiagram
面向对象类、领域模型、接口类图
classDiagram
状态机、生命周期、状态转换状态图
stateDiagram-v2
高层系统概览(C4 Level 1)C4上下文图
C4Context
应用、数据库、服务(C4 Level 2)C4容器图
C4Container
内部组件(C4 Level 3)C4组件图
C4Component
带编号步骤的请求流C4动态图
C4Dynamic
基础设施、云部署C4部署图
C4Deployment
带图标的云服务(AWS/GCP/Azure)架构图
architecture-beta
项目时间线、排程甘特图
gantt
比例数据、百分比饼图
pie
头脑风暴、层级化想法思维导图
mindmap
历史事件、年表时间线图
timeline
分支策略、Git历史Git图
gitGraph
流量数量、资源分配桑基图
sankey-beta
X/Y数据可视化XY图表
xychart-beta
优先级矩阵、战略定位象限图
quadrantChart
布局控制、网格定位块图
block-beta
网络数据包、协议头数据包图
packet-beta
任务看板、看板工作流看板图
kanban
用户体验、满意度评分用户旅程图
journey
系统需求可追溯性需求图
requirementDiagram
若用户描述无法明确对应某一类型,建议2-3个选项并简要说明理由,再让用户选择。

When to Load References

何时加载参考文件

Load reference files ONLY when needed for the specific diagram type:
  • C4 diagrams → Read
    references/c4-architecture.md
    BEFORE writing code
  • AWS/Cloud architecture → Read
    references/aws-architecture.md
    BEFORE writing code
  • Code-to-diagram → Read
    references/code-to-diagram.md
    BEFORE analyzing
  • Theming/styling → Read
    references/themes.md
    when user requests custom themes
  • Syntax errors → Read
    references/troubleshooting.md
    when validation fails
  • Any diagram type details → Read
    references/diagram-types.md
    for comprehensive syntax
仅在特定图表类型需要时加载参考文件:
  • C4图表 → 编写代码前阅读
    references/c4-architecture.md
  • AWS/云架构图 → 编写代码前阅读
    references/aws-architecture.md
  • 代码转图表 → 分析前阅读
    references/code-to-diagram.md
  • 主题/样式 → 用户要求自定义主题时阅读
    references/themes.md
  • 语法错误 → 验证失败时阅读
    references/troubleshooting.md
  • 任何图表类型细节 → 阅读
    references/diagram-types.md
    获取完整语法

Step 2: Create the Diagram

步骤2:创建图表

2.1 — Write Mermaid Code

2.1 — 编写Mermaid代码

Follow these principles in order of priority:
  1. Elegance first — every diagram must look professional with init directives and curated colors
  2. Correctness — valid syntax that renders without errors
  3. Clarity — meaningful labels, logical flow direction, clear relationships
  4. Simplicity — under 15 nodes per diagram; split complex systems into multiple
  5. Consistency — uniform naming (camelCase for IDs, descriptive labels in brackets)
按以下优先级遵循原则:
  1. 优雅优先 —— 所有图表必须通过init指令和精心调配的颜色实现专业外观
  2. 正确性 —— 语法有效,可正常渲染
  3. 清晰性 —— 标签表意明确、流向逻辑清晰、关系明确
  4. 简洁性 —— 每张图节点数少于15;复杂系统拆分为多张图
  5. 一致性 —— 命名统一(ID用驼峰命名法,标签用描述性括号格式)

2.2 — Structure Rules

2.2 — 结构规则

%% 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:
  • Node IDs: camelCase, descriptive (
    orderService
    , not
    s1
    )
  • 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 processes
  • LR
    (left-right) for timelines, pipelines, and sequential processes
  • RL
    for right-to-left reading contexts
  • Use
    subgraph
    to group related nodes; name subgraphs meaningfully
  • Add
    direction
    inside subgraphs when needed for different flow
%% Diagram: [用途] | Author: [自动生成] | Date: [自动生成]
%%{init: {'theme': 'base', 'themeVariables': { ... }}}%%
[diagramType]
    [内容]
关键注意事项:
%%{init}
指令必须放在第一行非注释位置,在图表类型声明之前。或者,在文件最开头使用YAML前置配置。
命名规范:
  • 节点ID:驼峰命名法,具描述性(
    orderService
    ,而非
    s1
  • 标签:括号内的自然语言(
    [订单服务]
  • 关系:动作动词(
    "发送订单至"
    "读取自"
布局最佳实践:
  • TD
    (自上而下)用于层级化流程和处理过程
  • LR
    (从左到右)用于时间线、流水线和顺序流程
  • RL
    用于从右到左的阅读场景
  • 使用
    subgraph
    分组相关节点;子图命名需具意义
  • 当需要不同流向时,在子图内添加
    direction
    指令

2.3 — Quick Reference Examples

2.3 — 快速参考示例

Flowchart (with professional styling):
mermaid
%%{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):
mermaid
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):
mermaid
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
.
流程图(带专业样式):
mermaid
%%{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([开始]) --> Input[/用户输入/]
    Input --> Validate{验证通过?}
    Validate -->|是| Process[处理数据]
    Validate -->|否| Error[显示错误]
    Error --> Input
    Process --> Save[(保存至数据库)]
    Save --> End([结束])
时序图和ERD样式示例,请阅读
references/themes.md
C4上下文图(必须使用优雅样式):
mermaid
C4Context
    title System Context — 电商平台

    Person(customer, "客户", "在线下单")
    System(platform, "电商平台", "处理订单与支付")
    System_Ext(payment, "支付网关", "处理交易")
    System_Ext(email, "邮件服务", "发送通知")

    Rel(customer, platform, "使用", "HTTPS")
    Rel(platform, payment, "处理支付", "API")
    Rel(platform, email, "发送邮件", "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")
架构图(AWS带Iconify图标):
mermaid
architecture-beta
    group vpc(logos:aws-vpc)[VPC]

    service api(logos:aws-api-gateway)[API网关] in vpc
    service lambda(logos:aws-lambda)[Lambda] in vpc
    service db(logos:aws-dynamodb)[DynamoDB] in vpc
    service s3(logos:aws-s3)[S3存储桶]

    api:R --> L:lambda
    lambda:R --> L:db
    lambda:B --> T:s3
重要提示:
logos:*
图标的architecture-beta图表需要注册图标包。使用渲染脚本时,需添加
--icons logos
参数。若在不支持图标包的Markdown查看器中渲染,使用内置图标(
cloud
database
disk
server
internet
)作为替代。完整图标目录和渲染说明请阅读
references/aws-architecture.md
所有图表类型的完整语法,请阅读
references/diagram-types.md

C4 Diagrams — Mandatory Styling Guide

C4图表——强制样式指南

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:
C4图表的元素样式是固定的(系统为蓝色框,人物为灰色框等),但默认的关系线条是生硬的黑色,会造成视觉干扰。必须应用以下样式规则:

The C4 Styling Pattern

C4样式模板

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")
所有C4图表必须在末尾添加以下指令:
    %% === 强制样式 ===
    %% 为所有关系应用柔和线条颜色
    UpdateRelStyle(fromAlias, toAlias, $textColor="#475569", $lineColor="#94a3b8")
    %% 为图表中每个Rel()重复此指令

    %% 优化布局间距
    UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")

C4 Color Values Reference

C4颜色参考值

PurposeColorHexNotes
Soft line colorSlate-400
#94a3b8
Replaces harsh default black
Line text colorSlate-600
#475569
Readable but not dominant
Accent lineBlue-400
#60a5fa
For highlighted or primary relationships
Warning lineAmber-500
#f59e0b
For external/risky connections
Custom element bgEmerald
#10b981
For data stores or success highlights
Custom element bgIndigo
#4f46e5
For primary system emphasis
用途颜色名称十六进制值说明
柔和线条颜色石板灰-400
#94a3b8
替代生硬的默认黑色
线条文本颜色石板灰-600
#475569
清晰可读但不突兀
强调线条颜色蓝色-400
#60a5fa
用于高亮或核心关系
警告线条颜色琥珀色-500
#f59e0b
用于外部/高风险连接
自定义元素背景翡翠绿
#10b981
用于数据存储或成功状态高亮
自定义元素背景靛蓝色
#4f46e5
用于核心系统强调

C4 Layout Tips

C4布局技巧

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.
  • Use
    $c4ShapeInRow="3"
    for most diagrams (prevents horizontal crowding)
  • Use
    $c4ShapeInRow="2"
    for diagrams with long labels
  • Use
    $c4BoundaryInRow="1"
    always (stacks boundaries vertically for clarity)
  • Apply
    $offsetY="-10"
    to
    UpdateRelStyle
    when labels overlap with elements
  • Prefer tree-shaped topologies (1 in, 1-2 out per node) over mesh topologies
  • Declare elements in flow order — the order of
    Container()
    declarations affects layout
  • Use directional
    Rel_D
    ,
    Rel_R
    , etc. only as a last resort when auto-layout creates overlapping
For comprehensive C4 syntax, examples, and patterns, read
references/c4-architecture.md
.
关键注意事项——每张图最多6个
Rel()
。超过6个关系会导致Dagre引擎将箭头穿过节点,造成图表难以阅读。若系统需要更多连接,将其拆分为多张聚焦的图表。
  • 大多数图表使用
    $c4ShapeInRow="3"
    (避免水平拥挤)
  • 标签较长的图表使用
    $c4ShapeInRow="2"
  • 始终使用
    $c4BoundaryInRow="1"
    (垂直堆叠边界,提升清晰度)
  • 标签与元素重叠时,在
    UpdateRelStyle
    中添加
    $offsetY="-10"
  • 优先选择树形拓扑(每个节点1个输入,1-2个输出)而非网状拓扑
  • 按流向顺序声明元素——
    Container()
    的声明顺序会影响布局
  • 仅当自动布局造成重叠时,才作为最后手段使用定向
    Rel_D
    Rel_R
    等指令
完整C4语法、示例和模板,请阅读
references/c4-architecture.md

Step 3: Validate

步骤3:验证

Before rendering, ALWAYS validate the Mermaid syntax:
bash
node $SKILL_DIR/scripts/validate.mjs <file.mmd>
If validation fails:
  1. Read the error message carefully
  2. Consult
    references/troubleshooting.md
    for common fixes
  3. Fix the syntax and re-validate
  4. Maximum 3 fix attempts before asking the user for clarification
渲染前,必须验证Mermaid语法:
bash
node $SKILL_DIR/scripts/validate.mjs <file.mmd>
若验证失败:
  1. 仔细阅读错误信息
  2. 参考
    references/troubleshooting.md
    获取常见修复方案
  3. 修复语法后重新验证
  4. 最多尝试3次修复,若仍失败则向用户请求澄清

Step 4: Render

步骤4:渲染

4.1 — Setup (First Run Only)

4.1 — 初始化(仅首次运行)

bash
bash $SKILL_DIR/scripts/setup.sh
This auto-installs both rendering engines and icon pack dependencies. Run once per environment.
bash
bash $SKILL_DIR/scripts/setup.sh
此脚本会自动安装两个渲染引擎和图标包依赖。每个环境仅需运行一次。

4.2 — Single Diagram Rendering

4.2 — 单图表渲染

bash
undefined
bash
undefined

SVG (default — best quality)

SVG(默认——最佳画质)

node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg

PNG (for documents/presentations)

PNG(用于文档/演示文稿)

node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.png --width 1200
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.png --width 1200

ASCII (for terminals/READMEs)

ASCII(用于终端/ README)

node $SKILL_DIR/scripts/render-ascii.mjs -i diagram.mmd
node $SKILL_DIR/scripts/render-ascii.mjs -i diagram.mmd

With icon packs (architecture-beta with AWS/tech icons)

带图标包(architecture-beta带AWS/技术图标)

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.
node $SKILL_DIR/scripts/render.mjs -i diagram.mmd -o diagram.svg --icons logos,fa

`--icons`参数用于在渲染前注册Iconify图标包。可用包:`logos`(AWS/技术图标)、`fa`(Font Awesome)。AWS图表使用`logos`包。

4.3 — Batch Rendering

4.3 — 批量渲染

For multiple diagrams at once:
bash
node $SKILL_DIR/scripts/batch.mjs \
  --input-dir ./diagrams \
  --output-dir ./rendered \
  --format svg \
  --theme default \
  --workers 4
同时渲染多个图表:
bash
node $SKILL_DIR/scripts/batch.mjs \\
  --input-dir ./diagrams \\
  --output-dir ./rendered \\
  --format svg \\
  --theme default \\
  --workers 4

4.4 — Available Themes

4.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).
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原生(5种):
default
|
forest
|
dark
|
neutral
|
base
自定义主题:
--theme base --config '{"theme":"base","themeVariables":{"primaryColor":"#4f46e5","lineColor":"#94a3b8"}}'
完整主题目录请阅读
references/themes.md
。渲染脚本会自动选择最佳引擎(优先mmdc,其次beautiful-mermaid,图标包使用Puppeteer)。

Step 5: Code-to-Diagram (When Requested)

步骤5:代码转图表(按需使用)

When the user asks to visualize existing code or architecture:
  1. Read
    references/code-to-diagram.md
    for the analysis methodology
  2. 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
  3. Generate the .mmd file with proper init directives (Golden Rule 1)
  4. Validate and render as usual
当用户要求可视化现有代码或架构时:
  1. 阅读
    references/code-to-diagram.md
    获取分析方法
  2. 分析代码库以确定合适的图表类型:
    • 模块依赖 → 流程图或类图
    • API路由与处理器 → 时序图
    • 数据库模型/schema → ERD图
    • 服务架构 → C4容器图或架构图
    • 代码中的状态机 → 状态图
  3. 生成带正确init指令的.mmd文件(遵循黄金规则1)
  4. 按常规流程验证并渲染

Troubleshooting Quick Reference

故障排除快速参考

SymptomLikely CauseFix
Diagram won't renderSyntax errorRun validate.mjs, check brackets/quotes
Labels cut offText too longShorten labels or use line breaks
<br/>
Layout looks wrongWrong directionTry different TD/LR/BT/RL
Nodes overlapToo many nodesSplit into subgraphs or multiple diagrams
Lines too dark/thickNo init directiveAdd
%%{init}
with
lineColor: '#94a3b8'
C4 lines overlappingNo styling appliedAdd
UpdateRelStyle
with offsets to each Rel
AWS icons not showingNo icon packUse
--icons logos
flag or fallback to built-in icons
mmdc
not found
Not installedRun
setup.sh
Theme not appliedWrong enginebeautiful-mermaid themes only work with that engine
For comprehensive troubleshooting, read
references/troubleshooting.md
.
症状可能原因修复方案
图表无法渲染语法错误运行validate.mjs,检查括号/引号
标签被截断文本过长缩短标签或使用换行符
<br/>
布局异常方向错误尝试不同的TD/LR/BT/RL方向
节点重叠节点过多拆分为子图或多张图表
线条过暗/过粗未使用init指令添加带
lineColor: '#94a3b8'
%%{init}
指令
C4线条重叠未应用样式为每个Rel添加带偏移量的
UpdateRelStyle
指令
AWS图标不显示未加载图标包使用
--icons logos
参数或替换为内置图标
mmdc
未找到
未安装运行
setup.sh
主题未生效引擎错误beautiful-mermaid主题仅适用于对应引擎
完整故障排除指南,请阅读
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
  • .mmd源文件与渲染输出文件保存在同一目录
  • 命名规则:
    {用途}-{类型}.mmd
    (例如:
    auth-flow-sequence.mmd
  • 批量渲染:保留输入文件名,修改扩展名
  • 始终向用户提供.mmd源文件和渲染后的文件 ",