---
sync_policy: engine_only
---
/**
 * dependency-cruiser 配置 — 架构依赖约束（SoloForge 脚手架生成）
 *
 * 用途: 在构建/CI 阶段自动拦截架构退化（循环依赖、跨层依赖、反向依赖），
 *       作为「架构适应度函数」配合 SoloForge gate 的 external_command 执行器实现硬约束。
 * 文档: https://github.com/sverweij/dependency-cruiser
 * 运行: npx depcruise --config .dependency-cruiser.config.js src
 * 退出码: 0 = 无违规；非0 = 检测到违规（SoloForge gate 据此 hard_fail）
 *
 * 注: 本配置不含 Handlebars 变量（项目级通用），可按需补充业务包路径规则。
 */
module.exports = {
  forbidden: [
    {
      name: "no-circular",
      severity: "error",
      comment: "禁止循环依赖——会导致初始化顺序问题与编译错误",
      from: {},
      to: { circular: true },
    },
    {
      name: "no-controller-to-dao",
      severity: "error",
      comment: "Controller/页面/路由层禁止直接访问数据层（必须经 Service）",
      from: { path: "(controller|api|pages|routes)" },
      to: { path: "(mapper|dao|repository|entity)$" },
    },
    {
      name: "no-utils-to-feature",
      severity: "error",
      comment: "通用/工具层禁止反向依赖业务层",
      from: { path: "(utils|common|shared|lib)" },
      to: { pathNot: "(utils|common|shared|lib)" },
    },
    {
      name: "no-orphan",
      severity: "warn",
      comment: "检测未被引用的模块（疑似死代码）",
      from: { orphan: true, pathNot: "(^|/)index\\.[jt]sx?$" },
      to: {},
    },
  ],
  options: {
    doNotFollow: "node_modules",
    tsPreCompilationDeps: true,
    enhancedResolveOptions: { exportsFields: ["exports"] },
    reporterOptions: { text: { highlightFocused: true } },
  },
};
