Plan an incremental refactor for legacy code
Break down monolith or fragile legacy modules into safe, testable milestones using branch-by-abstraction patterns.
You getCurrent Architecture Weaknesses, characterization Test Strategy and phased Refactoring Roadmap
Prompt
Act as a software modernization architect. Review the provided fragile code module and devise a phased, non-breaking refactoring roadmap using the branch-by-abstraction pattern.
Rules:
- Maintain full backward compatibility for current callers during all intermediate releases.
- Isolate side effects, tight database coupling, and global state first.
- Provide specific characterization tests to lock down current behavior before changes start.
- Break execution into 3-4 distinct pull requests that can be merged independently to production without risk.
Output format:
- Current Architecture Weaknesses (anti-patterns and regression hotspots)
- Characterization Test Strategy (exact inputs and state to assert)
- Phased Refactoring Roadmap (PR 1 through PR 4 with objectives, design pattern used, and rollback plan)
- Verification Checklist
Here is the module to refactor:Example output
Paste your legacy class or function into Claude, ChatGPT, or Gemini. Ask follow-up prompts for specific adapter code if you need to run both implementations concurrently under a feature toggle.
Make it repeatable
Keep using this prompt without pasting it in every time.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Refactor nested legacy loops into flat readable helper functions
Decompose deeply nested legacy loops into single-purpose functions. Use this when reviewing complex procedural code that is hard to test or debug.
Refactor Pasted Code for Readability Without Changing Its Behavior
Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.
Split a large pull request into reviewable commits
Break down overwhelming pull requests into clean, sequential, logically isolated commits. Use it when code reviews stall due to sprawling diffs.
Document module behavior from its test suite
Extract clear business rules, accepted inputs, and edge cases for undocumented modules solely from their test suites.
Design a Scalable API Rate Limiting Architecture
Get a complete technical blueprint for implementing API rate limiting using Redis, including data structures, tiered limit logic, and standard response headers.
Port a Function or Module to Another Language With Tests Proving Same Behavior
Lists the source code's behaviors and edge cases, writes tests in the target language first, ports the code idiomatically, and gives a table of library mappings and semantics that differ.