tech-debt: Guard module boundaries (lint warnings, server-only, explicit access checks)
Back to our planType
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-boundarieswith element types forapp,modules/*(entry files and internals),platform, and today's folders, configured as warnings. Use itsdependenciesrule (https://www.jsboundaries.dev/docs/rules/dependencies, opens in a new tab). - Add
server-onlyto files that run Payload queries (utilities/feeds.ts,getDocument.ts,getGlobals.ts,getRedirects.ts, and similar). - Set
overrideAccessexplicitly on every Local API read; makegetDocumentrespect access rules. - Create the empty
src/modules/andsrc/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-onlyfile from a client component fails the build (checked once locally and noted in the PR). - Not done: Every
payload.find,findGlobalandfindByIDcall passesoverrideAccessexplicitly. - 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