P
💻DeveloppementAdvancedAll AIs

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 :

  1. 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).

  2. 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.

  3. 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é
  4. Tests de sécurisation : Pour chaque étape, propose les tests unitaires à écrire AVANT de refactorer pour garantir la non-régression.

  5. Code refactoré final : Fournis la version complète du code modernisé avec des commentaires expliquant les choix architecturaux.

  6. 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

Modernize an inherited codebase before adding new featuresPrepare a technical audit by identifying and fixing code smellsProgressively migrate procedural code to object-oriented or functional architecture

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 Optimizer

Comments

  • 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

💻DeveloppementIntermediateAll AIs

NetworkPolicies for micro-segmentation

Isolate workloads with network policies

061
💻DeveloppementIntermediateClaude

Prompt Claude to Create a Prototype

Creating a prototype is a crucial step in developing a product, application, or service. Traditionally, this phase requires a variety of technical skills, time, and often a multidisciplinary team. With Claude, you can significantly accelerate this process by generating functional prototypes from a simple description of your idea. Whether you want to design an interactive user interface, a web application mockup, an API prototype, or even a technical proof of concept, Claude can produce functional code, HTML/CSS wireframes, or complete architectures ready to be tested. The major advantage is Claude's ability to iterate quickly: you describe your vision, get a first prototype, then refine through successive exchanges until you get exactly what you're looking for. This approach democratizes rapid prototyping and allows entrepreneurs, designers, and product managers to validate their hypotheses without fully relying on a development team in the early stages of the project.

093
💻DeveloppementAdvancedChatGPT

Optimize Slow SQL Queries

Analyze and optimize your slow SQL queries through execution plan analysis and precise index recommendations.

38344
💻DeveloppementIntermediateAll AIs

Sora Prompt for Debugging Code

Sora, OpenAI's video generation model, may seem like a surprising choice for debugging code. Yet its ability to produce dynamic visualizations opens up unique perspectives for understanding and resolving complex bugs. By generating visual representations of execution flow, data structures, or interactions between components, Sora allows developers to literally see their code's behavior. This visual approach is particularly effective for bugs related to user interfaces, animations, state transitions, or rendering issues. Instead of sifting through endless logs, you can ask Sora to create a video illustrating expected versus observed behavior, making problem identification easier. The prompts on this page guide you in using Sora for debugging, turning textual bug descriptions into clear visualizations that accelerate resolution. Whether you're working on front-end, visual algorithms, or complex data flows, these techniques help you adopt a visual debugging approach.

063