legacy について
フレームワーク、言語、依存関係の更新や技術的負債の削減に取り組む開発者向けのレガシーシステム刷新スキルです。段階的な変更、互換性、テスト、監視、ロールバック計画を重視します。
主な機能
- 01ストラングラーフィグと抽象化による移行パターン
- 02移行前・中・後のチェックリスト
- 03段階的な移行ガイダンス
- 04互換性アダプターの例
- 05テストとロールバック計画
活用シーン
- 01Express アプリケーションを Fastify に移行
- 02言語バージョンのアップグレード
- 03互換性を保ちながら技術的負債を削減
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ htlin222/ dotfiles --skill legacyインストール後、Claude Code で/legacyを入力して読み込まれたか確認します。
詳細
レガシーシステムのモダナイゼーション
レガシーシステムを安全にアップグレードし、モダナイズします。
使用する場面
- フレームワークの移行
- 言語バージョンのアップグレード
- モノリスの分割
- 技術的負債の削減
- 依存関係の更新
移行戦略
ストラングラーフィグパターン
┌─────────────────────────────────────┐
│ Load Balancer │
└──────────────┬──────────────────────┘
│
┌───────┴───────┐
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ Legacy │ │ New │
│ System │ │ Service │
└─────────────┘ └─────────────┘
1. Route new features to new service
2. Gradually migrate existing features
3. Eventually retire legacy system
抽象化による分岐
# 1. Create abstraction layer
class PaymentProcessor(ABC):
@abstractmethod
def process(self, amount: float) -> bool:
pass
# 2. Wrap legacy implementation
class LegacyPaymentProcessor(PaymentProcessor):
def __init__(self, legacy_system):
self.legacy = legacy_system
def process(self, amount: float) -> bool:
return self.legacy.old_process_method(amount)
# 3. Create new implementation
class ModernPaymentProcessor(PaymentProcessor):
def process(self, amount: float) -> bool:
# New implementation
pass
# 4. Use feature flag to switch
processor = (ModernPaymentProcessor() if feature_flag("new_payment")
else LegacyPaymentProcessor(legacy))
移行チェックリスト
開始前
- 現在の動作を文書化する
- 既存の機能にテストを追加する
- モニタリングとアラートを設定する
- ロールバック計画を作成する
- ステークホルダーに連絡する
移行中
- 段階的に変更する
- 変更のたびにテストする
- エラー率を監視する
- レガシーシステムを並行して稼働させる
- 破壊的変更を文書化する
移行後
- フィーチャーフラグを削除する
- レガシーコードを整理する
- ドキュメントを更新する
- 古いコードベースをアーカイブする
- 振り返りで得た教訓を記録する
よくある移行
jQuery から React へ
// Phase 1: Embed React in jQuery app
const root = document.getElementById("new-component");
ReactDOM.render(<NewComponent />, root);
// Phase 2: Shared state
window.appState = { user: null };
// Both jQuery and React read from appState
// Phase 3: Gradual replacement
// Replace one component at a time
Python 2 から 3 へ
# Use __future__ imports for compatibility
from __future__ import print_function, division, absolute_import
# Use six for cross-version compatibility
import six
if six.PY2:
text_type = unicode
else:
text_type = str
# Run 2to3 tool
# python -m lib2to3 --write --nobackups src/
互換性レイヤー
# Adapter for API changes
class CompatibilityAdapter:
def __init__(self, new_service):
self.new = new_service
# Old API signature
def get_user(self, user_id):
# Translate to new API
return self.new.fetch_user(id=user_id)
# Deprecation warning
def old_method(self):
warnings.warn(
"old_method is deprecated, use new_method instead",
DeprecationWarning
)
return self.new.new_method()
例
入力:「Express から Fastify へ移行する」 **アクション:**アダプターレイヤーを作成し、ルートを段階的に移行して、各ステップをテストします
入力:「このモジュールの技術的負債を削減する」 **アクション:**まずテストを追加し、段階的にリファクタリングして、互換性を維持します
コメント
Markdown 対応