$ recombobulate _
home / tips / ask-claude-to-extract-logic-from-a-fat-controller
0

Ask Claude to Extract Logic from a Fat Controller

bagwaa @bagwaa · Mar 26, 2026 · Workflows
ask-claude-to-extract-logic-from-a-fat-controller

Controllers should orchestrate, not implement. When a controller method grows past 50 lines it's usually doing too much — and Claude can refactor it cleanly.

This controller method is doing too much. Extract the business logic into a dedicated
OrderService class. The controller should only handle HTTP concerns: parsing the
request, calling the service, and returning the response. Move validation, database
writes, email dispatch, and event firing into the service.

Claude identifies the HTTP concerns (request parsing, response formatting) and separates them from the business logic (calculations, persistence, side effects), producing a clean service class with a single public method.

Ask it to go further:

Now make OrderService testable in isolation. Replace direct model calls with a
repository interface, and inject the mailer as a dependency so we can mock it
in tests.

Claude will introduce the interface, update the service constructor, and update the service container binding — making the whole thing unit testable without hitting the database.

If you have multiple fat controllers, point Claude at the whole directory:

Look at all controllers in app/Http/Controllers and identify the top 3 that have
the most business logic mixed in. List the methods and what they're doing.

That gives you a prioritised refactoring backlog without reading a single file yourself.

A fat controller is a symptom, not a sin — Claude turns the diagnosis into a diff.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Scan Pending Changes for Security Issues with /security-review

The /security-review command scans your uncommitted changes for injection vectors, auth gaps, hardcoded secrets, and other common vulnerabilities.

bagwaa @bagwaa · 1 hour ago
0
Run Setup Scripts on Every Session with the SessionStart Hook

The SessionStart hook fires when any session begins or resumes, making it ideal for loading environment variables and running one-time setup scripts.

bagwaa @bagwaa · 1 hour ago
0
Write Property-Based Tests with fast-check and Claude

Ask Claude to write property-based tests for your functions using fast-check — it identifies the mathematical invariants in your code and generates tests that cover inputs you'd never enumerate by hand.

bagwaa @bagwaa · 2 hours ago