legacy
Legacy Modernization
Safely upgrade and modernize legacy systems.
When to Use
- Framework migrations
- Language version upgrades
- Monolith decomposition
- Technical debt reduction
- Dependency updates
Migration Strategies
Strangler Fig Pattern
┌─────────────────────────────────────┐
│ Load Balancer │
└──────────────┬──────────────────────┘
│
┌───────┴───────┐
│ │
┌──────▼──────┐ ┌──────▼──────┐
│ Legacy │ │ New │
│ System │ │ Service │
└─────────────┘ └─────────────┘
1. Route new features to new service
2. Gradually migrate existing features
3. Eventually retire legacy system
Branch by Abstraction
# 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))
Migration Checklist
Before Starting
- Document current behavior
- Add tests for existing functionality
- Set up monitoring and alerts
- Create rollback plan
- Communicate with stakeholders
During Migration
- Make incremental changes
- Test after each change
- Monitor error rates
- Keep legacy running in parallel
- Document breaking changes
After Migration
- Remove feature flags
- Clean up legacy code
- Update documentation
- Archive old codebase
- Post-mortem lessons learned
Common Migrations
jQuery to 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 to 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/
Compatibility Layers
# 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()
Examples
Input: "Migrate from Express to Fastify" Action: Create adapter layer, migrate routes incrementally, test each step
Input: "Reduce technical debt in this module" Action: Add tests first, refactor incrementally, maintain compatibility
More from htlin222/dotfiles
data-science
Data analysis, SQL queries, BigQuery operations, and data insights. Use for data analysis tasks and queries.
52c-lang
Write efficient C code with proper memory management and system calls. Use for C optimization, memory issues, or system programming.
46quarto-book
Generate Quarto Book project structure with chapters, configuration, and output settings. Use when user wants to create a book, multi-chapter document, technical manual, or asks about Quarto book setup.
45scientific-figure-assembly
Assemble multi-panel scientific figures with panel labels (A, B, C) at publication quality (300 DPI) using R. Use when combining individual plots into journal-ready figures.
43ai-engineer
Build LLM apps, RAG systems, and prompt pipelines. Use for AI-powered features.
42devops
Configure CI/CD, Docker, and cloud deployments. Use for deployment setup, containers, or infrastructure automation.
42