1.3 KiB
1.3 KiB
@repo/cms-core — Payload CMS Definition
All Payload configuration lives here: payload.config.ts, collections, globals, hooks, access control. The apps/cms app is a thin shell that imports this config.
Hook Rules
| Category | Location | Examples |
|---|---|---|
| CMS-operational | Stay in hook | Slugify, image resize, default values |
| Business logic | Delegate to use case | Notifications, validation, cross-domain updates |
DO
- Keep hooks thin (max 5-10 lines)
- Import use cases from
@repo/core/application - Map Payload hook args to use case input types
DON'T
- Import from
@repo/core/infrastructure - Put business validation in hooks
- Call external services directly from hooks
- Duplicate logic that exists in a use case
Adding a New Collection
- Create folder:
src/collections/{name}/ - Create:
index.ts(CollectionConfig),fields.ts - Optionally:
hooks/,access/ - Import in
src/payload.config.tscollections array - Export from
src/index.ts
Adding a Hook That Calls a Use Case
- Create
src/collections/{name}/hooks/{hook-name}.ts - Import use case from
@repo/core(application layer only) - Map Payload's hook args to use case input
- Call use case, return data
Rule of thumb: If deleting the hook would break a business requirement, the logic must be in a use case.