Refactor Legacy Code Step by Step
This prompt guides AI to analyze legacy code and produce a structured refactoring plan with diagnosis, prioritization, tests, and modernized code.
Paste in your AI
Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.
Tu es un architecte logiciel senior spécialisé en refactoring et modernisation de code. Analyse le code legacy suivant écrit en [LANGAGE] et propose un plan de refactoring complet.
Code à refactorer :
[CODE_LEGACY]
Contexte du projet : [CONTEXTE_PROJET]
Contraintes techniques : [CONTRAINTES] (ex : ne pas casser l'API publique, compatibilité ascendante, budget temps limité)
Procède en suivant ces étapes :
-
Diagnostic : Identifie tous les code smells présents (God class, fonctions trop longues, couplage fort, nommage obscur, duplication, responsabilités mélangées, etc.). Classe-les par sévérité (critique, majeur, mineur).
-
Analyse des risques : Pour chaque problème identifié, évalue le risque de régression si on le corrige. Indique les zones fragiles qui nécessitent des tests avant toute modification.
-
Plan de refactoring priorisé : Propose un plan étape par étape, ordonné par priorité et par dépendance. Pour chaque étape :
- Décris la transformation à appliquer (Extract Method, Move Class, Replace Conditional with Polymorphism, etc.)
- Montre le code avant/après
- Justifie pourquoi cette transformation améliore la qualité
-
Tests de sécurisation : Pour chaque étape, propose les tests unitaires à écrire AVANT de refactorer pour garantir la non-régression.
-
Code refactoré final : Fournis la version complète du code modernisé avec des commentaires expliquant les choix architecturaux.
-
Métriques d'amélioration : Compare avant/après sur : complexité cyclomatique, nombre de lignes, couplage, cohésion, lisibilité estimée.
Utilise les principes SOLID, les design patterns appropriés, et les conventions modernes du langage [LANGAGE].
Personalize this prompt with Léa
Answer 3 questions and Léa tailors the prompt to your situation.
Why this prompt works
<p>This prompt is designed to obtain methodical and professional legacy code refactoring. By providing the <strong>language</strong>, <strong>source code</strong>, <strong>project context</strong>, and <strong>technical constraints</strong>, you enable the AI to produce a tailored analysis rather than generic advice.</p><p>The 6-step structure reproduces an experienced architect's approach: first understand the problems (diagnosis and code smells), then assess risks before acting, then plan transformations in the right order, and finally secure each step with tests. This progressive approach <strong>minimizes regression risks</strong> while measurably improving code quality.</p><p>For best results: provide a sufficiently complete code excerpt for clear context, specify real constraints (public API to preserve, deadline, external dependencies), and if the code is very long, break it into modules and submit them one at a time.</p>
Use Cases
Expected Output
A structured report containing code smell diagnosis classified by severity, a prioritized refactoring plan with before/after code for each step, security unit tests, the final modernized code, and a quality metrics comparison table.
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- LéaAI
Ajoute une étape 0 : génère d'abord des tests de caractérisation (golden master) pour chaque bloc non testé. Cela sécurise le refactoring et affine le diagnostic. Pour un code très volumineux, découpe-le en plusieurs modules distincts et traite-les un par un.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Stable Diffusion Prompt to Create a Software Architecture
Stable Diffusion offers fascinating possibilities for visualizing abstract concepts like software architecture. By combining precise technical terms with suitable visual directives, it becomes possible to generate stylized diagrams, infrastructure schemas, and visual representations of complex systems. Whether you are a developer looking to illustrate technical documentation, a software architect preparing a presentation, or a trainer aiming to make abstract concepts tangible, Stable Diffusion can transform your text descriptions into impactful visuals. The tool particularly excels at creating conceptual illustrations showing interactions between components, data flows, and abstraction layers. While Stable Diffusion does not replace traditional UML diagramming tools, it brings an artistic and instantly understandable dimension to your architectures, ideal for executive presentations, technical blog posts, or training materials. The key lies in crafting prompts that balance technical precision with visual vocabulary the model masters.
Implement pipeline as code testing
Test CI/CD pipelines
Design a Complete REST API
Design a robust and well-structured REST API with OpenAPI documentation, error handling, and security best practices.
Learn Git Basics for Beginners
Learn Git from scratch with illustrated explanations, concrete examples, a practical workflow, and an essential commands cheatsheet.