SVR Pattern

SVR(service, validator & repository) is a lightweight CRUD Service pattern.


The Philosophy

The idea is to have an easy to understand, flexible, testable pattern that follows the single responsibility principle.


S = Service

The service is the main access point. You can look at it as the main API. It's responsibility is to orchestrate the behaviour between the validator, repository and other resources/services.


V = Validator

The validator is used for doing all the validation. It should not have any side effects.


R = Repository

The repository is the data layer. It's role is to get, add, update and delete data.


Dependencies

To prevent circular dependencies and to keep the code DRY. It is important to follow these dependency rules.

ServiceCan depend on Validator & Repository
ValidatorCan depend on Repository
RepositoryCan depend on None

Testability

By having orchestration, validation and CRUD operations separated in differnet classes makes each class much easier to test since you only have to focus on one thing when testing each class.