Skip to content
SprecherEast
Issue 130

tech-debt: Guard module boundaries (lint warnings, server-only, explicit access checks)

Back to our plan
Done
cmstoolingtech-debtpriority: medium

Type

tech-debt

Summary

Add automatic checks that keep each part of the code in its lane: pages may not reach into the database directly, browser code may not import server code, and one business area may not reach into another's internals. They start as warnings so nothing breaks while code moves.

Problem

Nothing enforces structure today. 10 page and route files query Payload directly, the server-only package isn't used, and some Local API reads rely on Payload's default of skipping access control ("In the Local API, all Access Control is skipped by default", https://payloadcms.com/docs/access-control/overview, opens in a new tab). The redirect-target lookup (utilities/getDocument.ts) is one of them.

Proposed fix

  • Add eslint-plugin-boundaries with element types for app, modules/* (entry files and internals), platform, and today's folders, configured as warnings. Use its dependencies rule (https://www.jsboundaries.dev/docs/rules/dependencies, opens in a new tab).
  • Add server-only to files that run Payload queries (utilities/feeds.ts, getDocument.ts, getGlobals.ts, getRedirects.ts, and similar).
  • Set overrideAccess explicitly on every Local API read; make getDocument respect access rules.
  • Create the empty src/modules/ and src/platform/ folders with a README each, and the @/modules/* and @/platform/* path aliases.

Acceptance criteria

  • Not done: ESLint reports boundary violations as warnings; CI stays green.
  • Not done: Importing a server-only file from a client component fails the build (checked once locally and noted in the PR).
  • Not done: Every payload.find, findGlobal and findByID call passes overrideAccess explicitly.
  • Not done: No visible change on the site.

Depends on

#129 (tests). Step 5 of #127.

Area

tooling, cms

Priority

medium


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab