Refactor Plan + Safety Net (Incremental Steps + Tests)
What does this prompt do?
Turns a messy module into a staged refactor plan that preserves behavior. It identifies seams, proposes an incremental sequence of changes with checkpoints, defines the tests and characterization coverage needed to prevent regressions, and includes rollback/feature-flag guidance for safe delivery. Best for legacy code, large components, and “we need to clean this up without breaking prod”.
The Prompt
Act as a [enter your role]. Description: [enter your description] Refactor context: - Code area/module: - Current problems (complexity, duplication, bugs, performance, DX): - Must keep behavior the same? (yes/no + exceptions) - Constraints (timeline, no big rewrites, backwards compatibility, rollout rules): - Target quality goals (readability, testability, performance, architecture compliance): Input: - Code snippet(s) / file(s) / architecture notes: [paste here] - Current tests (if any) and known edge cases: [paste here] Rules: - Do not ask me questions. If information is missing, state explicit assumptions and proceed. - Do NOT propose a big-bang rewrite. Provide an incremental plan with verification at each step. - Be specific: name functions/modules to extract, interfaces to introduce, and tests to add. Task: 1) Refactor strategy (high-level) - Identify seams and boundaries - Decide refactor pattern(s) (strangler, extract module, adapter, etc.) 2) Step-by-step plan (incremental) For each step include: - Goal - Exact changes (what to move/extract/rename) - Verification (tests to run/add, observable behavior) - Risk + rollback strategy 3) Test safety net - Characterization tests to lock behavior - New unit/integration tests (specific cases) - Coverage of edge cases and failure modes 4) Final state sketch - Intended module structure - Public interfaces and responsibilities Output format: Refactor Summary Risks & Assumptions Incremental Plan (Steps 1..N) Test Safety Net Final Target Structure
How to Use This Prompt
- Copy the prompt using the button above
- Open your preferred AI tool (ChatGPT, Claude, etc.)
- Paste the prompt and customize as needed
- Add specific steps in the WordPress editor for better guidance