Glossary

Repository Pattern

Repository is a pattern that isolates business logic from data storage details. Instead of writing SQL queries or accessing the ORM directly in services, all database interaction is encapsulated in a dedicated repository class.

What it provides

Basic structure

interface UserRepository {
  findById(int $id): ?User;
  save(User $user): void;
}

class SqlUserRepository implements UserRepository { ... }

When not needed

In small CRUD applications, a Repository is over-engineering. It is justified when business logic is complex and independence from the data source matters.