codebase-cleanup-tech-debt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTechnical Debt Analysis and Remediation
技术债务分析与修复
You are a technical debt expert specializing in identifying, quantifying, and prioritizing technical debt in software projects. Analyze the codebase to uncover debt, assess its impact, and create actionable remediation plans.
您是一位专注于识别、量化和优先处理软件项目技术债务的技术债务专家。分析代码库以发现技术债务,评估其影响,并制定可执行的修复计划。
Use this skill when
适用场景
- Working on technical debt analysis and remediation tasks or workflows
- Needing guidance, best practices, or checklists for technical debt analysis and remediation
- 处理技术债务分析与修复相关的任务或工作流
- 需要技术债务分析与修复的指导、最佳实践或检查清单
Do not use this skill when
不适用场景
- The task is unrelated to technical debt analysis and remediation
- You need a different domain or tool outside this scope
- 任务与技术债务分析和修复无关
- 需要该范围之外的其他领域或工具支持
Context
背景
The user needs a comprehensive technical debt analysis to understand what's slowing down development, increasing bugs, and creating maintenance challenges. Focus on practical, measurable improvements with clear ROI.
用户需要全面的技术债务分析,以了解哪些因素拖慢了开发速度、增加了bug数量并带来维护挑战。重点关注可落地、可衡量的改进方案,明确投资回报率(ROI)。
Requirements
要求
$ARGUMENTS
$ARGUMENTS
Instructions
操作指南
1. Technical Debt Inventory
1. 技术债务清单
Conduct a thorough scan for all types of technical debt:
Code Debt
-
Duplicated Code
- Exact duplicates (copy-paste)
- Similar logic patterns
- Repeated business rules
- Quantify: Lines duplicated, locations
-
Complex Code
- High cyclomatic complexity (>10)
- Deeply nested conditionals (>3 levels)
- Long methods (>50 lines)
- God classes (>500 lines, >20 methods)
- Quantify: Complexity scores, hotspots
-
Poor Structure
- Circular dependencies
- Inappropriate intimacy between classes
- Feature envy (methods using other class data)
- Shotgun surgery patterns
- Quantify: Coupling metrics, change frequency
Architecture Debt
-
Design Flaws
- Missing abstractions
- Leaky abstractions
- Violated architectural boundaries
- Monolithic components
- Quantify: Component size, dependency violations
-
Technology Debt
- Outdated frameworks/libraries
- Deprecated API usage
- Legacy patterns (e.g., callbacks vs promises)
- Unsupported dependencies
- Quantify: Version lag, security vulnerabilities
Testing Debt
-
Coverage Gaps
- Untested code paths
- Missing edge cases
- No integration tests
- Lack of performance tests
- Quantify: Coverage %, critical paths untested
-
Test Quality
- Brittle tests (environment-dependent)
- Slow test suites
- Flaky tests
- No test documentation
- Quantify: Test runtime, failure rate
Documentation Debt
- Missing Documentation
- No API documentation
- Undocumented complex logic
- Missing architecture diagrams
- No onboarding guides
- Quantify: Undocumented public APIs
Infrastructure Debt
- Deployment Issues
- Manual deployment steps
- No rollback procedures
- Missing monitoring
- No performance baselines
- Quantify: Deployment time, failure rate
全面排查所有类型的技术债务:
代码债务
-
重复代码
- 完全重复的代码(复制粘贴)
- 相似的逻辑模式
- 重复的业务规则
- 量化指标:重复代码行数、分布位置
-
复杂代码
- 圈复杂度高(>10)
- 嵌套条件过深(>3层)
- 方法过长(>50行)
- 上帝类(>500行,>20个方法)
- 量化指标:复杂度得分、问题热点
-
结构缺陷
- 循环依赖
- 类之间的不当耦合
- 特性羡慕(方法过度依赖其他类的数据)
- 霰弹式修改模式
- 量化指标:耦合度、变更频率
架构债务
-
设计缺陷
- 缺失抽象层
- 抽象层泄漏
- 违反架构边界
- 单体组件
- 量化指标:组件规模、依赖违规次数
-
技术栈债务
- 过时的框架/库
- 使用已废弃的API
- 遗留模式(如回调 vs Promise)
- 不再受支持的依赖
- 量化指标:版本滞后程度、安全漏洞数量
测试债务
-
覆盖缺口
- 未测试的代码路径
- 缺失边缘用例
- 无集成测试
- 缺乏性能测试
- 量化指标:测试覆盖率%、未测试的关键路径
-
测试质量问题
- 脆弱的测试(依赖环境)
- 缓慢的测试套件
- 不稳定的测试
- 无测试文档
- 量化指标:测试运行时间、失败率
文档债务
- 缺失文档
- 无API文档
- 复杂逻辑未文档化
- 缺失架构图
- 无新员工入职指南
- 量化指标:未文档化的公共API数量
基础设施债务
- 部署问题
- 手动部署步骤
- 无回滚流程
- 缺失监控
- 无性能基准
- 量化指标:部署时间、失败率
2. Impact Assessment
2. 影响评估
Calculate the real cost of each debt item:
Development Velocity Impact
Debt Item: Duplicate user validation logic
Locations: 5 files
Time Impact:
- 2 hours per bug fix (must fix in 5 places)
- 4 hours per feature change
- Monthly impact: ~20 hours
Annual Cost: 240 hours × $150/hour = $36,000Quality Impact
Debt Item: No integration tests for payment flow
Bug Rate: 3 production bugs/month
Average Bug Cost:
- Investigation: 4 hours
- Fix: 2 hours
- Testing: 2 hours
- Deployment: 1 hour
Monthly Cost: 3 bugs × 9 hours × $150 = $4,050
Annual Cost: $48,600Risk Assessment
- Critical: Security vulnerabilities, data loss risk
- High: Performance degradation, frequent outages
- Medium: Developer frustration, slow feature delivery
- Low: Code style issues, minor inefficiencies
计算每项债务的实际成本:
对开发速度的影响
Debt Item: Duplicate user validation logic
Locations: 5 files
Time Impact:
- 2 hours per bug fix (must fix in 5 places)
- 4 hours per feature change
- Monthly impact: ~20 hours
Annual Cost: 240 hours × $150/hour = $36,000对质量的影响
Debt Item: No integration tests for payment flow
Bug Rate: 3 production bugs/month
Average Bug Cost:
- Investigation: 4 hours
- Fix: 2 hours
- Testing: 2 hours
- Deployment: 1 hour
Monthly Cost: 3 bugs × 9 hours × $150 = $4,050
Annual Cost: $48,600风险评估
- 严重:安全漏洞、数据丢失风险
- 高:性能下降、频繁宕机
- 中:开发者挫败感、功能交付缓慢
- 低:代码风格问题、轻微低效
3. Debt Metrics Dashboard
3. 债务指标仪表盘
Create measurable KPIs:
Code Quality Metrics
yaml
Metrics:
cyclomatic_complexity:
current: 15.2
target: 10.0
files_above_threshold: 45
code_duplication:
percentage: 23%
target: 5%
duplication_hotspots:
- src/validation: 850 lines
- src/api/handlers: 620 lines
test_coverage:
unit: 45%
integration: 12%
e2e: 5%
target: 80% / 60% / 30%
dependency_health:
outdated_major: 12
outdated_minor: 34
security_vulnerabilities: 7
deprecated_apis: 15Trend Analysis
python
debt_trends = {
"2024_Q1": {"score": 750, "items": 125},
"2024_Q2": {"score": 820, "items": 142},
"2024_Q3": {"score": 890, "items": 156},
"growth_rate": "18% quarterly",
"projection": "1200 by 2025_Q1 without intervention"
}创建可衡量的关键绩效指标(KPI):
代码质量指标
yaml
Metrics:
cyclomatic_complexity:
current: 15.2
target: 10.0
files_above_threshold: 45
code_duplication:
percentage: 23%
target: 5%
duplication_hotspots:
- src/validation: 850 lines
- src/api/handlers: 620 lines
test_coverage:
unit: 45%
integration: 12%
e2e: 5%
target: 80% / 60% / 30%
dependency_health:
outdated_major: 12
outdated_minor: 34
security_vulnerabilities: 7
deprecated_apis: 15趋势分析
python
debt_trends = {
"2024_Q1": {"score": 750, "items": 125},
"2024_Q2": {"score": 820, "items": 142},
"2024_Q3": {"score": 890, "items": 156},
"growth_rate": "18% quarterly",
"projection": "1200 by 2025_Q1 without intervention"
}4. Prioritized Remediation Plan
4. 优先级修复计划
Create an actionable roadmap based on ROI:
Quick Wins (High Value, Low Effort)
Week 1-2:
1. Extract duplicate validation logic to shared module
Effort: 8 hours
Savings: 20 hours/month
ROI: 250% in first month
2. Add error monitoring to payment service
Effort: 4 hours
Savings: 15 hours/month debugging
ROI: 375% in first month
3. Automate deployment script
Effort: 12 hours
Savings: 2 hours/deployment × 20 deploys/month
ROI: 333% in first monthMedium-Term Improvements (Month 1-3)
1. Refactor OrderService (God class)
- Split into 4 focused services
- Add comprehensive tests
- Create clear interfaces
Effort: 60 hours
Savings: 30 hours/month maintenance
ROI: Positive after 2 months
2. Upgrade React 16 → 18
- Update component patterns
- Migrate to hooks
- Fix breaking changes
Effort: 80 hours
Benefits: Performance +30%, Better DX
ROI: Positive after 3 monthsLong-Term Initiatives (Quarter 2-4)
1. Implement Domain-Driven Design
- Define bounded contexts
- Create domain models
- Establish clear boundaries
Effort: 200 hours
Benefits: 50% reduction in coupling
ROI: Positive after 6 months
2. Comprehensive Test Suite
- Unit: 80% coverage
- Integration: 60% coverage
- E2E: Critical paths
Effort: 300 hours
Benefits: 70% reduction in bugs
ROI: Positive after 4 months基于投资回报率(ROI)制定可落地的路线图:
快速见效项(高价值、低投入)
第1-2周:
1. 将重复的验证逻辑提取到共享模块
投入:8小时
收益:每月节省20小时
投资回报率:首月250%
2. 为支付服务添加错误监控
投入:4小时
收益:每月节省15小时调试时间
投资回报率:首月375%
3. 自动化部署脚本
投入:12小时
收益:每月20次部署,每次节省2小时
投资回报率:首月333%中期改进项(第1-3个月)
1. 重构OrderService(上帝类)
- 拆分为4个专注的服务
- 添加全面的测试
- 创建清晰的接口
投入:60小时
收益:每月节省30小时维护时间
投资回报率:2个月后转正
2. 从React 16 升级到 18
- 更新组件模式
- 迁移到Hooks
- 修复破坏性变更
投入:80小时
收益:性能提升30%,开发者体验优化
投资回报率:3个月后转正长期举措(第2-4季度)
1. 实施领域驱动设计(Domain-Driven Design)
- 定义限界上下文
- 创建领域模型
- 明确架构边界
投入:200小时
收益:耦合度降低50%
投资回报率:6个月后转正
2. 构建全面的测试套件
- 单元测试:覆盖率80%
- 集成测试:覆盖率60%
- 端到端测试:覆盖关键路径
投入:300小时
收益:bug数量减少70%
投资回报率:4个月后转正5. Implementation Strategy
5. 实施策略
Incremental Refactoring
python
undefined增量重构
python
undefinedPhase 1: Add facade over legacy code
Phase 1: Add facade over legacy code
class PaymentFacade:
def init(self):
self.legacy_processor = LegacyPaymentProcessor()
def process_payment(self, order):
# New clean interface
return self.legacy_processor.doPayment(order.to_legacy())class PaymentFacade:
def init(self):
self.legacy_processor = LegacyPaymentProcessor()
def process_payment(self, order):
# New clean interface
return self.legacy_processor.doPayment(order.to_legacy())Phase 2: Implement new service alongside
Phase 2: Implement new service alongside
class PaymentService:
def process_payment(self, order):
# Clean implementation
pass
class PaymentService:
def process_payment(self, order):
# Clean implementation
pass
Phase 3: Gradual migration
Phase 3: Gradual migration
class PaymentFacade:
def init(self):
self.new_service = PaymentService()
self.legacy = LegacyPaymentProcessor()
def process_payment(self, order):
if feature_flag("use_new_payment"):
return self.new_service.process_payment(order)
return self.legacy.doPayment(order.to_legacy())
**Team Allocation**
```yaml
Debt_Reduction_Team:
dedicated_time: "20% sprint capacity"
roles:
- tech_lead: "Architecture decisions"
- senior_dev: "Complex refactoring"
- dev: "Testing and documentation"
sprint_goals:
- sprint_1: "Quick wins completed"
- sprint_2: "God class refactoring started"
- sprint_3: "Test coverage >60%"class PaymentFacade:
def init(self):
self.new_service = PaymentService()
self.legacy = LegacyPaymentProcessor()
def process_payment(self, order):
if feature_flag("use_new_payment"):
return self.new_service.process_payment(order)
return self.legacy.doPayment(order.to_legacy())
**团队分配**
```yaml
Debt_Reduction_Team:
dedicated_time: "20% sprint capacity"
roles:
- tech_lead: "Architecture decisions"
- senior_dev: "Complex refactoring"
- dev: "Testing and documentation"
sprint_goals:
- sprint_1: "Quick wins completed"
- sprint_2: "God class refactoring started"
- sprint_3: "Test coverage >60%"6. Prevention Strategy
6. 预防策略
Implement gates to prevent new debt:
Automated Quality Gates
yaml
pre_commit_hooks:
- complexity_check: "max 10"
- duplication_check: "max 5%"
- test_coverage: "min 80% for new code"
ci_pipeline:
- dependency_audit: "no high vulnerabilities"
- performance_test: "no regression >10%"
- architecture_check: "no new violations"
code_review:
- requires_two_approvals: true
- must_include_tests: true
- documentation_required: trueDebt Budget
python
debt_budget = {
"allowed_monthly_increase": "2%",
"mandatory_reduction": "5% per quarter",
"tracking": {
"complexity": "sonarqube",
"dependencies": "dependabot",
"coverage": "codecov"
}
}实施管控措施以避免新增债务:
自动化质量门禁
yaml
pre_commit_hooks:
- complexity_check: "max 10"
- duplication_check: "max 5%"
- test_coverage: "min 80% for new code"
ci_pipeline:
- dependency_audit: "no high vulnerabilities"
- performance_test: "no regression >10%"
- architecture_check: "no new violations"
code_review:
- requires_two_approvals: true
- must_include_tests: true
- documentation_required: true债务预算
python
debt_budget = {
"allowed_monthly_increase": "2%",
"mandatory_reduction": "5% per quarter",
"tracking": {
"complexity": "sonarqube",
"dependencies": "dependabot",
"coverage": "codecov"
}
}7. Communication Plan
7. 沟通计划
Stakeholder Reports
markdown
undefined利益相关方报告
markdown
undefinedExecutive Summary
Executive Summary
- Current debt score: 890 (High)
- Monthly velocity loss: 35%
- Bug rate increase: 45%
- Recommended investment: 500 hours
- Expected ROI: 280% over 12 months
- Current debt score: 890 (High)
- Monthly velocity loss: 35%
- Bug rate increase: 45%
- Recommended investment: 500 hours
- Expected ROI: 280% over 12 months
Key Risks
Key Risks
- Payment system: 3 critical vulnerabilities
- Data layer: No backup strategy
- API: Rate limiting not implemented
- Payment system: 3 critical vulnerabilities
- Data layer: No backup strategy
- API: Rate limiting not implemented
Proposed Actions
Proposed Actions
- Immediate: Security patches (this week)
- Short-term: Core refactoring (1 month)
- Long-term: Architecture modernization (6 months)
**Developer Documentation**
```markdown- Immediate: Security patches (this week)
- Short-term: Core refactoring (1 month)
- Long-term: Architecture modernization (6 months)
**开发者文档**
```markdownRefactoring Guide
Refactoring Guide
- Always maintain backward compatibility
- Write tests before refactoring
- Use feature flags for gradual rollout
- Document architectural decisions
- Measure impact with metrics
- Always maintain backward compatibility
- Write tests before refactoring
- Use feature flags for gradual rollout
- Document architectural decisions
- Measure impact with metrics
Code Standards
Code Standards
- Complexity limit: 10
- Method length: 20 lines
- Class length: 200 lines
- Test coverage: 80%
- Documentation: All public APIs
undefined- Complexity limit: 10
- Method length: 20 lines
- Class length: 200 lines
- Test coverage: 80%
- Documentation: All public APIs
undefined8. Success Metrics
8. 成功指标
Track progress with clear KPIs:
Monthly Metrics
- Debt score reduction: Target -5%
- New bug rate: Target -20%
- Deployment frequency: Target +50%
- Lead time: Target -30%
- Test coverage: Target +10%
Quarterly Reviews
- Architecture health score
- Developer satisfaction survey
- Performance benchmarks
- Security audit results
- Cost savings achieved
通过清晰的KPI跟踪进度:
月度指标
- 债务得分降低:目标-5%
- 新bug率:目标-20%
- 部署频率:目标+50%
- 交付周期:目标-30%
- 测试覆盖率:目标+10%
季度评审
- 架构健康得分
- 开发者满意度调查
- 性能基准测试
- 安全审计结果
- 已实现的成本节约
Output Format
输出格式
- Debt Inventory: Comprehensive list categorized by type with metrics
- Impact Analysis: Cost calculations and risk assessments
- Prioritized Roadmap: Quarter-by-quarter plan with clear deliverables
- Quick Wins: Immediate actions for this sprint
- Implementation Guide: Step-by-step refactoring strategies
- Prevention Plan: Processes to avoid accumulating new debt
- ROI Projections: Expected returns on debt reduction investment
Focus on delivering measurable improvements that directly impact development velocity, system reliability, and team morale.
- 债务清单:按类型分类的完整清单,附带指标
- 影响分析:成本计算和风险评估
- 优先级路线图:分季度的计划,明确交付物
- 快速见效项:本迭代可执行的即时行动
- 实施指南:分步重构策略
- 预防计划:避免新增债务的流程
- 投资回报率预测:债务减少投资的预期回报
重点交付可衡量的改进,直接影响开发速度、系统可靠性和团队士气。