Refactoring with AI Assistance
Cursor AI excels at refactoring — it sees the whole codebase and can suggest architectural improvements.
Common Refactoring Commands
Extract Component
Select a section of JSX, press Cmd+K, type:
"Extract this into a separate component file called [Name]. Keep the same props interface."
Split Large File
In Composer:
"This file is 500 lines. Break it into smaller components: extract the form into FormSection, the list into ListSection, and the filters into FilterBar."
Improve Naming
"Audit this file for unclear variable and function names. Rename anything that isn't immediately obvious."
Reduce Complexity
"This function has too many conditions. Refactor it to be simpler — use early returns, extract helper functions, or use a lookup pattern."
Refactoring Workflow
- Write tests first (if you have them) or at minimum, note expected behavior
- Refactor with Cursor
- Run tests / manually verify
- Commit each refactoring step separately
