ProcessComposable · Yields to: Voice, Density, Craft
Refactor
Restructure messy, monolithic, or legacy codebases into clean, modular structures.
When to Use
- User says "refactor my project", "clean up my code", "split this file"
- Legacy code needs modernization
- Monolith needs to be broken into modules
Triggers
"refactor my project", "clean up my code", "split this file",
"restructure my files", "modularize this"Examples
Example 1
Split a monolithic file
Break a 2000-line file into focused modules.
Before: server.js (2000 lines — routes, middleware, DB, utils)
After /refactor:
server/
├── index.js # App setup and listen
├── routes/
│ ├── users.js # User routes
│ ├── auth.js # Auth routes
│ └── health.js # Health check
├── middleware/
│ ├── auth.js # Auth middleware
│ ├── rateLimit.js # Rate limiting
│ └── errorHandler.js
├── db/
│ ├── connection.js # DB connection
│ └── models/ # Data models
└── utils/
└── logger.js # Structured loggingExample 2
Refactor then harden pipeline
Clean structure first, then add production patterns.
/refactor → /harden
Refactor splits the monolith into clean modules.
Harden adds: rate limiting per route, graceful shutdown
in index.js, health checks, error boundaries per module,
structured logging, input validation.Example 3
Modernize legacy code
Update old patterns to current idioms.
/refactor modernize this callback-based code to async/await
The agent:
- Converts callback chains to async/await
- Replaces var with const/let
- Updates require() to import (if ESM target)
- Extracts reusable utility functions
- Adds proper error handling with try/catch