Agent Skillszebbern/claude-code-guide › code-to-diagram

code-to-diagram

GitHub

通过AST解析代码库的导入依赖,自动生成架构图、流程图和目录结构图。支持Python/JS/TS/Go/Java,输出Mermaid或SVG格式,用于可视化代码结构、理解模块关系及辅助重构。

skills/code-to-diagram/SKILL.md zebbern/claude-code-guide

Trigger Scenarios

用户要求可视化代码架构 需要绘制模块依赖图 分析项目结构以便重构 生成技术文档中的架构图

Install

npx skills add zebbern/claude-code-guide --skill code-to-diagram -g -y
More Options

Use without installing

npx skills use zebbern/claude-code-guide@code-to-diagram

指定 Agent (Claude Code)

npx skills add zebbern/claude-code-guide --skill code-to-diagram -a claude-code -g -y

安装 repo 全部 skill

npx skills add zebbern/claude-code-guide --all -g -y

预览 repo 内 skill

npx skills add zebbern/claude-code-guide --list

SKILL.md

Frontmatter
{
    "name": "code-to-diagram",
    "tags": [
        "visualization",
        "architecture",
        "mermaid",
        "ast",
        "diagram"
    ],
    "type": "tool",
    "license": "MIT",
    "description": "Analyze codebases and automatically generate architecture diagrams, flowcharts, and org charts. Uses AST parsing to map import dependencies for Python, JS\/TS, Go, and Java, outputting Mermaid or SVG files. Triggered when users ask to visualize code architecture, understand dependencies, draw a flowchart, or create a module diagram from source code."
}

Code to Diagram

Extract import and dependency relationships from a codebase via AST parsing, and automatically generate three types of diagrams:

  1. Architecture Diagram — Module/directory-level dependency relationships
  2. Flowchart — File-level import call chains
  3. Org Chart — Directory/file hierarchy structure

Supported languages: Python, JavaScript, TypeScript, Go, Java

Output formats: Mermaid text (.mmd) or SVG images (requires mmdc installed on the system)

Usage

Basic: Analyze an Entire Project

python3 scripts/analyze_codebase.py /path/to/project

Outputs three Mermaid diagrams to stdout and writes .mmd files to the current directory.

Specify Diagram Type

# Architecture diagram only
python3 scripts/analyze_codebase.py /path/to/project --type architecture

# Flowchart only
python3 scripts/analyze_codebase.py /path/to/project --type flowchart

# Org chart only
python3 scripts/analyze_codebase.py /path/to/project --type org

Specify Output Directory and Format

# Output to a specific directory
python3 scripts/analyze_codebase.py /path/to/project --output /tmp/diagrams

# Output as SVG (requires mmdc)
python3 scripts/analyze_codebase.py /path/to/project --format svg

# Output both Mermaid and SVG
python3 scripts/analyze_codebase.py /path/to/project --format both

Output JSON Analysis Results

python3 scripts/analyze_codebase.py /path/to/project --json

Parameters

Parameter Description
directory Code directory to analyze (required)
--type, -t Diagram type: architecture, flowchart, org, all (default: all)
--output, -o Output directory (default: current directory)
--format, -f Output format: mermaid, svg, both (default: mermaid)
--max-files Maximum number of files to scan (default: 500)
--max-depth Maximum depth for org chart (default: 4)
--json Output analysis results in JSON format

How It Works

  1. Scan phase: Recursively traverse the directory, skipping node_modules, .git, __pycache__, etc.
  2. Parse phase:
    • Python files: uses the ast module to parse import and from ... import statements
    • JS/TS files: uses regex to match import, require, and export from
    • Go files: uses regex to match import statements
    • Java files: uses regex to match import statements
  3. Resolve internal dependencies: Maps import paths to actual files within the project
  4. Generate diagrams: Converts dependency relationships into Mermaid diagram syntax
  5. Render (optional): Calls mmdc (Mermaid CLI) to render .mmd files as SVG

Use Cases

  • Quickly understand the module structure of an unfamiliar project
  • Visualize dependencies during code review
  • Create architecture diagrams for technical documentation
  • Detect circular dependencies or excessive coupling
  • Analyze project structure before refactoring

Dependencies

  • Python 3.7+ (standard library only, no extra packages needed)
  • SVG output requires @mermaid-js/mermaid-cli (optional)

Notes

  • Only analyzes static import relationships; dynamic imports are not tracked
  • For large projects, use --max-files to limit the scan scope
  • Mermaid diagrams with too many nodes may be hard to render; use --type to generate diagrams separately

Version History

  • 1ed99ef Current 2026-07-25 05:52

Same Skill Collection

skills/academic-paper-reviewer/SKILL.md
skills/active-directory-attacks/SKILL.md
skills/api-fuzzing-bug-bounty/SKILL.md
skills/api-shape-explorer/SKILL.md
skills/audit-flow/SKILL.md
skills/authentication-patterns/SKILL.md
skills/aws-penetration-testing/SKILL.md
skills/broken-authentication/SKILL.md
skills/burp-suite-testing/SKILL.md
skills/caching/SKILL.md
skills/chart-image/SKILL.md
skills/cloud-penetration-testing/SKILL.md
skills/code-documenter/SKILL.md
skills/composition-patterns/SKILL.md
skills/cross-examine/SKILL.md
skills/cv-tailor/SKILL.md
skills/data-viz-renderer/SKILL.md
skills/database-optimizer/SKILL.md
skills/database-scout/SKILL.md
skills/dataset-quality-audit/SKILL.md
skills/deep-module-refactor/SKILL.md
skills/design-system-builder/SKILL.md
skills/dev-guide-generator/SKILL.md
skills/ethical-hacking-methodology/SKILL.md
skills/file-path-traversal/SKILL.md
skills/html-injection-testing/SKILL.md
skills/http-load-profiler/SKILL.md
skills/idor-testing/SKILL.md
skills/linux-privilege-escalation/SKILL.md
skills/linux-shell-scripting/SKILL.md
skills/localization-toolkit/SKILL.md
skills/log-error-digest/SKILL.md
skills/metasploit-framework/SKILL.md
skills/network-101/SKILL.md
skills/nextjs-developer/SKILL.md
skills/pdf/SKILL.md
skills/pentest-checklist/SKILL.md
skills/pentest-commands/SKILL.md
skills/pipeline-blueprint/SKILL.md
skills/playwright/ci/SKILL.md
skills/playwright/core/SKILL.md
skills/playwright/migration/SKILL.md
skills/playwright/playwright-cli/SKILL.md
skills/playwright/pom/SKILL.md
skills/playwright/SKILL.md
skills/privilege-escalation-methods/SKILL.md
skills/project-sizing-guide/SKILL.md
skills/r2-upload/SKILL.md
skills/r3f-animation/SKILL.md

Metadata

Files
0
Version
90de986
Hash
82de1fa7
Indexed
2026-07-25 05:52

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-20 09:12
浙ICP备14020137号-1 $mapa de visitantes$