$ recombobulate _
home / tips / let-claude-implement-the-repository-pattern-in-your-codebase
0

Let Claude Implement the Repository Pattern in Your Codebase

bagwaa @bagwaa · Mar 26, 2026 · Workflows
let-claude-implement-the-repository-pattern-in-your-codebase

Direct Eloquent calls scattered across controllers make code hard to test and even harder to swap out later. The Repository pattern fixes this — and Claude can retrofit it onto existing code without breaking anything.

Show Claude a controller that's doing too much and ask it to extract a repository:

Refactor this controller so all database access goes through a repository.
Create a UserRepositoryInterface and an EloquentUserRepository implementation.
Bind the interface in a service provider. Keep the controller thin.

@app/Http/Controllers/UserController.php

Claude will generate the interface, the Eloquent implementation, update the service provider, and inject the repository into the controller via the constructor — complete with updated tests that mock the interface rather than hitting the database.

For bigger refactors, ask Claude to do one model at a time and generate the full set of files:

Create a repository for the Order model. Include methods for: 
findById, findByUser, findPendingOlderThan(Carbon $date), and save.
Write a mock in tests/Fakes/ that I can use in unit tests.

Repositories are most valuable as seams for testing — having Claude generate them means you get the interface, implementation, and test fake in one go.

~/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