Mermaid Diagrams Skill
Generates Mermaid diagrams and renders them to PNG using the mmdc CLI.
Reference Files
- - Architecture patterns (flowchart, C4, cloud, network, microservices) → INLINECODE1
- Sequence diagram patterns (API flows, auth, CI/CD, DLP flows) → INLINECODE2
Load the relevant reference file based on diagram type requested.
Rendering Tool
Use mermaid.ink (free online renderer, no browser/install needed):
CODEBLOCK0
- - Output directory: INLINECODE3
- Width: 2048px default; increase for very wide diagrams (
&width=3000) - Always create output directory first: INLINECODE5
Workflow
1. Identify Diagram Type
- - Network/system/cloud/microservices → use
flowchart or INLINECODE7 - API/auth/data flows, step-by-step processes → use INLINECODE8
- When in doubt: sequence for "how does X work step by step", architecture for "what does X look like"
2. Load Reference File
- - Architecture → INLINECODE9
- Sequence → INLINECODE10
3. Generate Mermaid Code
- - Write complete, valid Mermaid syntax
- Use descriptive node labels (not just A, B, C)
- Use subgraphs to group related components in architecture diagrams
- Use alt/loop/note blocks to add clarity in sequence diagrams
- Match the style of the patterns in the reference file
4. Save .mmd File
Save to: INLINECODE11
Use kebab-case, descriptive filenames: auth-flow.mmd, aws-architecture.mmd, INLINECODE14
5. Render to PNG via mermaid.ink
CODEBLOCK1
6. Confirm Output
Report the full path to the saved PNG. Offer to adjust layout, add components, or generate a
.mmd file for further editing in mermaid.live or VS Code.
Tips
- -
flowchart LR for left-to-right pipelines and network flows - INLINECODE17 for top-down hierarchies and cloud stacks
- Wide diagrams: increase
-w (width); tall diagrams: increase -H (height) - For very complex diagrams, break into multiple diagrams
- Always include a title comment at the top of the .mmd file: INLINECODE20
Mermaid 图表技能
生成 Mermaid 图表,并使用 mmdc 命令行工具将其渲染为 PNG 格式。
参考文件
- - 架构模式(流程图、C4、云架构、网络、微服务)→ references/architecture-patterns.md
- 时序图模式(API 流程、认证、CI/CD、DLP 流程)→ references/sequence-patterns.md
根据请求的图表类型加载相应的参考文件。
渲染工具
使用 mermaid.ink(免费在线渲染器,无需浏览器/安装):
bash
mkdir -p /home/bcaddy/.openclaw/workspace/diagrams
ENCODED=$(cat | base64 -w 0)
curl -s https://mermaid.ink/img/${ENCODED}?bgColor=white&width=2048 \
-o /home/bcaddy/.openclaw/workspace/diagrams/.png
- - 输出目录:/home/bcaddy/.openclaw/workspace/diagrams/
- 宽度:默认 2048px;对于非常宽的图表可增加(&width=3000)
- 始终先创建输出目录:mkdir -p /home/bcaddy/.openclaw/workspace/diagrams
工作流程
1. 识别图表类型
- - 网络/系统/云/微服务 → 使用 flowchart 或 C4Context
- API/认证/数据流程、分步过程 → 使用 sequenceDiagram
- 不确定时:对于X 如何逐步工作使用时序图,对于X 是什么样子使用架构图
2. 加载参考文件
- - 架构 → references/architecture-patterns.md
- 时序 → references/sequence-patterns.md
3. 生成 Mermaid 代码
- - 编写完整、有效的 Mermaid 语法
- 使用描述性节点标签(不仅仅是 A、B、C)
- 在架构图中使用子图对相关组件进行分组
- 在时序图中使用 alt/loop/note 块增加清晰度
- 匹配参考文件中的模式风格
4. 保存 .mmd 文件
保存至:/home/bcaddy/.openclaw/workspace/diagrams/<描述性名称>.mmd
使用短横线命名法、描述性文件名:auth-flow.mmd、aws-architecture.mmd、api-gateway-sequence.mmd
5. 通过 mermaid.ink 渲染为 PNG
bash
ENCODED=$(cat /home/bcaddy/.openclaw/workspace/diagrams/
.mmd | base64 -w 0)
curl -s https://mermaid.ink/img/${ENCODED}?bgColor=white&width=2048 \
-o /home/bcaddy/.openclaw/workspace/diagrams/.png
6. 确认输出
报告保存的 PNG 文件的完整路径。提供调整布局、添加组件或生成 .mmd 文件以便在 mermaid.live 或 VS Code 中进一步编辑的选项。
提示
- - flowchart LR 用于从左到右的管道和网络流程
- flowchart TD 用于自上而下的层级结构和云堆栈
- 宽图表:增加 -w(宽度);高图表:增加 -H(高度)
- 对于非常复杂的图表,拆分为多个图表
- 始终在 .mmd 文件顶部包含标题注释:%% Title: ...