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.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

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

💻DeveloppementIntermediateAll AIs

Perplexity Prompt for Creating a Software Architecture

Perplexity stands out as a particularly powerful tool for software architecture design thanks to its ability to synthesize recent and verified technical sources. Unlike a classic LLM that relies solely on its training data, Perplexity queries the web in real time to integrate the latest best practices, emerging architectural patterns, and community feedback. Whether you are designing a microservices architecture, a modular monolith, or an event-driven system, a well-structured prompt allows you to obtain contextualized recommendations with verifiable sources. The challenge is to provide enough business and technical context for Perplexity to cross-reference relevant information: technology stack, scalability constraints, infrastructure budget, and team skills. By phrasing your request precisely, you transform Perplexity into a true consultant architect capable of proposing component diagrams, reasoned technology choices, and deployment strategies tailored to your specific context.

475
💻DeveloppementAdvancedAll AIs

Kubernetes Backup Strategy

Kubernetes Disaster Recovery Plan

324
💻DeveloppementIntermediateAll AIs

Adapting an API for Different Clients

Tailoring API responses to client needs

371
💻DeveloppementAdvancedAll AIs

Implement cost optimization with Terraform

Reduce cloud infrastructure costs

369