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

从宏观层面分析项目,生成整体架构视图。
分析步骤:
  1. 识别项目类型和技术栈
    • 检查配置文件:
      package.json
      ,
      pyproject.toml
      ,
      Cargo.toml
      ,
      go.mod
      ,
      pom.xml
    • 识别框架:React, Vue, Django, FastAPI, Spring Boot 等
    • 识别构建工具和依赖管理器
  2. 分析目录结构
    • 使用 Glob 扫描主要目录
    • 识别分层模式:controllers, services, models, utils 等
    • 标注入口文件和配置文件
  3. 提取核心模块
    • 识别主要功能模块
    • 分析模块间的依赖关系
    • 识别外部服务依赖(数据库、缓存、消息队列等)
  4. 生成架构图
输出格式(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:
  1. Identify Project Type and Tech Stack
    • Check configuration files:
      package.json
      ,
      pyproject.toml
      ,
      Cargo.toml
      ,
      go.mod
      ,
      pom.xml
      , etc.
    • Identify frameworks: React, Vue, Django, FastAPI, Spring Boot, etc.
    • Identify build tools and dependency managers
  2. Analyze Directory Structure
    • Scan main directories using Glob
    • Identify layered patterns: controllers, services, models, utils, etc.
    • Mark entry files and configuration files
  3. Extract Core Modules
    • Identify main functional modules
    • Analyze dependency relationships between modules
    • Identify external service dependencies (databases, caches, message queues, etc.)
  4. 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 --> Cache
Architecture 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

深入分析特定模块或功能的数据流转过程。
分析步骤:
  1. 确定分析目标
    • 明确要分析的功能或模块
    • 识别入口点(API 端点、事件处理器、命令入口)
  2. 追踪代码调用链
    • 从入口点开始追踪函数调用
    • 记录数据在各层之间的转换
    • 标注关键的数据处理节点
  3. 识别数据模型
    • 分析输入数据结构
    • 追踪数据变换过程
    • 记录输出数据结构
  4. 生成时序图和数据流图
时序图输出格式(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 --> O2

In-depth analysis of data flow processes for specific modules or functions.
Analysis Steps:
  1. Define Analysis Objectives
    • Clarify the specific module or function to analyze
    • Identify entry points (API endpoints, event handlers, command entries)
  2. Trace Code Call Chains
    • Track function calls starting from the entry point
    • Record data transformations between layers
    • Mark key data processing nodes
  3. Identify Data Models
    • Analyze input data structures
    • Trace data transformation processes
    • Record output data structures
  4. 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

  1. 使用 Glob 扫描项目根目录,识别配置文件
  2. 分析目录结构,识别主要模块
  3. 使用 Grep 搜索 import/require 语句分析依赖
  4. 综合分析后生成 Mermaid 架构图
  5. 用中文标注各模块的职责
  6. 使用
    mermaid-live-preview
    编码脚本为每个 Mermaid 图生成在线预览链接
  1. Scan the project root directory using Glob to identify configuration files
  2. Analyze directory structure to identify main modules
  3. Use Grep to search import/require statements for dependency analysis
  4. Generate Mermaid architecture diagram after comprehensive analysis
  5. Annotate the responsibilities of each module in Chinese
  6. Use the
    mermaid-live-preview
    scripting tool to generate online preview links for each Mermaid diagram

执行模块数据流分析

Perform Module Data Flow Analysis

  1. 确认用户想分析的具体模块或功能
  2. 定位入口文件和入口函数
  3. 逐层追踪函数调用,使用 Read 工具查看代码
  4. 记录每个步骤的数据变化
  5. 生成时序图和数据流图
  6. 用中文描述关键数据流转节点
  7. 使用
    mermaid-live-preview
    编码脚本为每个 Mermaid 图生成在线预览链接

  1. Confirm the specific module or function the user wants to analyze
  2. Locate entry files and entry functions
  3. Track function calls layer by layer, using the Read tool to view code
  4. Record data changes at each step
  5. Generate sequence diagrams and data flow diagrams
  6. Describe key data flow nodes in Chinese
  7. Use the
    mermaid-live-preview
    scripting tool to generate online preview links for each Mermaid diagram

输出规范

Output Specifications

架构分析报告结构

Architecture Analysis Report Structure

markdown
undefined
markdown
undefined

项目概述

Project Overview

  • 项目名称
  • 技术栈
  • 项目类型
  • Project Name
  • Tech Stack
  • Project Type

目录结构

Directory Structure

  • 主要目录说明
  • Main Directory Explanations

架构图

Architecture Diagram

[Mermaid 图]
[Mermaid Diagram]

核心模块说明

Core Module Explanations

模块名称职责依赖
.........
Module NameResponsibilityDependencies
.........

外部依赖

External Dependencies

  • 数据库
  • 第三方服务
undefined
  • Databases
  • Third-party Services
undefined

数据流分析报告结构

Data Flow Analysis Report Structure

markdown
undefined
markdown
undefined

分析目标

Analysis Objectives

  • 功能/模块名称
  • 入口点
  • Feature/Module Name
  • Entry Points

时序图

Sequence Diagram

[Mermaid 时序图]
[Mermaid Sequence Diagram]

数据流图

Data Flow Diagram

[Mermaid 流程图]
[Mermaid Flowchart]

关键节点说明

Key Node Explanations

节点文件位置数据变换
.........
NodeFile LocationData Transformation
.........

数据模型

Data Models

  • 输入结构
  • 输出结构

---
  • Input Structure
  • Output Structure

---

文档输出流程

Document Output Process

分析完成后,将结果保存到项目的
docs/
目录。
After analysis, save the results to the project's
docs/
directory.

输出步骤

Output Steps

  1. 检查 docs 目录
    • 如果
      docs/
      目录不存在,创建该目录
    • 检查是否有现有的架构文档,避免覆盖
  2. 确定文件名
    • 架构分析:
      docs/architecture.md
    • 数据流分析:
      docs/dataflow-{模块名}.md
    • 如用户指定文件名,使用用户指定的名称
  3. 写入文档
    • 使用 Write 工具将分析报告写入目标文件
    • 文档头部添加生成时间和分析范围说明
  4. 生成在线预览链接
    • 对每个生成的 Mermaid 图表,使用
      mermaid-live-preview
      skill 的编码脚本生成在线预览链接:
      bash
      python3 <skills-root>/skills/mermaid-live-preview/scripts/encode.py "<mermaid代码>"
    • 将输出的 Edit 和 View 链接附加在对应 Mermaid 代码块之后
    • 格式示例:
      markdown
      [在线编辑](https://mermaid.live/edit#pako:...) | [在线预览](https://mermaid.live/view#pako:...)
  5. 确认输出
    • 告知用户文档已保存的路径
    • 附带在线预览链接,用户可直接点击查看图表
  1. Check docs Directory
    • Create the
      docs/
      directory if it does not exist
    • Check for existing architecture documents to avoid overwriting
  2. Determine File Names
    • Architecture analysis:
      docs/architecture.md
    • Data flow analysis:
      docs/dataflow-{module-name}.md
    • Use user-specified file names if provided
  3. 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
  4. Generate Online Preview Links
    • For each generated Mermaid diagram, use the
      encode.py
      script from the
      mermaid-live-preview
      skill to generate online preview links:
      bash
      python3 <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:...)
  5. Confirm Output
    • Inform the user of the saved document path
    • Include online preview links for direct access to the charts

文档模板

Document Templates

架构文档 (
docs/architecture.md
):
markdown
undefined
Architecture Document (
docs/architecture.md
):
markdown
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

分析类型文件名格式示例
系统架构
architecture.md
docs/architecture.md
模块架构
architecture-{模块}.md
docs/architecture-auth.md
数据流
dataflow-{功能}.md
docs/dataflow-login.md
时序图
sequence-{流程}.md
docs/sequence-order-create.md

Analysis TypeFile Name FormatExample
System Architecture
architecture.md
docs/architecture.md
Module Architecture
architecture-{module}.md
docs/architecture-auth.md
Data Flow
dataflow-{feature}.md
docs/dataflow-login.md
Sequence Diagram
sequence-{process}.md
docs/sequence-order-create.md

最佳实践

Best Practices

  • 优先使用项目已有的文档(README、API 文档)作为参考
  • 架构图保持简洁,避免过于细节
  • 时序图聚焦主流程,分支逻辑可单独说明
  • 所有图表使用中文标注
  • 为每个模块提供简短的职责说明
  • 每个 Mermaid 图表输出后,必须附带在线预览链接(使用
    mermaid-live-preview
    skill 的
    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
    encode.py
    from the
    mermaid-live-preview
    skill)
  • Always save analysis results to the
    docs/
    directory after completion
  • Retain historical versions or make incremental updates when modifying existing documents