Skip to content

mxnklimt/Code_Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

🧠 Code Analysis — 代码逻辑图自动生成器

A Claude Code Skill that automatically scans project directories and generates high-resolution bilingual (EN/CN) code logic diagrams — tailored for DL/ML model architectures and multi-language system design.


✨ Features

Feature Description
🔍 Smart Scan Auto-detect model definitions (PyTorch/TF/ONNX/Flax), training pipelines, and service code
🏗️ DL Model Architecture Paper-style model diagrams tracing forward()/create_model() execution path
📊 Code Logic Diagrams Call graphs, sequence diagrams, data-flow charts, class diagrams
🌐 Bilingual Labels All nodes/edges in English + 中文 for cross-team readability
🔠 Large Font Rendering Mermaid config-based 24px font sizing — text never overflows node boundaries
🖼️ High-res Output 4× scale, 3840×2880 canvas — sharp even at poster-size prints
🎨 Professional Styling Custom classDef color palette, grouped subgraphs, labeled edges
🚀 Zero Config Auto-installs mermaid-cli via npx if not present

📂 Repository Structure

Code_Analysis/
├── README.md                          ← You are here
├── code-diagram-generator/            ← Claude Code Skill
│   └── SKILL.md                       ← Skill definition (install this)
└── diagrams/                          ← Example outputs (faster-whisper project)
    ├── mermaid-config.json            ← Font config (24px, spacing)
    ├── large-font.css                 ← CSS supplementary protection
    ├── model/
    │   ├── whisper_architecture.mmd   ← Whisper model E2E architecture
    │   ├── whisper_architecture.svg
    │   └── whisper_architecture.png   (4× scale)
    ├── logic/
    │   ├── transcription_call_graph.* ← Full module call graph
    │   ├── transcription_sequence.*   ← 7-phase transcription timeline
    │   ├── batched_vs_sequential.*    ← Two inference mode comparison
    │   └── project_structure.*        ← Package structure & deps
    └── pipeline/
        ├── inference_pipeline.mmd     ← End-to-end inference data flow
        ├── inference_pipeline.svg
        └── inference_pipeline.png     (4× scale)

📸 Example Outputs

Whisper Model Architecture 模型架构

The complete faster-whisper inference pipeline: Audio Input → PyAV Decode → Silero VAD → STFT/Mel Feature Extraction → CTranslate2 Encoder (Conv1D + Transformer) → Decoder (Token Embedding + Cross-Attention) → Beam Search with Temperature Fallback → Word-level Alignment via DTW.

Whisper Architecture


Transcription Call Graph 转录调用图

Full call relationship across all modules: WhisperModel.transcribe() and BatchedInferencePipeline.transcribe() entry points, spanning audio.py, feature_extractor.py, tokenizer.py, vad.py, and the CTranslate2 backend.

Call Graph


Transcription Sequence 转录时序图

Complete 7-phase lifecycle of a single transcribe() call: Audio Decode → VAD Filter → Feature Extraction → Language Detection → Sliding Window Generation (with fallback) → Word Timestamps → Timestamp Restoration.

Transcription Sequence


Sequential vs Batched Mode 顺序模式 vs 批处理模式

Architecture comparison of the two inference modes: WhisperModel.transcribe() (sliding window, condition on previous text) vs BatchedInferencePipeline (VAD-chunked, parallel batch GPU inference).

Batched vs Sequential


Inference Pipeline 推理流水线

End-to-end data flow from audio input (file/stream/array) through decode, VAD, Mel spectrogram, CTranslate2 encoder/decoder, to segment/word output.

Inference Pipeline


Project Structure 工程目录结构

Package layout and internal module dependencies of faster-whisper: transcribe.py (core, ~1900 lines) depending on feature_extractor.py, audio.py, tokenizer.py, vad.py, and utils.py.

Project Structure


🚀 How to Use (as a Claude Code Skill)

Install

  1. Copy code-diagram-generator/SKILL.md to ~/.claude/skills/code-diagram-generator/SKILL.md
  2. Or point Claude Code to this repo path

Invoke

Just tell Claude:

帮我分析 D:\my-project 的代码结构,生成逻辑图

Or in English:

Generate architecture diagrams for ./my-ml-project

Requirements

  • Node.js ≥ 16 (for mermaid-cli)
  • mermaid-cli auto-installs via npx

🔧 Rendering (Manual)

If you want to render .mmd files yourself:

# All-in-one command
npx @mermaid-js/mermaid-cli \
  -i input.mmd \
  -o output.png \
  -b white \
  -c mermaid-config.json \
  --width 3840 --height 2880 --scale 4 --pdfFit

Key file: diagrams/mermaid-config.json — this sets fontSize: "24px" at the layout engine level, so node containers are sized correctly for large bilingual text.


🎨 Design Decisions

Decision Reasoning
Mermaid (not Graphviz/D2) Text-based, version-controllable, GitHub-native rendering
Config-based font sizing (not CSS) CSS can't change baked-in foreignObject dimensions — config makes layout engine compute correct sizes
--scale 4 4× oversampling produces print-quality PNGs (1-3 MB each)
Bilingual labels Teams in China often mix EN/CN; single-language diagrams always leave someone out
classDef color palette Mermaid defaults are pastel and hard to distinguish; professional colors improve scannability

📋 Supported Languages & Frameworks

Language Frameworks Detected
Python PyTorch, TensorFlow, Keras, JAX/Flax, PaddlePaddle, ONNX Runtime, Flask
Go net/http, TF C API, ONNX Runtime Go, Redis
Rust Actix-web, TF C FFI, ort crate, Redis
JavaScript/TypeScript Node.js patterns, Express
General Any project with function calls, classes, or data pipelines

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages