mermaid-diagram
它能做什么
这个技能为流程图、时序图、类图等编写 Mermaid 图表代码,然后进行检查。适合任何需要根据文字描述绘制清晰图表的人。
适用场景
- ✓当你需要根据描述生成流程图、时序图或类图时。
- ✓当你希望把 Mermaid 文件保存在图表文件夹中用于文档时。
- ✓当图表包含数学符号,并且必须正确渲染时。
技能链接
https://github.com/wanshuiyin/Auto-claude-code-research-in-sleep/blob/main/skills/skills-codex/mermaid-diagram/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请为我的 API 调用画一张 Mermaid 时序图,保存到图表文件夹,并检查语法。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会选择图表类型,编写代码,并把 .mmd 和 .md 文件保存到图表文件夹。它会验证语法,并在需要时经过几轮调整布局。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Mermaid Diagram Generator
Generate high-quality Mermaid diagram code based on user requirements, with file output and verification.
Constants
- OUTPUT_DIR =
figures/— Output directory for generated files - MAX_ITERATIONS = 3 — Maximum refinement rounds for syntax or layout issues
Workflow: MUST EXECUTE ALL STEPS
Step 0: Pre-flight Check
Create output directory
mkdir -p figures
Step 1: Understand Requirements & Select Diagram Type
Parse the input: $ARGUMENTS
- Analyze the request and choose the most suitable diagram type
- Read the corresponding Mermaid syntax reference below
- If the diagram involves mathematical notation, apply the math syntax rules from the Math Formulas in Diagrams section
- Identify all components, connections, and data flow
- Plan the diagram structure before writing code
Step 2: Read Documentation
Select the appropriate diagram type. Use built-in Mermaid knowledge first; if external documentation is needed and your environment provides it, fetch the up-to-date syntax reference.
Configuration & Themes
Choose theme, colors, and layout before writing code. For academic diagrams, prefer clean white backgrounds, restrained colors, and readable labels over decorative styling.
| Type | Use Cases |
|---|---|
| Flowchart | Processes, decisions, steps |
| Sequence Diagram | Interactions, messaging, API calls |
| Class Diagram | Class structure, inheritance, associations |
| State Diagram | State machines, state transitions |
| ER Diagram | Database design, entity relationships |
| Gantt Chart | Project planning, timelines |
| Pie Chart | Proportions, distributions |
| Mindmap | Hierarchical structures, knowledge graphs |
| Timeline | Historical events, milestones |
| Git Graph | Branches, merges, versions |
| Quadrant Chart | Four-quadrant analysis |
| Requirement Diagram | Requirements traceability |
| C4 Diagram | System architecture |
| Sankey Diagram | Flow, conversions |
| XY Chart | Line charts, bar charts |
| Block Diagram | System components, modules |
| Packet Diagram | Network protocols, data structures |
| Kanban | Task management, workflows |
| Architecture Diagram | System architecture |
| Radar Chart | Multi-dimensional comparison |
| Treemap | Hierarchical data visualization |
| User Journey | User experience flows |
| ZenUML | Sequence diagrams (code style) |
Step 3: Generate Mermaid Code & Save Files
Generate the Mermaid code and save two files:
File 1: figures/<diagram-name>.mmd — Raw Mermaid source
The .mmd file contains only raw Mermaid code, no markdown fences.
File 2: figures/<diagram-name>.md — Markdown with embedded Mermaid
The .md file wraps the same Mermaid code in a mermaid code block for preview rendering, plus a short title and description.
Diagram Title
Use a concise title in the .md wrapper that matches the generated diagram name.
Naming convention: use a descriptive kebab-case name derived from the request, such as auth-flow, system-architecture, or database-er.
Step 4: Verify Mermaid Syntax (MANDATORY)
Codex MUST verify the generated Mermaid code by running the Mermaid CLI (mmdc).
Check if mermaid-cli is available
if command -v mmdc >/dev/null 2>&1; then
mmdc -i figures/<diagram-name>.mmd -o figures/<diagram-name>.png -b transparent \
&& echo "Syntax valid — PNG rendered to figures/<diagram-name>.png"
else
npx -y @mermaid-js/mermaid-cli@latest -i figures/<diagram-name>.mmd -o figures/<diagram-name>.png -b transparent \
&& echo "Syntax valid — PNG rendered to figures/<diagram-name>.png"
fi
If verification fails:
- Read the error carefully
- Fix the syntax issue in both
.mmdand.md - Re-run verification
- Repeat up to
MAX_ITERATIONS
Step 5: Codex STRICT Visual Review & Scoring (MANDATORY)
After successful rendering, Codex MUST read the generated PNG and perform a strict review:
## Codex's STRICT Review of <diagram-name>
### What I See
[Describe the rendered diagram in detail]
### Files Generated
- `figures/<diagram-name>.mmd`
- `figures/<diagram-name>.md`
- `figures/<diagram-name>.png`
### ═══════════════════════════════════════════════════════════════
### STRICT VERIFICATION CHECKLIST (ALL must pass for score ≥ 9)
### ═══════════════════════════════════════════════════════════════
#### A. File Correctness
- [ ] `.mmd` contains valid Mermaid syntax
- [ ] `.
常见问题
图表类型有多少种?
该技能涵盖很多类型,包括流程图、时序图、类图、ER 图和甘特图。
文件保存到哪里?
默认保存到项目中的图表文件夹。
它需要联网吗?
它先使用内置的 Mermaid 知识,只有在环境提供外部文档时才会去获取。
详情
作者的原始描述
Generate Mermaid diagrams from user requirements. Save .mmd and .md files to figures/ with syntax verification. Supports flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, and many more diagram types.
热度
- GitHub 星标
- 18k
- 排名
- #10605
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
ablation-planner
18k帮你的智能体为论文规划消融实验,在主要结果看起来不错之后,选出审稿人很可能会要求的测试。
alphaxiv
18k让你的智能体借助 AlphaXiv 摘要快速阅读一篇研究论文,并以完整文本或 LaTeX 源文件作为备用,只需提供 arXiv 链接或编号。
analyze-results
18k帮你的智能体分析机器学习实验结果,将各次运行与基线进行比较,并把数字整理成清晰的发现和后续步骤。
arxiv
18k让你的智能体在 arXiv 上搜索学术论文、阅读论文详情,并把 PDF 保存到你的文库中,用于某个研究主题。