Skip to main content

mermaid-diagram

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.

v1.0.0New

Unsigned, install at your own risk

Unverified

This skill has no cryptographic signature attached. We can't verify the contents match what the publisher intended.

Install this skill

No account required. Pick your tool, or use the command that detects it for you.

Run in your terminal. It detects your AI tool.

npx @skills-hub-ai/cli install auto-research-skills-codex-mermaid-diagram
Or get the file:
Browse all CLI commands →
Manual setup by platform

Claude Code

~/.claude/skills/auto-research-skills-codex-mermaid-diagram/SKILL.md

Setup guide →
0Save

Instructions

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

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

  1. Analyze the request and choose the most suitable diagram type
  2. Read the corresponding Mermaid syntax reference below
  3. If the diagram involves mathematical notation, apply the math syntax rules from the Math Formulas in Diagrams section
  4. Identify all components, connections, and data flow
  5. 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.

TypeUse Cases
FlowchartProcesses, decisions, steps
Sequence DiagramInteractions, messaging, API calls
Class DiagramClass structure, inheritance, associations
State DiagramState machines, state transitions
ER DiagramDatabase design, entity relationships
Gantt ChartProject planning, timelines
Pie ChartProportions, distributions
MindmapHierarchical structures, knowledge graphs
TimelineHistorical events, milestones
Git GraphBranches, merges, versions
Quadrant ChartFour-quadrant analysis
Requirement DiagramRequirements traceability
C4 DiagramSystem architecture
Sankey DiagramFlow, conversions
XY ChartLine charts, bar charts
Block DiagramSystem components, modules
Packet DiagramNetwork protocols, data structures
KanbanTask management, workflows
Architecture DiagramSystem architecture
Radar ChartMulti-dimensional comparison
TreemapHierarchical data visualization
User JourneyUser experience flows
ZenUMLSequence 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:

  1. Read the error carefully
  2. Fix the syntax issue in both .mmd and .md
  3. Re-run verification
  4. Continue only while a concrete error remains and the next correction addresses it; respect any user-set round or budget limit.

Step 5: Review the Rendered Diagram (MANDATORY)

After successful rendering, Codex MUST inspect the generated PNG against the request. Check that required components and labels are present, each arrow has the intended source, target, and direction, and the layout, text, and data flow are readable at the intended viewing size. Confirm that .mmd contains raw Mermaid and .md wraps the same code in a Mermaid fence.

Fix concrete semantic or readability problems in both source files, then re-render and inspect the affected areas. Stop when the diagram meets the request and no material issue remains; do not repeat review for a numerical score or cosmetic preference. Respect any user-set round or budget limit. If rendering is unavailable or a material issue remains at that limit, report it clearly instead of claiming verification succeeded.

Step 6: Final Output Summary

When accepted, present:

Mermaid diagram generated successfully.

Files:
  figures/<diagram-name>.mmd
  figures/<diagram-name>.md
  figures/<diagram-name>.png

To re-render manually:
  mmdc -i figures/<diagram-name>.mmd -o figures/<diagram-name>.png

Architecture Diagram Best Practices

When generating architecture-beta diagrams, apply these layout techniques for complex diagrams:

Use Junctions for Layout Control

Think of the diagram as an invisible grid. Use junction nodes as virtual anchor points on that grid to precisely control placement. This is especially useful when a direct edge produces unexpected positioning.

Instead of connecting services directly:

lb:R --> L:scim
lb:R --> L:webapi

Route through junctions:

junction j_lb_r
lb:R -- L:j_lb_r
junction j_scim_l
j_lb_r:T -- B:j_scim_l
j_scim_l:R --> L:scim
junction j_webapi_l
j_lb_r:B -- T:j_webapi_l
j_webapi_l:R --> L:webapi

Use Edges out of Groups for Floating Components

For services that have no real logical connection but still need stable placement, use a junction combined with {group} to anchor them without inventing a semantic edge.

CVPR/ICLR/NeurIPS Style Guide (for Academic Diagrams)

When the diagram is intended for academic papers, apply these style standards:

Visual Standards

  • Clean white background
  • Sans-serif fonts
  • Subtle coordinated color palette
  • Print-friendly grayscale readability
  • Thin professional borders

Layout Standards

  • Horizontal flow for pipelines
  • Clear grouping
  • Consistent sizing
  • Balanced whitespace

Arrow Standards (MOST CRITICAL)

  • Thick strokes
  • Clear arrowheads
  • Dark colors
  • Labeled arrows
  • No crossings
  • Correct direction

Color Palette (Academic Professional)

  • Inputs: Green (#10B981 / #34D399)
  • Encoders: Blue (#2563EB / #3B82F6)
  • Fusion: Purple (#7C3AED / #8B5CF6)
  • Outputs: Orange (#EA580C / #F97316)
  • Arrows: Dark gray (#333333 / #1F2937)
  • Background: White (#FFFFFF)

What to AVOID

  • Rainbow color schemes
  • Thin hairline arrows
  • Heavy shadows or glow effects
  • 3D effects
  • Decorative icons that add no meaning
  • Tiny unreadable text

Math Formulas in Diagrams (KaTeX)

Mermaid supports rendering mathematical expressions via KaTeX. When the diagram content involves formulas, equations, Greek letters, subscripts, superscripts, fractions, or matrices, use KaTeX notation instead of plain-text approximations.

Supported Diagram Types for Math

Math rendering with $$...$$ is supported in:

  • Flowcharts — in node labels and edge labels
  • Sequence Diagrams — in participant aliases, messages, and notes

Syntax Rules

  1. Wrap math expressions in $$ inside quoted strings:

    A["$$x^2$$"] -->|"$$\\sqrt{x+3}$$"| B("$$\\frac{1}{2}$$")
    
  2. Node labels with math must be quoted

  3. Mix text and math by placing $$ only around the math portion

  4. Use \text{} for non-math text inside $$

Common Math Patterns for ML/Science Diagrams

ConceptKaTeX Syntax
Subscript$$W_Q$$
Superscript$$x^2$$
Fraction$$\\frac{QK^T}{\\sqrt{d_k}}$$
Greek letters$$\\alpha, \\beta, \\gamma$$
Square root$$\\sqrt{d_k}$$
Summation$$\\sum_{i=1}^{n} x_i$$
Matrix$$\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix}$$
Softmax$$\\text{softmax}(z_i)$$
Norm`$$\
Hat/tilde$$\\hat{y}, \\tilde{x}$$

Example: Attention Mechanism with Math

flowchart TD
    Q["$$Q \\in \\mathbb{R}^{n \\times d_k}$$"]
    K["$$K \\in \\mathbb{R}^{n \\times d_k}$$"]
    V["$$V \\in \\mathbb{R}^{n \\times d_v}$$"]
    scores["$$\\frac{QK^T}{\\sqrt{d_k}}$$"]
    softmax["$$\\text{softmax}(\\cdot)$$"]
    output["$$\\text{Attention}(Q,K,V)$$"]

    Q --> scores
    K --> scores
    scores --> softmax
    softmax --> weighted["$$\\alpha V$$"]
    V --> weighted
    weighted --> output

When to Use Math vs Plain Text

  • Use math when the diagram is for academic or technical audiences and precision matters
  • Use plain text when the diagram is for general audiences or math would add clutter
  • Default to KaTeX automatically if the request already contains math notation

Gotchas

  • $$ delimiters must be inside quoted strings
  • Very long formulas may overflow node boxes
  • Always verify rendering with mmdc

Code Quality Rules

Generated Mermaid code MUST:

  1. Have correct syntax that renders directly
  2. Have clear structure with proper indentation
  3. Use semantic node naming, not A, B, C
  4. Include styling when needed
  5. Use <br/> for line breaks inside node labels, never \n
  6. Avoid special characters that break Mermaid parsing unless properly quoted

Output Structure

figures/
├── <diagram-name>.mmd
├── <diagram-name>.md
└── <diagram-name>.png

Key Rules (MUST FOLLOW)

  1. Save .mmd and .md files to figures/ with descriptive kebab-case names and identical Mermaid code.
  2. Read the relevant syntax guidance, render with mmdc, and inspect the generated PNG before claiming verification.
  3. Verify components, block contents, labels, and every arrow's direction against the request.
  4. Fix concrete errors and report any unresolved issue or unavailable verification clearly.

User requirements: $ARGUMENTS

This skill doesn’t include stateful context yet, instructions only. Learn about stateful skills.

Security

Loading security scan...

Reviews (0)

Browse all →
specification-writingWrite the full patent specification from claims and invention disclosure. Use when user says "撰写说明书", "write specification", "写说明书", "patent description", or wants to draft the complete patent specification.1 installspatent-pipelineFull patent drafting pipeline from invention description to jurisdiction-formatted filing documents. Supports CN (CNIPA), US (USPTO), EP (EPO). Supports invention patents and utility models. Use when user says "写专利", "patent pipeline", "专利申请", "draft patent", "写权利要求书", or wants to draft a complete patent application.1 installslean-formalizeDevelop and verify a mathematical proof in Lean, continue an incomplete Lean project, or audit whether it proves the original statement. Connect actual inputs to intermediate lemmas, assemble the target theorem, check its transitive axioms, and provide a reproducible handoff. Use when Lean is requested or a specific proof obligation benefits from formal verification; use proof-writer for ordinary mathematical drafting.1 installsfeishu-notifySend notifications to Feishu/Lark. Internal utility used by other skills, or manually via /feishu-notify. Use when user says "发飞书", "notify feishu", or other skills need to send status updates.1 installsauto-review-loop-llmAutonomous research review loop using any OpenAI-compatible LLM API. Configure via llm-chat MCP server or environment variables. Trigger with "auto review loop llm" or "llm review".0 installsinterview-cheatsheetGenerate a long-form Chinese interview-prep cheat sheet on a specific ML/LLM topic — formulas with derivations, from-scratch PyTorch code, comparison tables, and 高频面试题 (L1 必会 / L2 进阶 / L3 顶级 lab). Use when the user says '写面试 cheat sheet', '写一份 X 教程', '帮我准备 Y 面试题', '出一份 X 速查', or wants a detailed Chinese tutorial on a specific ML topic.0 installs

More from Auto Research

View source →
pixel-artGenerate pixel art SVG illustrations for READMEs, docs, or slides. Use when user says "画像素图", "pixel art", "make an SVG illustration", "README hero image", or wants a cute visual.9 installsmermaid-diagramGenerate Mermaid diagrams from user requirements. Supports flowcharts, sequence diagrams, class diagrams, ER diagrams, Gantt charts, and 18 more diagram types.4 installspaper-writingWorkflow 3: Full paper writing pipeline that goes from a narrative report to a polished, submission-ready PDF. Use when user says "写论文全流程", "write paper pipeline", "从报告到PDF", "paper writing", or wants the complete paper generation workflow.4 installspatent-reviewGet an external patent examiner review of a patent application. Use when user says "专利审查", "patent review", "审查意见", "examiner review", or wants critical feedback on patent claims and specification.2 installsexperiment-planTurn a refined research proposal or method idea into a detailed, claim-driven experiment roadmap. Use after `research-refine`, or when the user asks for a detailed experiment plan, ablation matrix, evaluation protocol, run order, compute budget, or paper-ready validation that supports the core problem, novelty, simplicity, and any LLM / VLM / Diffusion / RL-based contribution.2 installscitation-auditZero-context verification that every bibliographic entry in the paper is real, correctly attributed, and used in a context the cited paper actually supports — catching hallucinated authors, wrong years, fabricated venues, version mismatches, and wrong-context citations. Use when user says "审查引用", "check citations", "citation audit", "verify references", "引用核对", or before submission to ensure bibliography integrity.2 installs

More Build skills

Browse category →
senior-frontendBuild and review React, Next.js, TypeScript or Tailwind frontends: components, scaffolding, performance and bundle size. Use whenever the user wants a new component or app, a page feels slow, the bundle is too big, or asks for a frontend code review.635 installsui-design-systemUse when building a design system: tokens, component docs, responsive scales or developer handoff. Generates tokens with design_token_generator.py.535 installsfrontend-designGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.346 installssenior-backendBuild and fix backend services: REST or GraphQL APIs, auth, microservices, PostgreSQL queries, migrations and load tests. Use whenever the user's API is slow or broken, needs login or auth added, a schema change, or a new endpoint or service scaffolded.246 installsself-improving-agentCurate what the agent has learned into durable project knowledge. Reviews Claude Code auto-memory (MEMORY.md and its topic files) for learnings worth keeping, promotes proven ones into CLAUDE.md or .claude/rules/, records a correction as a lesson that persists across sessions, prunes stale or duplicate entries, and turns a recurring fix into a reusable skill. Use whenever the user asks what you have learned or saved about the project, which memories should become permanent rules, to remember a lesson or stop repeating a mistake, or to clean up, audit or check memory health.173 installsusing-superpowersUse when starting any conversation - establishes how to find and use skills, requiring skill invocation before ANY response including clarifying questions145 installs

Frequently asked questions about mermaid-diagram

What does the mermaid-diagram skill do?

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. It's a reusable SKILL.md instruction set that loads into your AI coding assistant on demand, no prompt engineering, no copy-pasting every session.

How do I install the mermaid-diagram skill?

Run `npx @skills-hub-ai/cli install auto-research-skills-codex-mermaid-diagram` from your terminal. The CLI writes the SKILL.md to the correct location for your AI tool (e.g. ~/.claude/skills/auto-research-skills-codex-mermaid-diagram/ for Claude Code or ~/.cursor/skills/ for Cursor with --target cursor) and adds it to your project's .skills.json lockfile.

Which AI tools does mermaid-diagram work with?

mermaid-diagram runs in Claude Code. It follows the open Agent Skills standard (SKILL.md), so the same skill works in every supported tool without modification.

Is the mermaid-diagram skill free?

Yes. Every skill on skills-hub.ai is free and open-source. There are no premium tiers, paywalls, or usage limits. You only pay for whatever AI assistant you're already using.

How do I use mermaid-diagram after installing it?

In Claude Code, type `/auto-research-skills-codex-mermaid-diagram` (or whatever slash command the skill registers) and the AI follows the skill's instructions immediately. You can also reference it by name in natural language, your AI loads the skill into context when relevant.

Can I share the mermaid-diagram skill with my team?

Yes. Commit your project's .skills.json lockfile and teammates run `npx @skills-hub-ai/cli install` (no args) to install every skill at the exact version you pinned. Organization-scoped installs work via skills-hub.ai organizations.