About controller-cleanup
A Symfony development skill for simplifying controllers by moving business logic and related responsibilities into dedicated components. It emphasizes preserving HTTP behavior and verifying the refactor with functional tests.
Key features
- 01Inventory controller responsibilities
- 02Test HTTP behavior before refactoring
- 03Map requests to validated DTOs
- 04Extract services, voters, and handlers
- 05Delegate from lean controller actions
- 06Use invokable console commands
Use cases
- 01Refactor actions containing business logic
- 02Separate validation and authorization from persistence
- 03Make console commands delegate to shared services
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ dev-toolings/ superpowers-symfony --skill controller-cleanupAfter installing, type/controller-cleanupin Claude Code to confirm it loaded.
Bundled filesreference.md
Details
From the project READMEController Cleanup (Symfony)
Use when
- A controller action holds business logic, queries, or more than a handful of lines.
- Input parsing, validation, authorization and persistence are mixed in one action.
- A console command does the real work itself instead of delegating it.
Default workflow
- List what the action does: input, validation, authorization, business logic, persistence, side effects.
- Cover the current HTTP behavior with a functional test before moving anything.
- Map input to a DTO with
#[MapRequestPayload]or#[MapQueryString]and let the validator reject it. - Move business logic into a service or a command handler, authorization into a voter, side effects into events or messages.
- Leave the action to resolve, authorize, delegate and respond, in five to ten lines.
Guardrails
- Type-hint services as arguments or constructor parameters; never pull them from the container.
- Keep the HTTP behavior identical: same status codes, same payloads.
- Do not move the logic into a "manager" that is the old controller under a new name.
- Write console entry points as invokable
#[AsCommand]classes (Symfony 7.3+) that delegate to the same services.
Progressive disclosure
- Use this file for execution posture and risk controls.
- Open references when deep implementation details are needed.
Output contract
- Lean actions that delegate.
- The extracted DTOs, services, voters or handlers, one responsibility each.
- Functional tests showing the HTTP behavior is unchanged.
References
reference.md
Comments
Markdown supported