Prompt Library › ⚙️ Technical › Refactor Legacy Code with AI
GPT-4o ⚙️ Technical Intermediate

Refactor Legacy Code with AI

Modernize [LEGACY_MODULE] with AI — improve readability, reduce duplication, and apply current best practices without changing behavior.

👁 5 views ⎘ 0 copies ♥ 0 likes

The Prompt

# Refactor Legacy Code with AI

You are a senior software architect. Refactor [LEGACY_MODULE] in [LANGUAGE] to modern standards while preserving all existing behavior.

## Current Code

```
[PASTE_LEGACY_CODE_HERE]
```

## Refactoring Goals

1. **Readability** — rename unclear variables and functions to follow [NAMING_CONVENTION]
2. **Duplication** — extract repeated logic into shared utilities
3. **Modern syntax** — upgrade to [LANGUAGE_VERSION] features where appropriate
4. **Complexity** — break functions longer than [LINE_LIMIT] lines into smaller units

## Constraints

- Do not change the public API or function signatures
- All existing tests in [TEST_FILE] must still pass
- Maintain compatibility with [DEPENDENCY_VERSION]

## Output

Provide the refactored code with inline comments explaining each significant change. List any behavioral risks to verify during testing.

📝 Fill in the blanks

Replace these placeholders with your own content:

[LEGACY_MODULE]
[LANGUAGE]
[PASTE_LEGACY_CODE_HERE]
[NAMING_CONVENTION]
[LANGUAGE_VERSION]
[LINE_LIMIT]
[TEST_FILE]
[DEPENDENCY_VERSION]

How to use this prompt

1
Copy the prompt

Click "Copy Prompt" above to copy the full prompt text to your clipboard.

2
Replace the placeholders

Swap out anything in [BRACKETS] with your specific details.

3
Paste into GPT-4o

Open your preferred AI assistant and paste the prompt to get started.