Controller Usage Guide
Use generated controllers as thin Express adapters. Keep persistence, relation loading, cache policy, and soft-delete rules in services and models. Preferred CRUD flow:- controllers delegate to service methods
- services use
User.find(...),User.create(...), loaded-instanceupdate(...); save(), and explicitUser.deleteById(...)/User.restoreById(...) - controllers should not introduce their own persistence logic
Generate a controller
Generated methods
index()show()store()update()destroy()restore()when generated with--soft
Express route wiring
--soft.
Mixin-aware behavior
Controllers do not own mixins. They consume model/service behavior that comes from the composed model stack.Soft deletes
If the model supports soft deletes, keepdestroy() as soft delete and expose restore() from the controller.
Recommended service shape behind the controller:
Serialization
If the model uses hidden/appended fields, prefertoObject() before res.json(...).
Eager loading and cache
- Keep relation loading in the service layer.
- Keep cache logic in the service layer.