One shared service helper for server calls; remove the pass-through use cases
Back to our planSummary
Thirteen small files in our modules (use-cases/) do nothing but pass a call straight to the database query beside them. The owner wants them gone, replaced by one light, shared way for server calls to run, using what Payload and Next.js already provide first, so error handling and logging live in one place and can grow later.
Details
Summary of the owner's direction (2026-10-31, voice session with Claude): build one centralized implementation that handles everything on the application side, as a very lightweight server service wrapper that more things can plug into later. He agreed to use Payload's and Next's built-in pieces first, and not to build a loading indicator or request interception until a slow service needs them.
Ladder (native first, docs/guidelines/development.md):
- Native: Payload's
afterErrorhooks (per collection and global) for CMS-side errors; Next.jserror.tsx/loading.tsxper route segment for the screens. Confirm against the Payload 3.91 and Next 16 docs before writing code, and record what each covers on this issue. - Our code, only for the gap: one small helper in
src/platform/that every use case runs through (for examplerunUseCase(name, fn)). It catches and logs a server failure without personal data (reusinglogServerFailure), returns the existingActionResultshape where a use case already does, and is the single place future concerns (timing, request IDs, retries) plug in. Typed, noany, its own tests.
Changes:
- Delete the 13 pass-through use cases (
findPostPage,findFaqEntries,findResources,listEventSlugs,findPostsAfter,findSearchResults,listPostPageNumbers,listPostSlugs,getFooterNav,getHeaderNav,getCurrentUser,signOutCurrentUser, and any other with no logic). Their module'sserver.tsexports the query or runs it through the shared helper instead. - Use cases that do real work (for example
changeOwnPassword) move onto the shared helper, so their try/catch-and-log isn't repeated. - Update
docs/architecture/(where code goes, the layer rules) and the lint boundary rules if they require a use case for every read. Changing the architecture rule is the owner's decision recorded above.
Not in scope: a client-side request interceptor or a global loading indicator.
Acceptance criteria
- The pass-through use-case files are gone, and every page still gets its data the same way (no behaviour change, tests unchanged or updated).
- One shared helper handles catching and logging for use cases; no use case repeats its own try/catch-and-log.
- Payload's error hook and Next's error and loading pages are used where they fit, as recorded on the issue.
- Lint boundary rules and
docs/architecture/match the new rule; knip reports nothing unused.
Generated by Claude Code, opens in a new tab