依赖关系图生成器 dependency-graph-generator

依赖关系图生成器是一款用于分析软件代码架构的工具,能够自动扫描代码库,生成模块间的依赖关系可视化图谱。核心功能包括循环依赖检测、耦合度指标计算(传入耦合、传出耦合)、不稳定性分析,并支持导出为Graphviz、D3、Mermaid等多种格式。适用于微服务解耦、代码重构规划、系统迁移策略制定等场景,帮助开发者和架构师理解代码结构、识别设计缺陷、优化系统架构。

架构设计 0 次安装 0 次浏览 更新于 2/26/2026

名称: 依赖关系图生成器 描述: 生成模块依赖关系图,具备循环依赖检测和耦合度指标计算功能 允许使用的工具:

  • Bash
  • Read
  • Write
  • Glob
  • Grep

依赖关系图生成器技能

概述

生成模块依赖关系图,具备循环依赖识别、耦合度指标计算功能,并支持以Graphviz或D3格式输出可视化结果。

功能

  • 生成模块依赖关系图
  • 识别循环依赖
  • 计算耦合度指标(传入耦合、传出耦合)
  • 计算不稳定性指标
  • 可视化依赖关系(Graphviz、D3)
  • 包/模块级别分析
  • 外部依赖跟踪

目标流程

  • 微服务解耦
  • 重构规划
  • 迁移策略

输入模式

{
  "type": "object",
  "required": ["entryPoints"],
  "properties": {
    "entryPoints": {
      "type": "array",
      "items": { "type": "string" },
      "description": "入口点文件或目录"
    },
    "outputFormat": {
      "type": "string",
      "enum": ["dot", "json", "d3", "mermaid"],
      "default": "dot"
    },
    "outputPath": {
      "type": "string",
      "description": "输出文件路径"
    },
    "options": {
      "type": "object",
      "properties": {
        "depth": {
          "type": "number",
          "default": -1,
          "description": "最大深度(-1表示无限制)"
        },
        "includeExternal": {
          "type": "boolean",
          "default": false
        },
        "groupByPackage": {
          "type": "boolean",
          "default": true
        },
        "detectCircular": {
          "type": "boolean",
          "default": true
        }
      }
    }
  }
}

输出模式

{
  "type": "object",
  "properties": {
    "graph": {
      "type": "object",
      "properties": {
        "nodes": { "type": "array" },
        "edges": { "type": "array" }
      }
    },
    "circularDependencies": {
      "type": "array",
      "items": {
        "type": "array",
        "items": { "type": "string" }
      }
    },
    "metrics": {
      "type": "object",
      "properties": {
        "totalModules": { "type": "number" },
        "totalDependencies": { "type": "number" },
        "averageCoupling": { "type": "number" }
      }
    },
    "outputPath": {
      "type": "string"
    }
  }
}

使用示例

{
  kind: 'skill',
  skill: {
    name: 'dependency-graph-generator',
    context: {
      entryPoints: ['src/index.ts'],
      outputFormat: 'dot',
      outputPath: 'docs/dependencies.dot',
      options: {
        groupByPackage: true,
        detectCircular: true
      }
    }
  }
}