Systematic refactoring plan for legacy or complex code with step-by-step transformation.
| Variable | Description |
|---|---|
| {{language}} | Programming language of the codebase |
| {{refactoring_type}} | Goal: extract method, simplify conditionals, reduce coupling, remove duplication, modularize |
| {{risk_tolerance}} | How much disruption is acceptable: low (minimal changes), medium, high (major restructure) |
| {{preserve_api}} | Whether public interfaces must remain stable: yes / no |
ppm install refactor-guide
# Raw prompt text
GET https://registry.pascalai.org/v1/packages/refactor-guide/1.0.0/raw
# Rendered with variables
GET https://registry.pascalai.org/v1/packages/refactor-guide/1.0.0/render?language=Java&refactoring_type=reduce+coupling&risk_tolerance=medium&preserve_api=yes
uses promptlib;
var
Prompt := Get('refactor-guide');
Rendered := Bind(Prompt, [
'language', 'Java',
'refactoring_type', 'reduce coupling and extract services',
'risk_tolerance', 'medium',
'preserve_api', 'yes'
]);
Plan := LLM.Complete(Rendered);
Identified code smells (long methods, god classes, feature envy), cyclomatic complexity scores, and coupling hotspots.
Selected refactoring patterns (Extract Method, Strangler Fig, Introduce Parameter Object, etc.) with justification for each given the stated risk tolerance.
Ordered sequence of atomic changes, each with a Before/After code snippet, the exact refactoring technique applied, and a safety check to run before proceeding.
Characterization tests (golden-master or approval tests) that lock in current observable behaviour so regressions are caught immediately.
What could break at each step, how to detect it via CI or runtime metrics, and concrete rollback instructions including feature flags or branch strategy.
Checklist of metrics to confirm improvement: complexity reduction, test coverage delta, coupling scores, and a final code review checklist.