Skip to main content

Runtime Services

Services are the main application boundary for runtime behavior.

Core service rule

Services should own:
  • CRUD orchestration
  • query composition
  • eager loading decisions
  • soft-delete restore flows
  • cache reads and invalidation
Controllers should delegate to services. Services should delegate to models.

Query composition

load() and with() require explicit relation methods on the model instance.

Soft deletes

Use service methods to centralize soft-delete behavior:
  • restore flows
  • trashed views
  • force-delete boundaries
The service layer is where recovery policy belongs.

Hooks, casts, scopes, and serialization

  • hooks fire through normal create/update/delete paths
  • casts normalize model values before the service consumes them
  • scopes keep repeated query rules named and reusable
  • serialization should be normalized in or just before the service response boundary

Cache

Keep cache at the service boundary:

Driver note

The service surface stays the same for SQL and Mongo models. Keep ids typed as number | string and let the model choice control driver behavior.