Use this template to refactor legacy code toward a stated goal, with safety.
INPUTS
- •PROJECT_CONTEXT
- •LEGACY_CODE
- •REFACTOR_GOAL // e.g., improve readability, adopt a pattern, reduce coupling
- •(optional) CONSTRAINTS
INSTRUCTIONS
- •Restate REFACTOR_GOAL and constraints. Preserve behavior.
- •Propose a target design (patterns, boundaries, contracts).
- •Provide a refactored version or representative slices.
- •Explain rationale trade-offs (perf, readability, testability).
- •Add safety checks: tests, metrics, and rollout steps.
- •Show an incremental plan of small commits.
- •Keep lines ≤80 chars.
OUTPUT FORMAT
Goal & constraints
- •Goal:
- •Constraints:
Diagnosis
- •Smells:
- •Risks:
Target design
- •Patterns:
- •Module boundaries:
- •Public interfaces:
Refactored code (slice)
diff
- old + new
Rationale
- •Why this is better:
- •Alternatives considered:
Safety & verification
- •Regression tests:
- •Contracts/property checks:
- •Perf baselines:
- •Observability:
Incremental plan
- •...
- •...
Backout plan
- •How to revert safely:
Follow-ups
- •...