codingrefactoring
Legacy Code Refactoring Plan
Analyses legacy code and produces a step-by-step refactoring plan with before/after examples and risk assessment.
Prompt
You are a senior engineer specialising in legacy code modernisation for [industry] applications. The goal is to improve maintainability without breaking existing functionality. The target audience for this plan is the development team. Analyse the following [language] code and create a step-by-step refactoring plan. Format the output as a structured numbered list. For each step, provide: (1) what to change and why — name the code smell (e.g. 'God class', 'primitive obsession', 'shotgun surgery'), (2) the refactoring technique to apply (such as 'Extract Method', 'Replace Conditional with Polymorphism'), (3) before and after code snippets in a formatted code block, (4) risk level (low/medium/high) and what could break, (5) how to verify — a specific test to write, for example 'assert that calculateTotal(items) returns the same value before and after the refactor'. You must order the steps from lowest risk to highest risk. Avoid suggesting a complete rewrite — only work incrementally. Do not change the public API unless absolutely necessary. Only include 5-8 steps, each independently deployable. Mark any step that changes the public API. Here is the code:\n\n```[language]\n[PASTE CODE HERE]\n```
refactoringlegacy codecode smellsclean codemodernisationChatGPT / Claude
Build a prompt like this for your task
Use the free guided prompt builder on the homepage — pick what you need, answer three quick questions, and get a high-scoring prompt of your own.
Open the prompt builder →100
out of 100
Role definition100
Task clarity100
Specificity100
Context100
Output format100
Constraints100
Examples100
More coding prompts
coding100
Code Review Feedback Generator
Reviews code for bugs, performance, security, readability, and best practices with specific line-by-line feedback.
code reviewbest practicessecurity
coding100
REST API Endpoint Designer
Designs RESTful API endpoints with routes, methods, request/response schemas, auth, and error codes.
REST APIAPI designbackend
coding100
Database Schema Designer
Designs a normalised database schema with tables, relationships, indexes, and migration SQL for a given domain.
databaseschema designSQL