AI Agent Hub
Back to skills
Code To Mermaid Diagrams icon

Code To Mermaid Diagrams

Development Updated 2026.08.29

Paste the following prompt into your AI chat to install this skill:

Please install @user_82af032c/code2diagram by following https://skillhub.cn/install/skillhub.md.

About this skill

Problem It Addresses

When control flow, state transitions, API calls, or entity relationships are spread across multiple files, engineers often have to trace call order, branching logic, and data structures by hand. code2diagram targets this scenario: it reads a directory or file, identifies dominant logic patterns, and produces diagram artifacts that can be reviewed, not just described verbally.

How It Works

The core output consists of two files:

  • Markdown document: contains Mermaid source that can be previewed in Mermaid-capable editors or GitHub.
  • PNG image: a high-resolution rendered result suitable for documentation, comments, or screenshots.

The workflow has roughly four steps: first use Read, Glob, and Grep to understand the code structure; then choose a diagram type based on the pattern, such as stateDiagram-v2 for state machines, sequenceDiagram for message flow, and erDiagram for entity relationships. Next it generates Mermaid source, writes it to a .mmd file, and invokes a rendering script to produce the image.

Boundaries

Diagram labels are expected to use Chinese, while identifiers such as class names, function names, and variable names remain in the original text. It depends on Node.js and npx, and the script attempts to use mermaid-cli; for complex codebases, the abstraction level still needs human review instead of mechanically mapping every detail into one diagram.

Use Cases

  • After taking over an unfamiliar repository, map the main flow and state branches to prepare readable review diagrams.
  • Turn interface call chains and message ordering into sequence diagrams to help trace cross-service issues.
  • Draw domain entities and field relationships into ER diagrams for documentation and onboarding explanations.
  • Generate state diagrams for workflow-engine code to verify state transitions and edge conditions.

Best For

  • Engineers refactoring backend services who need to explain call chains clearly
  • Engineers taking over legacy code who need to prepare technical review diagrams
  • Engineers writing architecture docs who need illustrations for data flow
  • Engineers maintaining workflow systems who need to sort out state machines