Explain the Repository Pattern in the context of Clean Architecture.
Updated Apr 28, 2026
Short answer
The Repository Pattern mediates between the domain and data mapping layers using a collection-like interface.
Deep explanation
In CA, the Repository interface lives in the Domain/Use Case layer (Inner), and the implementation lives in the Infrastructure layer (Outer). This abstracts away the complexity of data access and ensures the domain doesn't know about SQL, ORMs, or APIs.
Real-world example
Using an In-Memory repository for unit tests and a PostgreSQL repository for production.
Common mistakes
- Naming repository methods after SQL terms (e.g., 'execQuery') instead of domain terms (e.g., 'findAllActive').
Follow-up questions
- Should a Repository return DTOs or Entities?