Legacy Modernizer
Core Workflow
Assess system — Analyze codebase, dependencies, risks, and business constraints. Produce a dependency map and risk register before proceeding.
- Validation checkpoint: Confirm all external integrations and data contracts are documented before moving to step 2.
Plan migration — Design an incremental roadmap with explicit rollback strategies per phase. Reference references/system-assessment.md for code analysis templates.
- Validation checkpoint: Confirm each phase has a defined rollback trigger and owner.
Build safety net — Create characterization tests and monitoring before touching production code. Target 80%+ coverage of existing behavior.
- Validation checkpoint: Run the characterization test suite and confirm it passes green on the unmodified legacy system before proceeding.
Migrate incrementally — Apply strangler fig pattern with feature flags. Route traffic via a facade; shift load gradually.
- Validation checkpoint: Verify error rates and latency metrics remain within baseline thresholds after each traffic increment (e.g., 5% → 25% → 50% → 100%).
Validate & iterate — Run full test suite, review monitoring dashboards, and confirm business behavior is preserved before retiring legacy code.
- Validation checkpoint: New code must be proven stable at 100% traffic for at least one release cycle before legacy path is removed.
Reference Guide
Load detailed guidance based on context:
| Topic |
Reference |
Load When |
| Strangler Fig |
references/strangler-fig-pattern.md |
Incremental replacement, facade layer, routing |
| Refactoring |
references/refactoring-patterns.md |
Extract service, branch by abstraction, adapters |
| Migration |
references/migration-strategies.md |
Database, UI, API, framework migrations |
| Testing |
references/legacy-testing.md |
Characterization tests, golden master, approval |
| Assessment |
references/system-assessment.md |
Code analysis, dependency mapping, risk evaluation |
Code Examples
Strangler Fig Facade (Python)
# facade.py — routes requests to legacy or new service based on a feature flag
import os
from legacy_service import LegacyOrderService
from new_service import NewOrderService
class OrderServiceFacade:
def __init__(self):
self._legacy = LegacyOrderService()
self._new = NewOrderService()
def get_order(self, order_id: str):
if os.getenv("USE_NEW_ORDER_SERVICE", "false").lower() == "true":
return self._new.fetch(order_id)
return self._legacy.get(order_id)
Feature Flag Wrapper
# feature_flags.py — thin wrapper around an environment or config-based flag store
import os
def flag_enabled(flag_name: str, default: bool = False) -> bool:
"""Check whether a migration feature flag is active."""
return os.getenv(flag_name, str(default)).lower() == "true"
# Usage
if flag_enabled("USE_NEW_PAYMENT_GATEWAY"):
result = new_gateway.charge(order)
else:
result = legacy_gateway.charge(order)
Characterization Test Template (pytest)
# test_characterization_orders.py
# Captures existing legacy behavior as a golden-master safety net.
import pytest
from legacy_service import LegacyOrderService
service = LegacyOrderService()
@pytest.mark.parametrize("order_id,expected_status", [
("ORD-001", "SHIPPED"),
("ORD-002", "PENDING"),
("ORD-003", "CANCELLED"),
])
def test_order_status_golden_master(order_id, expected_status):
"""Fail loudly if legacy behavior changes unexpectedly."""
result = service.get(order_id)
assert result["status"] == expected_status, (
f"Characterization broken for {order_id}: "
f"expected {expected_status}, got {result['status']}"
)
Constraints
MUST DO
- Maintain zero production disruption during all migrations
- Create comprehensive test coverage before refactoring (target 80%+)
- Use feature flags for all incremental rollouts
- Implement monitoring and rollback procedures
- Document all migration decisions and rationale
- Preserve existing business logic and behavior
- Communicate progress and risks transparently
MUST NOT DO
- Big bang rewrites or replacements
- Skip testing legacy behavior before changes
- Deploy without rollback capability
- Break existing integrations or APIs
- Ignore technical debt in new code
- Rush migrations without proper validation
- Remove legacy code before new code is proven
Output Templates
When implementing modernization, provide:
- Assessment summary (risks, dependencies, approach)
- Migration plan (phases, rollback strategy, metrics)
- Implementation code (facades, adapters, new services)
- Test coverage (characterization, integration, e2e)
- Monitoring setup (metrics, alerts, dashboards)
Knowledge Reference
Strangler fig pattern, branch by abstraction, characterization testing, incremental migration, feature flags, canary deployments, API versioning, database refactoring, microservices extraction, technical debt reduction, zero-downtime deployment
1---2name: legacy-modernizer3description: Designs incremental migration strategies, identifies service boundaries, produces dependency maps and migration roadmaps, and generates API facade designs for aging codebases. Use when modernizing legacy systems, implementing strangler fig pattern or branch by abstraction, decomposing monoliths, upgrading frameworks or languages, or reducing technical debt without disrupting business operations.4license: MIT5---67# Legacy Modernizer89## Core Workflow10111. **Assess system** — Analyze codebase, dependencies, risks, and business constraints. Produce a dependency map and risk register before proceeding.12 - *Validation checkpoint:* Confirm all external integrations and data contracts are documented before moving to step 2.13142. **Plan migration** — Design an incremental roadmap with explicit rollback strategies per phase. Reference `references/system-assessment.md` for code analysis templates.15 - *Validation checkpoint:* Confirm each phase has a defined rollback trigger and owner.16173. **Build safety net** — Create characterization tests and monitoring before touching production code. Target 80%+ coverage of existing behavior.18 - *Validation checkpoint:* Run the characterization test suite and confirm it passes green on the unmodified legacy system before proceeding.19204. **Migrate incrementally** — Apply strangler fig pattern with feature flags. Route traffic via a facade; shift load gradually.21 - *Validation checkpoint:* Verify error rates and latency metrics remain within baseline thresholds after each traffic increment (e.g., 5% → 25% → 50% → 100%).22235. **Validate & iterate** — Run full test suite, review monitoring dashboards, and confirm business behavior is preserved before retiring legacy code.24 - *Validation checkpoint:* New code must be proven stable at 100% traffic for at least one release cycle before legacy path is removed.2526## Reference Guide2728Load detailed guidance based on context:2930| Topic | Reference | Load When |31|-------|-----------|-----------|32| Strangler Fig | `references/strangler-fig-pattern.md` | Incremental replacement, facade layer, routing |33| Refactoring | `references/refactoring-patterns.md` | Extract service, branch by abstraction, adapters |34| Migration | `references/migration-strategies.md` | Database, UI, API, framework migrations |35| Testing | `references/legacy-testing.md` | Characterization tests, golden master, approval |36| Assessment | `references/system-assessment.md` | Code analysis, dependency mapping, risk evaluation |3738## Code Examples3940### Strangler Fig Facade (Python)41```python42# facade.py — routes requests to legacy or new service based on a feature flag43import os44from legacy_service import LegacyOrderService45from new_service import NewOrderService4647class OrderServiceFacade:48 def __init__(self):49 self._legacy = LegacyOrderService()50 self._new = NewOrderService()5152 def get_order(self, order_id: str):53 if os.getenv("USE_NEW_ORDER_SERVICE", "false").lower() == "true":54 return self._new.fetch(order_id)55 return self._legacy.get(order_id)56```5758### Feature Flag Wrapper59```python60# feature_flags.py — thin wrapper around an environment or config-based flag store61import os6263def flag_enabled(flag_name: str, default: bool = False) -> bool:64 """Check whether a migration feature flag is active."""65 return os.getenv(flag_name, str(default)).lower() == "true"6667# Usage68if flag_enabled("USE_NEW_PAYMENT_GATEWAY"):69 result = new_gateway.charge(order)70else:71 result = legacy_gateway.charge(order)72```7374### Characterization Test Template (pytest)75```python76# test_characterization_orders.py77# Captures existing legacy behavior as a golden-master safety net.78import pytest79from legacy_service import LegacyOrderService8081service = LegacyOrderService()8283@pytest.mark.parametrize("order_id,expected_status", [84 ("ORD-001", "SHIPPED"),85 ("ORD-002", "PENDING"),86 ("ORD-003", "CANCELLED"),87])88def test_order_status_golden_master(order_id, expected_status):89 """Fail loudly if legacy behavior changes unexpectedly."""90 result = service.get(order_id)91 assert result["status"] == expected_status, (92 f"Characterization broken for {order_id}: "93 f"expected {expected_status}, got {result['status']}"94 )95```9697## Constraints9899### MUST DO100- Maintain zero production disruption during all migrations101- Create comprehensive test coverage before refactoring (target 80%+)102- Use feature flags for all incremental rollouts103- Implement monitoring and rollback procedures104- Document all migration decisions and rationale105- Preserve existing business logic and behavior106- Communicate progress and risks transparently107108### MUST NOT DO109- Big bang rewrites or replacements110- Skip testing legacy behavior before changes111- Deploy without rollback capability112- Break existing integrations or APIs113- Ignore technical debt in new code114- Rush migrations without proper validation115- Remove legacy code before new code is proven116117## Output Templates118119When implementing modernization, provide:1201. Assessment summary (risks, dependencies, approach)1212. Migration plan (phases, rollback strategy, metrics)1223. Implementation code (facades, adapters, new services)1234. Test coverage (characterization, integration, e2e)1245. Monitoring setup (metrics, alerts, dashboards)125126## Knowledge Reference127128Strangler fig pattern, branch by abstraction, characterization testing, incremental migration, feature flags, canary deployments, API versioning, database refactoring, microservices extraction, technical debt reduction, zero-downtime deployment