project-analysis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese项目分析技能
Project Analysis Skill
本技能提供两种分析模式,帮助理解和可视化代码库结构。
This skill provides two analysis modes to help understand and visualize codebase structures.
分析模式
Analysis Modes
模式一:系统架构分析
Mode 1: System Architecture Analysis
从宏观层面分析项目,生成整体架构视图。
分析步骤:
-
识别项目类型和技术栈
- 检查配置文件:,
package.json,pyproject.toml,Cargo.toml,go.mod等pom.xml - 识别框架:React, Vue, Django, FastAPI, Spring Boot 等
- 识别构建工具和依赖管理器
- 检查配置文件:
-
分析目录结构
- 使用 Glob 扫描主要目录
- 识别分层模式:controllers, services, models, utils 等
- 标注入口文件和配置文件
-
提取核心模块
- 识别主要功能模块
- 分析模块间的依赖关系
- 识别外部服务依赖(数据库、缓存、消息队列等)
-
生成架构图
输出格式(Mermaid C4 架构图):
mermaid
graph TB
subgraph 表示层["表示层 (Presentation)"]
UI[用户界面]
API[API 网关]
end
subgraph 业务层["业务层 (Business)"]
Service1[服务模块1]
Service2[服务模块2]
end
subgraph 数据层["数据层 (Data)"]
DB[(数据库)]
Cache[(缓存)]
end
UI --> API
API --> Service1
API --> Service2
Service1 --> DB
Service2 --> Cache架构图模板选择:
- 分层架构:适用于传统 MVC、三层架构项目
- 微服务架构:适用于多服务、分布式系统
- 前后端分离:适用于 SPA + API 项目
- 单体应用:适用于小型项目
Analyze the project from a macro perspective and generate an overall architecture view.
Analysis Steps:
-
Identify Project Type and Tech Stack
- Check configuration files: ,
package.json,pyproject.toml,Cargo.toml,go.mod, etc.pom.xml - Identify frameworks: React, Vue, Django, FastAPI, Spring Boot, etc.
- Identify build tools and dependency managers
- Check configuration files:
-
Analyze Directory Structure
- Scan main directories using Glob
- Identify layered patterns: controllers, services, models, utils, etc.
- Mark entry files and configuration files
-
Extract Core Modules
- Identify main functional modules
- Analyze dependency relationships between modules
- Identify external service dependencies (databases, caches, message queues, etc.)
-
Generate Architecture Diagram
Output Format (Mermaid C4 Architecture Diagram):
mermaid
graph TB
subgraph 表示层["表示层 (Presentation)"]
UI[用户界面]
API[API 网关]
end
subgraph 业务层["业务层 (Business)"]
Service1[服务模块1]
Service2[服务模块2]
end
subgraph 数据层["数据层 (Data)"]
DB[(数据库)]
Cache[(缓存)]
end
UI --> API
API --> Service1
API --> Service2
Service1 --> DB
Service2 --> CacheArchitecture Diagram Template Options:
- Layered Architecture: Suitable for traditional MVC, three-tier architecture projects
- Microservices Architecture: Suitable for multi-service, distributed systems
- Frontend-Backend Separation: Suitable for SPA + API projects
- Monolithic Application: Suitable for small-scale projects
模式二:模块数据流分析
Mode 2: Module Data Flow Analysis
深入分析特定模块或功能的数据流转过程。
分析步骤:
-
确定分析目标
- 明确要分析的功能或模块
- 识别入口点(API 端点、事件处理器、命令入口)
-
追踪代码调用链
- 从入口点开始追踪函数调用
- 记录数据在各层之间的转换
- 标注关键的数据处理节点
-
识别数据模型
- 分析输入数据结构
- 追踪数据变换过程
- 记录输出数据结构
-
生成时序图和数据流图
时序图输出格式(Mermaid Sequence Diagram):
mermaid
sequenceDiagram
participant C as 客户端
participant A as API层
participant S as 服务层
participant D as 数据层
C->>A: 发送请求
A->>A: 参数验证
A->>S: 调用业务逻辑
S->>D: 查询数据
D-->>S: 返回数据
S->>S: 业务处理
S-->>A: 返回结果
A-->>C: 响应结果数据流图输出格式(Mermaid Flowchart):
mermaid
flowchart LR
subgraph 输入["输入数据"]
I1[请求参数]
I2[用户凭证]
end
subgraph 处理["处理过程"]
P1[验证] --> P2[转换]
P2 --> P3[业务逻辑]
P3 --> P4[持久化]
end
subgraph 输出["输出数据"]
O1[响应结果]
O2[事件通知]
end
I1 --> P1
I2 --> P1
P4 --> O1
P3 --> O2In-depth analysis of data flow processes for specific modules or functions.
Analysis Steps:
-
Define Analysis Objectives
- Clarify the specific module or function to analyze
- Identify entry points (API endpoints, event handlers, command entries)
-
Trace Code Call Chains
- Track function calls starting from the entry point
- Record data transformations between layers
- Mark key data processing nodes
-
Identify Data Models
- Analyze input data structures
- Trace data transformation processes
- Record output data structures
-
Generate Sequence Diagrams and Data Flow Diagrams
Sequence Diagram Output Format (Mermaid Sequence Diagram):
mermaid
sequenceDiagram
participant C as 客户端
participant A as API层
participant S as 服务层
participant D as 数据层
C->>A: 发送请求
A->>A: 参数验证
A->>S: 调用业务逻辑
S->>D: 查询数据
D-->>S: 返回数据
S->>S: 业务处理
S-->>A: 返回结果
A-->>C: 响应结果Data Flow Diagram Output Format (Mermaid Flowchart):
mermaid
flowchart LR
subgraph 输入["输入数据"]
I1[请求参数]
I2[用户凭证]
end
subgraph 处理["处理过程"]
P1[验证] --> P2[转换]
P2 --> P3[业务逻辑]
P3 --> P4[持久化]
end
subgraph 输出["输出数据"]
O1[响应结果]
O2[事件通知]
end
I1 --> P1
I2 --> P1
P4 --> O1
P3 --> O2使用指南
Usage Guide
执行系统架构分析
Perform System Architecture Analysis
- 使用 Glob 扫描项目根目录,识别配置文件
- 分析目录结构,识别主要模块
- 使用 Grep 搜索 import/require 语句分析依赖
- 综合分析后生成 Mermaid 架构图
- 用中文标注各模块的职责
- 使用 编码脚本为每个 Mermaid 图生成在线预览链接
mermaid-live-preview
- Scan the project root directory using Glob to identify configuration files
- Analyze directory structure to identify main modules
- Use Grep to search import/require statements for dependency analysis
- Generate Mermaid architecture diagram after comprehensive analysis
- Annotate the responsibilities of each module in Chinese
- Use the scripting tool to generate online preview links for each Mermaid diagram
mermaid-live-preview
执行模块数据流分析
Perform Module Data Flow Analysis
- 确认用户想分析的具体模块或功能
- 定位入口文件和入口函数
- 逐层追踪函数调用,使用 Read 工具查看代码
- 记录每个步骤的数据变化
- 生成时序图和数据流图
- 用中文描述关键数据流转节点
- 使用 编码脚本为每个 Mermaid 图生成在线预览链接
mermaid-live-preview
- Confirm the specific module or function the user wants to analyze
- Locate entry files and entry functions
- Track function calls layer by layer, using the Read tool to view code
- Record data changes at each step
- Generate sequence diagrams and data flow diagrams
- Describe key data flow nodes in Chinese
- Use the scripting tool to generate online preview links for each Mermaid diagram
mermaid-live-preview
输出规范
Output Specifications
架构分析报告结构
Architecture Analysis Report Structure
markdown
undefinedmarkdown
undefined项目概述
Project Overview
- 项目名称
- 技术栈
- 项目类型
- Project Name
- Tech Stack
- Project Type
目录结构
Directory Structure
- 主要目录说明
- Main Directory Explanations
架构图
Architecture Diagram
[Mermaid 图]
[Mermaid Diagram]
核心模块说明
Core Module Explanations
| 模块名称 | 职责 | 依赖 |
|---|---|---|
| ... | ... | ... |
| Module Name | Responsibility | Dependencies |
|---|---|---|
| ... | ... | ... |
外部依赖
External Dependencies
- 数据库
- 第三方服务
undefined- Databases
- Third-party Services
undefined数据流分析报告结构
Data Flow Analysis Report Structure
markdown
undefinedmarkdown
undefined分析目标
Analysis Objectives
- 功能/模块名称
- 入口点
- Feature/Module Name
- Entry Points
时序图
Sequence Diagram
[Mermaid 时序图]
[Mermaid Sequence Diagram]
数据流图
Data Flow Diagram
[Mermaid 流程图]
[Mermaid Flowchart]
关键节点说明
Key Node Explanations
| 节点 | 文件位置 | 数据变换 |
|---|---|---|
| ... | ... | ... |
| Node | File Location | Data Transformation |
|---|---|---|
| ... | ... | ... |
数据模型
Data Models
- 输入结构
- 输出结构
---- Input Structure
- Output Structure
---文档输出流程
Document Output Process
分析完成后,将结果保存到项目的 目录。
docs/After analysis, save the results to the project's directory.
docs/输出步骤
Output Steps
-
检查 docs 目录
- 如果 目录不存在,创建该目录
docs/ - 检查是否有现有的架构文档,避免覆盖
- 如果
-
确定文件名
- 架构分析:
docs/architecture.md - 数据流分析:
docs/dataflow-{模块名}.md - 如用户指定文件名,使用用户指定的名称
- 架构分析:
-
写入文档
- 使用 Write 工具将分析报告写入目标文件
- 文档头部添加生成时间和分析范围说明
-
生成在线预览链接
- 对每个生成的 Mermaid 图表,使用 skill 的编码脚本生成在线预览链接:
mermaid-live-previewbashpython3 <skills-root>/skills/mermaid-live-preview/scripts/encode.py "<mermaid代码>" - 将输出的 Edit 和 View 链接附加在对应 Mermaid 代码块之后
- 格式示例:
markdown
[在线编辑](https://mermaid.live/edit#pako:...) | [在线预览](https://mermaid.live/view#pako:...)
- 对每个生成的 Mermaid 图表,使用
-
确认输出
- 告知用户文档已保存的路径
- 附带在线预览链接,用户可直接点击查看图表
-
Check docs Directory
- Create the directory if it does not exist
docs/ - Check for existing architecture documents to avoid overwriting
- Create the
-
Determine File Names
- Architecture analysis:
docs/architecture.md - Data flow analysis:
docs/dataflow-{module-name}.md - Use user-specified file names if provided
- Architecture analysis:
-
Write Documents
- Use the Write tool to save the analysis report to the target file
- Add generation time and analysis scope notes at the top of the document
-
Generate Online Preview Links
- For each generated Mermaid diagram, use the script from the
encode.pyskill to generate online preview links:mermaid-live-previewbashpython3 <skills-root>/skills/mermaid-live-preview/scripts/encode.py "<mermaid-code>" - Append the output Edit and View links after the corresponding Mermaid code block
- Format example:
markdown
[Edit Online](https://mermaid.live/edit#pako:...) | [View Online](https://mermaid.live/view#pako:...)
- For each generated Mermaid diagram, use the
-
Confirm Output
- Inform the user of the saved document path
- Include online preview links for direct access to the charts
文档模板
Document Templates
架构文档 ():
docs/architecture.mdmarkdown
undefinedArchitecture Document ():
docs/architecture.mdmarkdown
undefined项目架构文档
Project Architecture Document
生成时间:YYYY-MM-DD 分析范围:全项目
Generation Time: YYYY-MM-DD Analysis Scope: Entire Project
项目概述
Project Overview
...
...
架构图
Architecture Diagram
...
在线编辑 | 在线预览
...
Edit Online | View Online
模块说明
Module Explanations
...
**数据流文档 (`docs/dataflow-{模块名}.md`):**
```markdown...
**Data Flow Document (`docs/dataflow-{module-name}.md`):**
```markdown{模块名} 数据流分析
{Module Name} Data Flow Analysis
生成时间:YYYY-MM-DD 分析模块:{模块路径}
Generation Time: YYYY-MM-DD Analyzed Module: {Module Path}
时序图
Sequence Diagram
...
在线编辑 | 在线预览
...
Edit Online | View Online
数据流图
Data Flow Diagram
...
在线编辑 | 在线预览
...
Edit Online | View Online
节点说明
Node Explanations
...
undefined...
undefined文件命名规范
File Naming Specifications
| 分析类型 | 文件名格式 | 示例 |
|---|---|---|
| 系统架构 | | |
| 模块架构 | | |
| 数据流 | | |
| 时序图 | | |
| Analysis Type | File Name Format | Example |
|---|---|---|
| System Architecture | | |
| Module Architecture | | |
| Data Flow | | |
| Sequence Diagram | | |
最佳实践
Best Practices
- 优先使用项目已有的文档(README、API 文档)作为参考
- 架构图保持简洁,避免过于细节
- 时序图聚焦主流程,分支逻辑可单独说明
- 所有图表使用中文标注
- 为每个模块提供简短的职责说明
- 每个 Mermaid 图表输出后,必须附带在线预览链接(使用 skill 的
mermaid-live-preview)encode.py - 分析完成后始终将结果保存到 目录
docs/ - 更新现有文档时保留历史版本或做增量更新
- Prioritize using existing project documents (README, API docs) as references
- Keep architecture diagrams concise and avoid excessive details
- Focus sequence diagrams on main processes; branch logic can be explained separately
- Use Chinese annotations for all diagrams
- Provide brief responsibility descriptions for each module
- Must include online preview links for each Mermaid diagram (using from the
encode.pyskill)mermaid-live-preview - Always save analysis results to the directory after completion
docs/ - Retain historical versions or make incremental updates when modifying existing documents