technical-debt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTechnical Debt
技术债务
Technical debt audit and prioritization framework for PHP/Laravel (MySQL) and Node/TypeScript/React projects. Contains 42 rules across 10 categories covering code, security, design, dependency, test, performance, data, documentation, infrastructure, and process debt. Produces a ranked ledger (effort × impact) so teams know what to fix first, not just what's broken. Supports both coding reference and audit mode with PASS/FAIL/N/A output.
针对PHP/Laravel(MySQL)和Node/TypeScript/React项目的技术债务审计与优先级排序框架。涵盖代码、安全、设计、依赖、测试、性能、数据、文档、基础设施和流程债务10个类别,包含42条规则。生成基于「工作量×影响」的排序清单,让团队不仅知道哪里有问题,更清楚优先修复什么。支持编码参考和审计模式,输出结果分为PASS/FAIL/N/A三类。
Metadata
元数据
- Version: 1.0.0
- Scope: PHP / Laravel (MySQL) + Node / TypeScript / React
- Rule Count: 42 rules across 10 categories
- License: MIT
- **版本:**1.0.0
- **适用范围:**PHP / Laravel(MySQL) + Node / TypeScript / React
- **规则数量:**10个类别共42条规则
- **许可证:**MIT
How to Audit
审计流程
When the user asks to "audit technical debt", "find tech debt", or "what should we refactor first" — run the checklist below against their codebase and produce a ranked debt ledger.
当用户要求“audit technical debt”“find tech debt”或“what should we refactor first”时,按照以下清单对其代码库进行审计,并生成排序后的债务清单。
Audit Step 1: Determine Scope
审计步骤1:确定范围
- If arguments provided (): audit only those paths or modules
$ARGUMENTS - If no arguments: audit the entire repository starting from the root
- 若提供参数():仅审计指定路径或模块
$ARGUMENTS - 若无参数:从根目录开始审计整个代码库
Audit Step 2: Detect Project Stack
审计步骤2:检测项目技术栈
Inspect and to determine which of the supported stacks (PHP/Laravel, Node/TypeScript/React, or both) is in use. Tooling commands (, , , , , etc.) are chosen based on this detection.
composer.jsonpackage.jsoncomposer outdatednpm outdatedphpstaneslintknip检查和,确定使用的是哪种支持的技术栈(PHP/Laravel、Node/TypeScript/React,或两者兼有)。根据检测结果选择对应的工具命令(、、、、等)。
composer.jsonpackage.jsoncomposer outdatednpm outdatedphpstaneslintknipAudit Step 3: Run Debt Checklist
审计步骤3:执行债务检查清单
Work through every item below. For each, output:
- PASS — brief confirmation of what was verified
- FAIL — exact (or command output), description of the debt, effort estimate (S/M/L), and impact (LOW/MED/HIGH/CRITICAL)
file:line - N/A — if the check does not apply to this project
逐一检查以下各项,针对每项输出:
- PASS — 简要确认已验证内容
- FAIL — 精确的(或命令输出)、债务描述、工作量估算(S/M/L)和影响程度(LOW/MED/HIGH/CRITICAL)
file:line - N/A — 若该检查不适用于当前项目
Code Debt
代码债务
- No duplicated blocks > 30 lines across files
- No function exceeds 50 lines or cyclomatic complexity > 10
- No class exceeds 300 lines or has > 15 public methods (god class)
- No unreachable code, unused exports, or commented-out blocks left in source
- No magic numbers or unexplained string literals in business logic
- No function exceeds 4 parameters (use a parameter object)
- 跨文件无超过30行的重复代码块
- 函数行数不超过50行,圈复杂度不超过10
- 类行数不超过300行,公共方法不超过15个(避免上帝类)
- 源代码中无不可达代码、未使用的导出或注释掉的代码块
- 业务逻辑中无魔法数字或未解释的字符串字面量
- 函数参数不超过4个(使用参数对象替代)
Security Debt
安全债务
- No secrets, API keys, or credentials committed to source (or git history)
- Every public endpoint validates input via a schema / FormRequest / DTO
- Passwords hashed with bcrypt or argon2id; no MD5/SHA-1
- Sessions have a bounded lifetime; auth-sensitive endpoints rate-limited
- Security headers present (CSP, HSTS, X-Content-Type-Options, Referrer-Policy)
- Authorization (not just authentication) enforced on every protected route
- 源代码(或git历史)中未提交密钥、API密钥或凭证
- 每个公开端点通过Schema/FormRequest/DTO验证输入
- 密码使用bcrypt或argon2id哈希;未使用MD5/SHA-1
- 会话有生命周期限制;敏感认证端点已做限流
- 存在安全头(CSP、HSTS、X-Content-Type-Options、Referrer-Policy)
- 每个受保护路由均强制执行授权(而非仅认证)
Design Debt
设计债务
- No circular dependencies between modules/packages
- Layers respect direction (UI → service → repository, never reversed)
- No "shotgun surgery" patterns (one change forcing edits in 5+ files)
- Abstractions hide implementation details (no leaking framework types across boundaries)
- 模块/包之间无循环依赖
- 分层结构遵循方向(UI → 服务 → 仓库,不可反向)
- 无“霰弹式修改”模式(一处变更需修改5个以上文件)
- 抽象层隐藏实现细节(框架类型不会跨边界泄露)
Dependency Debt
依赖债务
- No dependencies more than 2 major versions behind
- No abandoned/unmaintained packages (no release in > 24 months)
- No known CVEs reported by /
npm auditat HIGH or CRITICALcomposer audit - No unused dependencies in /
package.jsoncomposer.json
- 无落后2个以上主版本的依赖
- 无已废弃/无人维护的包(超过24个月未发布新版本)
- /
npm audit未报告HIGH或CRITICAL级别的已知CVEcomposer audit - /
package.json中无未使用的依赖composer.json
Test Debt
测试债务
- Critical paths have integration test coverage
- No skipped/disabled tests without linked issue or removal date
- No known flaky tests left in main branch
- Test suite runs in under 10 minutes (or has explicit budget documented)
- 关键路径有集成测试覆盖
- 无未关联问题或移除日期的跳过/禁用测试
- 主分支中无已知的不稳定测试
- 测试套件运行时间不超过10分钟(或已记录明确的时间预算)
Performance Debt
性能债务
- No N+1 query patterns on list endpoints (query count constant per request)
- No list endpoint returns an unbounded result set (pagination present)
- Frontend initial bundle within budget (~200 KB gzip); route-level code splitting in place
- Expensive read paths (aggregations, external APIs, static configs) are cached at a sensible layer
- 列表端点无N+1查询模式(每个请求的查询次数恒定)
- 列表端点无无限制结果集(已实现分页)
- 前端初始包大小在预算内(约200 KB gzip);已实现路由级代码分割
- 高开销读取路径(聚合、外部API、静态配置)已在合理层级缓存
Data Debt
数据债务
- Migrations are the only source of schema changes; production matches migration history
- All foreign-key and frequently-queried columns are indexed
- No orphaned child records; FK constraints enforced
- 迁移是架构变更的唯一来源;生产环境与迁移历史一致
- 所有外键和频繁查询的列均已建立索引
- 无孤立子记录;外键约束已强制执行
Documentation Debt
文档债务
- README reflects current setup and dev workflow
- No stale comments contradicting the code they describe
- Public APIs / exported modules have docblocks or type hints
- README反映当前配置和开发流程
- 无与所描述代码矛盾的过时注释
- 公开API/导出模块有文档块或类型提示
Infrastructure Debt
基础设施债务
- Runtime versions (Node, PHP) are on supported (non-EOL) releases
- No deprecated framework APIs in use (e.g., Laravel deprecations)
Route::get() - Build runs cleanly with zero warnings
- Secrets stored in a manager (Vault / Doppler / cloud SM); no long-lived shared credentials
- Structured logs, error tracking, p95 latency dashboards, and SLO-based alerts in place
- 运行时版本(Node、PHP)为支持版本(非EOL)
- 未使用已废弃的框架API(如Laravel 弃用项)
Route::get() - 构建过程无警告
- 密钥存储在管理器中(Vault/Doppler/云密钥管理服务);无长期共享凭证
- 已部署结构化日志、错误追踪、p95延迟仪表盘和基于SLO的告警
Process Debt
流程债务
- No /
TODO/FIXMEcomments older than 6 months without owner or ticketHACK - No markers without a removal date or replacement
@deprecated - Debt is tracked somewhere visible (issue tracker label, debt register, ADR)
- Every path has an owner (CODEOWNERS file present and current)
- No feature flags at 100% rollout for more than 6 weeks without a removal plan
- 无超过6个月且无负责人或工单的/
TODO/FIXME注释HACK - 无未指定移除日期或替代方案的标记
@deprecated - 债务已在可见位置追踪(问题追踪器标签、债务登记册、ADR)
- 每个路径都有负责人(CODEOWNERS文件存在且为最新)
- 无100%发布超过6周且无移除计划的功能标志
Audit Step 4: Build the Debt Ledger
审计步骤4:生成债务清单
End the audit with a prioritized table:
undefined审计结束后输出优先级排序表:
undefinedTechnical Debt Ledger
Technical Debt Ledger
| # | Category | Item | File / Location | Effort | Impact | Priority |
|---|---|---|---|---|---|---|
| 1 | deps | jQuery 1.12 (8y old, 3 CVEs) | package.json:14 | L | CRITICAL | P0 |
| 2 | code | OrderService god class (820 lines) | app/Services/OrderService.php | M | HIGH | P1 |
| 3 | test | 12 disabled tests in auth/ | tests/Feature/Auth/* | S | HIGH | P1 |
| ... |
| # | Category | Item | File / Location | Effort | Impact | Priority |
|---|---|---|---|---|---|---|
| 1 | deps | jQuery 1.12 (8y old, 3 CVEs) | package.json:14 | L | CRITICAL | P0 |
| 2 | code | OrderService god class (820 lines) | app/Services/OrderService.php | M | HIGH | P1 |
| 3 | test | 12 disabled tests in auth/ | tests/Feature/Auth/* | S | HIGH | P1 |
| ... |
Summary
Summary
- PASS: X checks
- FAIL: Y checks
- N/A: Z checks
- Top 3 to pay down first: (list highest-priority items with rationale)
**Priority formula:** `P0 = CRITICAL impact`, `P1 = HIGH impact`, `P2 = MED`, `P3 = LOW`. Within a priority, sort by ascending effort (cheap wins first).
**Effort scale:**
- **S** = under a day
- **M** = 1–5 days
- **L** = more than a week (likely needs to be broken down)
---- PASS: X checks
- FAIL: Y checks
- N/A: Z checks
- Top 3 to pay down first: (list highest-priority items with rationale)
**优先级公式:**`P0 = CRITICAL影响`,`P1 = HIGH影响`,`P2 = MED`,`P3 = LOW`。同一优先级内按工作量升序排序(优先处理低成本事项)。
**工作量等级:**
- **S** = 1天以内
- **M** = 1–5天
- **L** = 超过1周(可能需要拆分)
---When to Apply
适用场景
Reference these guidelines when:
- Running a tech-debt audit on a codebase
- Planning a refactoring sprint or debt-paydown initiative
- Reviewing a PR that introduces shortcuts (and deciding whether to accept them)
- Building a debt register or backlog category in your issue tracker
- Justifying engineering investment to non-engineering stakeholders
- Onboarding to a new codebase and assessing its health
- Writing an ADR (architecture decision record) for a debt-related decision
在以下场景参考本指南:
- 对代码库进行技术债务审计
- 规划重构迭代或债务偿还计划
- 审查引入捷径的PR并决定是否接受
- 在问题追踪器中建立债务登记册或待办事项分类
- 向非技术干系人说明工程投入的合理性
- 加入新代码库并评估其健康状况
- 撰写与债务相关的架构决策记录(ADR)
Step 1: Detect Project Stack
步骤1:检测项目技术栈
Always detect the stack before running tooling. This skill targets PHP / Laravel (with MySQL) and Node / TypeScript / React projects; detection commands below assume one or both are present.
| Signal | Stack | Tooling |
|---|---|---|
| PHP / Laravel | |
| Node / JS / TS / React | |
| MySQL connection available | Database | |
| any repo | Secrets scan | |
If both stacks are present (e.g., Laravel + Inertia + React), run audits for each.
运行工具前务必先检测技术栈。本工具针对PHP / Laravel(搭配MySQL)和Node / TypeScript / React项目;以下检测命令假设存在其中一种或两种技术栈。
| 信号 | 技术栈 | 工具 |
|---|---|---|
存在 | PHP / Laravel | |
存在 | Node / JS / TS / React | |
| 可连接MySQL | 数据库 | |
| 任意代码库 | 密钥扫描 | |
若同时存在两种技术栈(如Laravel + Inertia + React),则分别对每种技术栈进行审计。
Rule Categories by Priority
规则分类优先级
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Code Debt | CRITICAL | |
| 2 | Security Debt | CRITICAL | |
| 3 | Design Debt | HIGH | |
| 4 | Dependency Debt | HIGH | |
| 5 | Test Debt | HIGH | |
| 6 | Performance Debt | HIGH | |
| 7 | Data Debt | HIGH | |
| 8 | Documentation Debt | MEDIUM | |
| 9 | Infrastructure Debt | MEDIUM | |
| 10 | Process Debt | MEDIUM | |
| 优先级 | 分类 | 影响程度 | 前缀 |
|---|---|---|---|
| 1 | 代码债务 | CRITICAL | |
| 2 | 安全债务 | CRITICAL | |
| 3 | 设计债务 | HIGH | |
| 4 | 依赖债务 | HIGH | |
| 5 | 测试债务 | HIGH | |
| 6 | 性能债务 | HIGH | |
| 7 | 数据债务 | HIGH | |
| 8 | 文档债务 | MEDIUM | |
| 9 | 基础设施债务 | MEDIUM | |
| 10 | 流程债务 | MEDIUM | |
Quick Reference
快速参考
1. Code Debt (CRITICAL)
1. 代码债务(CRITICAL)
- — Detect and consolidate duplicated logic
code-duplication - — Cyclomatic and cognitive complexity thresholds
code-complexity - — Function and method length limits
code-long-functions - — Class size and responsibility limits
code-god-classes - — Unused code, unreachable branches, commented blocks
code-dead-code - — Hardcoded literals in business logic
code-magic-numbers - — Functions with too many positional params
code-long-parameter-lists
- — 检测并整合重复逻辑
code-duplication - — 圈复杂度与认知复杂度阈值
code-complexity - — 函数与方法长度限制
code-long-functions - — 类大小与职责限制
code-god-classes - — 未使用代码、不可达分支、注释块
code-dead-code - — 业务逻辑中的硬编码字面量
code-magic-numbers - — 参数过多的函数
code-long-parameter-lists
2. Security Debt (CRITICAL)
2. 安全债务(CRITICAL)
- — API keys, passwords, tokens in source / history
security-secrets-in-code - — Endpoints accepting untrusted input without schemas
security-input-validation - — Outdated auth, missing MFA, missing security headers
security-auth-hardening
- — 源代码/历史中的API密钥、密码、令牌
security-secrets-in-code - — 接受不可信输入但未使用Schema的端点
security-input-validation - — 过时认证方式、缺少MFA、缺少安全头
security-auth-hardening
3. Design Debt (HIGH)
3. 设计债务(HIGH)
- — Excessive direct dependencies between modules
design-tight-coupling - — Cyclic imports / requires
design-circular-deps - — Framework types crossing layer boundaries
design-leaky-abstractions - — Changes that touch many files at once
design-shotgun-surgery
- — 模块间过度直接依赖
design-tight-coupling - — 循环导入/依赖
design-circular-deps - — 框架类型跨层边界泄露
design-leaky-abstractions - — 需要修改多个文件的变更
design-shotgun-surgery
4. Dependency Debt (HIGH)
4. 依赖债务(HIGH)
- — Major versions behind on dependencies
deps-outdated-versions - — Unmaintained / abandoned libraries
deps-abandoned-packages - — Known CVEs in installed dependencies
deps-security-advisories - — Declared but unused packages
deps-unused-deps
- — 落后主版本的依赖
deps-outdated-versions - — 已废弃/无人维护的库
deps-abandoned-packages - — 已安装依赖中的已知CVE
deps-security-advisories - — 已声明但未使用的包
deps-unused-deps
5. Test Debt (HIGH)
5. 测试债务(HIGH)
- — Critical paths without tests
test-coverage-gaps - — Tests with non-deterministic outcomes
test-flaky-tests - — Skipped tests left in the suite
test-disabled-tests - — Tests blocking fast feedback
test-slow-tests
- — 无测试覆盖的关键路径
test-coverage-gaps - — 结果不确定的测试
test-flaky-tests - — 套件中被跳过的测试
test-disabled-tests - — 阻碍快速反馈的测试
test-slow-tests
6. Performance Debt (HIGH)
6. 性能债务(HIGH)
- — Linear request → quadratic database load
perf-n-plus-one - — Unbounded result sets
perf-missing-pagination - — Heavy / unsplit frontend bundles
perf-bundle-bloat - — Missing cache layers on read-heavy paths
perf-no-caching
- — 请求→数据库负载呈线性增长的查询
perf-n-plus-one - — 无限制结果集
perf-missing-pagination - — 过大/未拆分的前端包
perf-bundle-bloat - — 高读取路径缺少缓存层
perf-no-caching
7. Data Debt (HIGH)
7. 数据债务(HIGH)
- — Production schema diverges from migrations
data-schema-drift - — Hot queries doing sequential scans
data-missing-indexes - — Referential integrity gaps
data-orphaned-records
- — 生产环境架构与迁移历史不一致
data-schema-drift - — 热点查询执行全表扫描
data-missing-indexes - — 引用完整性缺失
data-orphaned-records
8. Documentation Debt (MEDIUM)
8. 文档债务(MEDIUM)
- — Comments contradicting current behavior
docs-stale-comments - — README/architecture docs out of date
docs-outdated-architecture - — Public APIs without docblocks or types
docs-undocumented-api
- — 与当前行为矛盾的注释
docs-stale-comments - — README/架构文档过时
docs-outdated-architecture - — 无文档块或类型提示的公开API
docs-undocumented-api
9. Infrastructure Debt (MEDIUM)
9. 基础设施债务(MEDIUM)
- — EOL or near-EOL language/runtime versions
infra-runtime-versions - — Framework deprecations still in use
infra-deprecated-apis - — Build/compile warnings ignored
infra-build-warnings - — Long-lived credentials, plain env files, leaked logs
infra-secrets-management - — Missing logs, metrics, traces, alerts, or SLOs
infra-monitoring-gaps
- — EOL或即将EOL的语言/运行时版本
infra-runtime-versions - — 仍在使用的框架弃用API
infra-deprecated-apis - — 被忽略的构建/编译警告
infra-build-warnings - — 长期凭证、明文环境文件、日志泄露
infra-secrets-management - — 缺少日志、指标、追踪、告警或SLO
infra-monitoring-gaps
10. Process Debt (MEDIUM)
10. 流程债务(MEDIUM)
- — Aging TODO/FIXME/HACK comments
process-todo-fixme-aging - —
process-deprecated-markerswithout removal plan@deprecated - — Debt visible in a register / backlog
process-debt-tracking - — Code without an owning team (CODEOWNERS)
process-ownership-gaps - — Stale feature flags polluting code paths
process-feature-flags-lingering
- — 过期的TODO/FIXME/HACK注释
process-todo-fixme-aging - — 无移除计划的
process-deprecated-markers标记@deprecated - — 在登记册/待办事项中可见的债务
process-debt-tracking - — 无负责团队的代码(CODEOWNERS)
process-ownership-gaps - — 污染代码路径的过时功能标志
process-feature-flags-lingering
Essential Patterns
核心模式
Debt Ledger Output Format
债务清单输出格式
| # | Category | Item | Location | Effort | Impact | Priority |
|---|----------|-------------------------------|-----------------------|--------|----------|----------|
| 1 | deps | guzzle 6.x (5y behind) | composer.json:18 | M | HIGH | P1 |
| 2 | code | InvoiceService dup logic | app/Services/Invoice* | S | MEDIUM | P2 |
| 3 | test | 8 skipped tests in checkout/ | tests/Feature/Checkout| S | HIGH | P1 || # | Category | Item | Location | Effort | Impact | Priority |
|---|----------|-------------------------------|-----------------------|--------|----------|----------|
| 1 | deps | guzzle 6.x (5y behind) | composer.json:18 | M | HIGH | P1 |
| 2 | code | InvoiceService dup logic | app/Services/Invoice* | S | MEDIUM | P2 |
| 3 | test | 8 skipped tests in checkout/ | tests/Feature/Checkout| S | HIGH | P1 |Effort × Impact Prioritization
工作量×影响优先级排序
LOW MEDIUM HIGH CRITICAL
S (<1d) → P3 P2 P1 P0
M (1-5d) → P3 P2 P1 P0
L (>1w) → P3 P3 P2 P1 (break down)Cheap + high-impact items go first. Expensive items always get broken down before scheduling.
LOW MEDIUM HIGH CRITICAL
S (<1d) → P3 P2 P1 P0
M (1-5d) → P3 P2 P1 P0
L (>1w) → P3 P3 P2 P1 (break down)低成本+高影响事项优先处理。高成本事项在排期前必须拆分。
Tooling Cheatsheet
工具速查表
bash
undefinedbash
undefinedPHP / Laravel
PHP / Laravel
composer outdated --direct # list outdated direct deps
composer audit # known CVEs
vendor/bin/phpstan analyse # static analysis
vendor/bin/phpmd app text cleancode # mess detector
composer outdated --direct # 列出过时的直接依赖
composer audit # 已知CVE检查
vendor/bin/phpstan analyse # 静态分析
vendor/bin/phpmd app text cleancode # 代码异味检测
Node / TS
Node / TS
npm outdated # list outdated deps
npm audit # known CVEs
npx depcheck # unused deps
npx tsc --noEmit # type errors
npx eslint . --max-warnings 0 # lint warnings
npm outdated # 列出过时依赖
npm audit # 已知CVE检查
npx depcheck # 未使用依赖检查
npx tsc --noEmit # 类型错误检查
npx eslint . --max-warnings 0 # 代码规范检查(零警告)
Cross-language
跨语言
git log --since="6 months ago" --diff-filter=A -p | grep -E "TODO|FIXME|HACK"
cloc . # lines of code per language
undefinedgit log --since="6 months ago" --diff-filter=A -p | grep -E "TODO|FIXME|HACK"
cloc . # 按语言统计代码行数
undefinedHow to Use
使用方法
Read individual rule files for detailed explanations and code examples:
rules/code-duplication.md
rules/design-circular-deps.md
rules/deps-outdated-versions.md
rules/test-flaky-tests.md
rules/process-todo-fixme-aging.mdEach rule file contains:
- YAML frontmatter with metadata (title, impact, tags)
- Brief explanation of why it matters
- How to detect (commands / patterns)
- Incorrect example with explanation
- Correct example or remediation strategy
阅读单个规则文件获取详细说明和代码示例:
rules/code-duplication.md
rules/design-circular-deps.md
rules/deps-outdated-versions.md
rules/test-flaky-tests.md
rules/process-todo-fixme-aging.md每个规则文件包含:
- 带元数据的YAML前置内容(标题、影响程度、标签)
- 简要说明该规则的重要性
- 检测方法(命令/模式)
- 错误示例及解释
- 正确示例或整改策略
References
参考资料
Full Compiled Document
完整编译文档
For the complete guide with all rules expanded:
AGENTS.md如需包含所有扩展规则的完整指南:
AGENTS.md