Refactor while preserving contracts | DevPrompt Lab

Improve a module in small steps without changing its public behavior.

prompt · Refactoring · intermediate

English Tiếng Việt

A safe refactoring prompt that inventories contracts first and keeps each change reviewable.

Reusable content

Refactor the named module to address the stated maintenance problem. Before editing, identify public APIs, serialized data shapes, routes, database behavior, and callers that must remain compatible. Prefer small changes with one clear purpose. Keep domain rules out of UI code and avoid broad rewrites. Add or update focused tests for preserved behavior. After the change, summarize the files changed, compatibility impact, and checks actually run. Stop if the requested goal requires a breaking change and explain the choice.

Module: {{MODULE}}

Maintenance problem: {{PAIN_POINT}}

Contracts to preserve: {{CONTRACTS}}

Test command: {{TEST_COMMAND}}

How to use it

Provide the supported contract and a narrow module boundary. Keep unrelated formatting out of the diff.

Example

Preserved: POST /api/v1/user/projects still returns the existing response envelope. Changed: validation extracted into a domain helper.