mcpField
C
code-refactoring-tech-debt

code-refactoring-tech-debt

github.com/rmyndharis開発1.9k39 回インストール2 週間前に更新
リポジトリ

code-refactoring-tech-debt について

開発チーム向けの技術的負債分析スキルです。コードやアーキテクチャ、テストの負債を洗い出し、影響評価から段階的な改善計画、指標や予防策まで整理します。

主な機能

  1. 01コード・設計・テスト負債の分類
  2. 02速度・品質・リスクへの影響評価
  3. 03段階的な改善ロードマップの作成
  4. 04品質指標と負債推移の追跡
  5. 05品質ゲートと予防策の策定

活用シーン

  1. 01開発を遅らせる負債の評価
  2. 02影響と工数に基づくリファクタリングの優先付け
  3. 03四半期ごとの負債削減計画と指標の策定

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/rmyndharis/antigravity-skills --skill code-refactoring-tech-debt

インストール後、Claude Code で/code-refactoring-tech-debtを入力して読み込まれたか確認します。

詳細

技術的負債の分析と解消

ソフトウェアプロジェクトの技術的負債の特定、定量化、優先順位付けを専門とする、技術的負債のエキスパートです。コードベースを分析して負債を明らかにし、その影響を評価して、実行可能な解消計画を作成してください。

このスキルを使用する場面

  • 技術的負債の分析と解消に関するタスクやワークフローに取り組む場合
  • 技術的負債の分析と解消に関するガイダンス、ベストプラクティス、チェックリストが必要な場合

このスキルを使用しない場面

  • タスクが技術的負債の分析と解消に関係しない場合
  • この範囲外の別のドメインやツールが必要な場合

コンテキスト

ユーザーは、開発を遅らせ、バグを増やし、保守上の課題を生み出している要因を理解するため、包括的な技術的負債の分析を必要としています。明確な ROI を伴う、実用的かつ測定可能な改善に重点を置いてください。

要件

$ARGUMENTS

手順

1. 技術的負債の一覧化

あらゆる種類の技術的負債を徹底的に調査してください。

コードの負債

  • コードの重複

    • 完全な重複(コピー&ペースト)
    • 類似したロジックパターン
    • 繰り返されるビジネスルール
    • 定量化:重複した行数、箇所
  • 複雑なコード

    • 循環的複雑度が高い(>10)
    • 条件分岐のネストが深い(>3 階層)
    • 長いメソッド(>50 行)
    • ゴッドクラス(>500 行、>20 メソッド)
    • 定量化:複雑度スコア、ホットスポット
  • 不適切な構造

    • 循環依存
    • クラス間の過度な密結合
    • フィーチャーエンヴィ(他のクラスのデータを使うメソッド)
    • ショットガン・サージェリーのパターン
    • 定量化:結合度の指標、変更頻度

アーキテクチャの負債

  • 設計上の欠陥

    • 抽象化の欠如
    • 漏れのある抽象化
    • アーキテクチャ上の境界の違反
    • モノリシックなコンポーネント
    • 定量化:コンポーネントの規模、依存関係の違反
  • 技術的負債

    • 古いフレームワーク/ライブラリ
    • 非推奨 API の使用
    • レガシーパターン(例:プロミスではなくコールバック)
    • サポート対象外の依存関係
    • 定量化:バージョンの遅れ、セキュリティ脆弱性

テストの負債

  • カバレッジの不足

    • テストされていないコードパス
    • エッジケースの欠如
    • 統合テストがない
    • パフォーマンステストの不足
    • 定量化:カバレッジ率、未テストの重要なパス
  • テストの品質

    • 壊れやすいテスト(環境に依存)
    • 遅いテストスイート
    • 不安定なテスト
    • テストのドキュメントがない
    • 定量化:テストの実行時間、失敗率

ドキュメントの負債

  • ドキュメントの不足
    • API ドキュメントがない
    • 複雑なロジックが文書化されていない
    • アーキテクチャ図がない
    • オンボーディングガイドがない
    • 定量化:文書化されていない公開 API

インフラストラクチャの負債

  • デプロイの問題
    • 手動のデプロイ手順
    • ロールバック手順がない
    • モニタリングが不足
    • パフォーマンスのベースラインがない
    • 定量化:デプロイ時間、失敗率
2. 影響の評価

負債項目ごとの実際のコストを算出してください。

開発速度への影響

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. 負債メトリクスのダッシュボード

測定可能な KPI を作成してください。

コード品質の指標

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

傾向分析

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. 優先順位を付けた解消計画

ROI に基づいた実行可能なロードマップを作成してください。

短期で成果が得られる施策(価値が高く、労力が少ない) 第 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 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 months

長期的な取り組み(第 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
5. 実施戦略

段階的なリファクタリング

# 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())

# Phase 2: Implement new service alongside
class PaymentService:
    def process_payment(self, order):
        # Clean implementation
        pass

# 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())

チームへの割り当て

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. 予防戦略

新たな負債を防ぐためのゲートを導入してください。

自動化された品質ゲート

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

負債の予算

debt_budget = {
    "allowed_monthly_increase": "2%",
    "mandatory_reduction": "5% per quarter",
    "tracking": {
        "complexity": "sonarqube",
        "dependencies": "dependabot",
        "coverage": "codecov"
    }
}
7. コミュニケーション計画

ステークホルダー向けレポート

## 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

## Key Risks
1. Payment system: 3 critical vulnerabilities
2. Data layer: No backup strategy
3. API: Rate limiting not implemented

## Proposed Actions
1. Immediate: Security patches (this week)
2. Short-term: Core refactoring (1 month)
3. Long-term: Architecture modernization (6 months)

開発者向けドキュメント

## Refactoring Guide
1. Always maintain backward compatibility
2. Write tests before refactoring
3. Use feature flags for gradual rollout
4. Document architectural decisions
5. Measure impact with metrics

## Code Standards
- Complexity limit: 10
- Method length: 20 lines
- Class length: 200 lines
- Test coverage: 80%
- Documentation: All public APIs
8. 成功指標

明確な KPI で進捗を追跡します。

月次指標

  • 負債スコアの削減:目標 -5%
  • 新規バグ発生率:目標 -20%
  • デプロイ頻度:目標 +50%
  • リードタイム:目標 -30%
  • テストカバレッジ:目標 +10%

四半期レビュー

  • アーキテクチャ健全性スコア
  • 開発者満足度調査
  • パフォーマンスベンチマーク
  • セキュリティ監査結果
  • 達成したコスト削減額

出力形式

  1. 負債の一覧:種類別に分類し、指標を含めた包括的な一覧
  2. 影響分析:コスト計算とリスク評価
  3. 優先順位付きロードマップ:明確な成果物を含む四半期ごとの計画
  4. クイックウィン:今スプリントで実施する即時対応
  5. 実装ガイド:リファクタリング戦略の段階的な手順
  6. 防止計画:新たな負債の蓄積を防ぐプロセス
  7. ROI の予測:負債削減への投資に対する期待収益

開発速度、システムの信頼性、チームの士気に直接影響する、測定可能な改善の実現に注力してください。

コメント