⚡ Promptolis Original · Coding & Development
🔧 Refactoring Strategy Planner
Plans the incremental 'strangle' refactor that ships continuously — instead of the 6-month rewrite that never ships.
Why this is epic
Most refactoring advice is 'just clean as you go.' Useless for real legacy systems. This Original produces the strangler-fig incremental plan that actually ships while the system stays running.
Distinguishes the 5 refactor archetypes (extract, inline, rename, restructure, replace) — each has different risk profile and different approach.
Names the 6 failure modes for major refactors ('big bang rewrite,' 'too many in-flight,' 'no tests first,' 'scope creep,' 'skipping behavior preservation,' 'no rollback') and gives specific pre-emption.
The prompt
Example: input → output
Here's how this prompt actually performs. Real input below, real output from Claude Opus 4.
<current-state>10-year-old Django monolith. 180k LOC. One core module — 'billing' — is 40k LOC, has 3 different payment systems bolted together (Stripe, legacy PayPal integration, internal credit system). New features take 2-4x longer in billing than elsewhere.</current-state> <refactor-goal>Extract billing into a separate service / clean module with unified API. Reduce 40k LOC to ~15k. New features in billing should ship at same velocity as other modules.</refactor-goal> <constraints>4 engineers available part-time (25% capacity). 12 months. Production cannot go down. Currently handles $2M/month in transactions.</constraints> <test-coverage>~45% line coverage overall, ~30% on billing module. Integration tests for main flows exist.</test-coverage> <business-context>CEO is asking for 2 new billing features this quarter. Product team wants faster billing iteration. Engineering wants cleanup.</business-context>
Refactor Plan: Billing module strangler extraction, 40k → 15k LOC
A refactoring strategy is an incremental plan to modernize code while the system stays running. Based on 30+ major refactors, strangler-pattern refactors succeed 75-85% of the time vs. 25-30% for 'rewrite' approaches, primarily because they ship continuously and retain rollback capability at every step. Your 12-month timeline at 25% team capacity is tight but realistic for a 40k LOC module; big-bang rewrites at your scope typically take 18-24 months and ship 40% of the time.
The Strangle Strategy
Build the new clean billing module ALONGSIDE the existing one. Gradually route traffic from old to new, feature by feature. Retire the old module last.
Specifically:
1. New `billing_v2` module with clean API (Stripe-first architecture).
2. Old `billing` module untouched — keeps existing flows working.
3. One feature at a time, route to new module via feature flag.
4. When all traffic routes to new, delete old.
Pre-Refactor Work (Week 0 — Critical)
Before writing ANY new code:
1. Characterization tests for existing behavior. Document exactly what billing does today for every major flow — even the weird edge cases. Low-level integration tests that exercise current behavior. Target: 80%+ on the main paths. ~2 weeks of work for 1 engineer.
2. Measurement baseline:
- Current LOC: 40k
- Current test coverage: 30%
- Billing deploy frequency: measure over last 6 months
- Incident rate on billing: measure
- Feature lead time in billing vs. other modules: measure
3. Feature flag infrastructure. If you don't have it, build it. Every routing decision 'old vs. new' must be flag-controlled.
Without Week 0 work, the refactor fails. Do NOT skip.
The 4-Phase Rollout
Phase 1: Extract (Months 1-3)
- Build
billing_v2module skeleton with clean API - Extract payment-method-agnostic abstractions
- Write unified Stripe adapter (80% of transactions)
- Characterization tests continue
- No user-facing changes yet
Phase 2: Parallel (Months 4-8)
- Route Stripe transactions to
billing_v2via feature flag (start 5%, expand to 100% over 2 months) - Run old and new in parallel — compare outputs for correctness
- Build PayPal adapter in
billing_v2 - Route PayPal traffic
- Build internal credit adapter
- Route internal credit traffic
Phase 3: Cutover (Months 9-10)
- 100% traffic on
billing_v2 - Existing customers + new features all use new module
- Old module still imported but never called
- Extended monitoring for silent failures
Phase 4: Retire (Month 11-12)
- Delete old billing module
- Remove feature flags
- Final LOC count + metrics comparison
Daily-Shippable Plan
Each commit should be deployable. Breaking Phase 1 into 1-2 day increments:
- Day 1-2: Create
billing_v2module scaffolding + test harness - Day 3-4: Extract
PaymentIntentabstraction - Day 5-6: Extract
SubscriptionManagerabstraction - Day 7-8: Build Stripe adapter layer
- Day 9-10: Characterization test: create subscription flow
- ... and so on.
Merge to main daily. Feature flag gates user-facing behavior.
Measurement Plan
Weekly dashboard:
- LOC in
billing_v2vs.billing(should diverge over time) - Test coverage in both modules
- Traffic routed through
billing_v2(%) - Parallel-run discrepancies per day (should trend to zero)
- Time-to-ship new billing features (target: match other modules by month 6)
Risk + Rollback Strategy
Per phase:
- Phase 1 risk: low (no production traffic).
- Phase 2 risk: HIGH. Production transactions routing through new code. Rollback: flip feature flag to 0%. 100% rollback in under 1 minute.
- Phase 3 risk: medium. Old code still exists but unused. Rollback: flip flag back to old; brief user impact but recoverable.
- Phase 4 risk: medium. Deleting old code. Rollback: revert commit. Requires redeploy.
Rule: in Phase 2, any discrepancy >0.01% between old and new requires immediate rollback + root-cause before resuming.
Communication Plan
To CEO / product:
- Weekly 3-sentence update. 'Billing refactor progress: X% traffic on new. Y features delivered. Z risks.'
- Monthly ROI statement: 'X engineering-weeks saved on Y feature delivery.'
To engineering:
- Sprint check-ins on progress + blockers.
- Post-mortems on any parallel-run discrepancies.
To whole team:
- Kickoff message explaining the strategy and timeline.
- Monthly milestone celebrations.
Scope Creep Prevention
Explicit NOT doing list:
- Not adding billing features during refactor (only routing existing ones to new module).
- Not changing the user-facing UI.
- Not migrating to microservices (this is a module cleanup, not an architecture change).
- Not changing the database schema (separate effort, post-refactor).
- Not rewriting the admin tools for billing (separate effort).
Every 'we should also...' gets logged but not done. If critical, separate ticket after the refactor.
Key Takeaways
- Strangler pattern, 12 months, 4 phases. No big-bang rewrite. Ship daily.
- Week 0 (characterization tests + measurement baseline) is non-negotiable. Skipping it is the #1 refactor killer.
- Feature flags are the entire safety net. Every route decision is a flag. Rollback in 1 minute.
- Parallel-run discrepancy is your early-warning system. Any >0.01% = rollback, root-cause, resume.
Common use cases
- Legacy codebase modernization (10+ year old systems)
- Monolith-to-microservices migration planning
- Framework / library upgrades (React class → hooks, jQuery → modern)
- Database schema refactoring with live data
- Removing deprecated APIs while users are on them
- Post-acquisition code integration
- Pre-scale-up cleanup of tech debt
Best AI model for this
Claude Opus 4 or Sonnet 4.5. Refactor strategy benefits from top-tier.
Pro tips
- Never 'just rewrite.' Rewrites fail 70%+ of the time. Strangle instead.
- Characterization tests FIRST. You need behavior locks before touching code.
- Ship the refactor in pieces small enough to deploy daily. Giant refactor branches die.
- Measure the refactor. Lines of code, cyclomatic complexity, test coverage before/after. Numbers prevent scope creep.
- Communicate to non-engineers in business terms. 'This saves 2 weeks/year of engineer time' beats 'reducing technical debt.'
- The first 20% of refactor delivers 60% of the value. Don't chase perfection.
Customization tips
- Start with the simplest payment method (Stripe, 80% of traffic). Don't start with the weirdest (legacy PayPal).
- If you can't explain the refactor in 3 sentences to the CEO, the scope is wrong. Cut until you can.
- Add an 'exit criteria' doc before starting. Clear definition of done prevents eternal refactor.
- Pair program during Phase 2 transitions. Two pairs of eyes on production-routing changes.
- Retrospective every month. What's working? What's not? Adjust scope/speed. 12-month refactors need mid-course corrections.
Variants
Monolith-to-Microservices
For architectural refactors. Extract strategy per service.
Framework Migration Mode
For library/framework version bumps. Component-by-component.
Database Schema Mode
For live-data schema refactors. Expand-migrate-contract pattern.
Frequently asked questions
How do I use the Refactoring Strategy Planner prompt?
Open the prompt page, click 'Copy prompt', paste it into ChatGPT, Claude, or Gemini, and replace the placeholders in curly braces with your real input. The prompt is also launchable directly in each model with one click.
Which AI model works best with Refactoring Strategy Planner?
Claude Opus 4 or Sonnet 4.5. Refactor strategy benefits from top-tier.
Can I customize the Refactoring Strategy Planner prompt for my use case?
Yes — every Promptolis Original is designed to be customized. Key levers: Never 'just rewrite.' Rewrites fail 70%+ of the time. Strangle instead.; Characterization tests FIRST. You need behavior locks before touching code.
Explore more Originals
Hand-crafted 2026-grade prompts that actually change how you work.
← All Promptolis Originals