Prompt file imported from jimzandueta/nestjs-http-server-boilerplate-codex-ai-assisted (
.codex/prompts/refactor.md). Fill in{{TARGET_FILES_OR_MODULES}},{{GOAL}},{{TRANSFORMATION}},{{CONSTRAINTS}}before use. Copyright stays with the author.
Prompt: Refactor
Inputs
- Target code: {{TARGET_FILES_OR_MODULES}}
- Refactoring goal: {{GOAL}} (reduce duplication, simplify logic, improve testability, etc.)
- Transformation type: {{TRANSFORMATION}} (extract function, move file, rename, simplify conditional, etc.)
- Constraints: {{CONSTRAINTS}} (preserve public API, backward compatibility, etc.)
Instructions
- Follow
.codex-generic/RULES.md. - Read
memory/learned-patterns.md— understand existing conventions before changing structure. - Read
memory/decisions.md— check if the current structure was an intentional choice. - Ensure test coverage first: Verify tests exist for the code being refactored. Add tests if coverage is insufficient.
- Plan the change: List all files to modify. Identify all callers/importers of affected code.
- One transformation at a time: Don't mix extract + rename + move.
- Preserve behavior: No functional changes — the test suite must produce identical results.
- Apply incrementally: Make small steps. Run tests after each step.
- Run
checklists/pre-commit.mdbefore finishing. - Document the new pattern in
memory/learned-patterns.md.
Refactoring Operations
| Operation | Risk | Key Check |
|---|---|---|
| Extract function | Low | Tests still pass, no behavior change |
| Extract module | Medium | All importers updated, no circular deps |
| Rename | Low | All references updated, naming follows convention |
| Inline | Low | Removing abstraction doesn't lose clarity |
| Move file | Medium | All importers updated, directory follows convention |
| Simplify conditional | Medium | All branches still covered by tests |
Patterns to Consult
patterns/naming.md— naming conventions for renamed/extracted codepatterns/repo-structure.md— directory placement for moved/extracted modulespatterns/dependency-management.md— if restructuring changes import graphsmemory/learned-patterns.md— existing patterns to align with