P
💻DeveloppementAdvancedChatGPT

Legacy Code Refactoring

Safely and incrementally refactor legacy code following SOLID principles and modern best practices.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert en refactoring et en amélioration de code legacy. Voici un morceau de code [LANGAGE] écrit il y a [ANCIENNETÉ] qui doit être modernisé :

[COLLER_LE_CODE_LEGACY]

Contexte du projet :

  • Framework actuel : [EX: Express 4, Django 3]
  • Version cible après refactoring : [EX: Express 5, Django 5]
  • Contraintes : [EX: pas de changement d'API publique, tests existants doivent passer]
  • Dette technique identifiée : [DESCRIPTION_OPTIONNELLE]

Effectue le refactoring en plusieurs étapes :

Étape 1 - Analyse : Identifie les anti-patterns, la duplication de code, les responsabilités multiples (violation du SRP), les dépendances cachées et les risques de régression.

Étape 2 - Stratégie : Propose un plan de refactoring incrémental qui permet de tester chaque étape indépendamment. Identifie les étapes critiques et les points de rollback.

Étape 3 - Code refactorisé : Produis le code refactorisé complet avec des commentaires expliquant chaque changement important. Respecte les principes SOLID et les patterns appropriés.

Étape 4 - Tests : Fournis des tests unitaires pour valider que le comportement est préservé après refactoring.

100% found this useful

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 approach refactoring as a methodical process rather than a haphazard rewrite. The decomposition into four distinct steps (analysis, strategy, code, tests) ensures the AI doesn't jump straight to code without understanding the constraints and risks.</p><p>Mentioning specific constraints (API compatibility, existing tests) is crucial as it forces the AI to produce a realistic and deployable refactoring, not a theoretically ideal code that would break backward compatibility.</p><p>Requesting validation tests in addition to the refactored code is a best practice that transforms this prompt into a retrospective TDD tool, securing each refactoring step with an automated test suite.</p>

Use Cases

Legacy project modernizationTechnical debt reductionMigration to new frameworks

Expected Output

A problem analysis, an incremental refactoring plan, the refactored code, and validation unit tests.

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

    Insère une étape 0 : tests de caractérisation du code legacy avant toute modification. L'étape 4 arrive trop tard — sans baseline, une régression à l'étape 3 est indétectable. Ajoute aussi la consigne : génère uniquement un diff par micro-étape plutôt que le fichier complet refactorisé, sinon le contexte sature dès 300 lignes de code legacy et tu perds la cohérence du plan incrémental.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

091
💻DeveloppementIntermediateAll AIs

Refactor legacy code to modern patterns

Gradually modernizing legacy code

0102
💻DeveloppementAdvancedAll AIs

PCI-DSS or SOC2 Compliance

Preparing for regulatory compliance

081
💻DeveloppementBeginnerAll AIs

Encryption at rest and in transit

Securing data at rest and in transit

083