Epic: Reorganize the code into business modules
Back to our planType
tech-debt
Summary
Reorganize the website's code so each business area (events, news, contact, accounts, reference content, site pages) has one home, each rule is written and tested once, and pages never talk to the database directly. Done in small steps, one pull request each; visitors see no change. Phase 2 (#122) is built on top of it.
Problem
An architecture review on 2026-10-19 (main at 190cb3d) found the code tidy at file level (median 43 lines, strict TypeScript) but organized by technical type, as inherited from Payload's website template:
- each business area is spread across 5 to 7 folders;
- 10 page and route files query Payload directly;
- the "upcoming event" rule is written in 3 files, category labels are copied 4 times (events twice, FAQ, resources), the "next 3 events" query twice;
- the data layer takes its types from UI components, and two shared components import page-level server actions;
- there are no automated tests;
- docs describe parts of the stack that no longer exist.
Proposed fix
Move to a modular monolith: src/modules/<area>/ with domain/ (pure rules), data/ (server-only queries over Payload's Local API), cms/ (collections and hooks), ui/, and two entry files (index.ts client-safe, server.ts server-only); src/platform/ for cross-cutting code; src/app/ for routes only. Rules enforced by ESLint (eslint-plugin-boundaries) and server-only. This follows the Next.js recommendation of a Data Access Layer for new projects (https://nextjs.org/docs/app/guides/data-security, opens in a new tab). No generic repository layer: Payload's Local API is already typed.
Process groundwork, in parallel with steps 1–3: #126 (issue forms and PR templates with a plain-language Summary, technical details, and how to test and validate). Agent guardrails: #144 (lean context with progressive disclosure), #145 (automated checks while editing, at commit, in CI and at review). Theme separation: #146 (pluggable themes), alongside the module moves.
Steps, in merge order:
- Not done: #128 Architecture map, conventions, glossary, data model; fix stale docs
- Not done: #129 Vitest and unit tests for existing rules
- Not done: #138 Agent skills: code placement, reuse first, writing tests; architecture checks in PR review
- Not done: #120 Upgrade to a Payload-supported Next.js 16.3.x (due about Nov 18)
- Not done: #130 Boundary rules as warnings,
server-only, explicit access checks - Not done: #131 Events module
- Not done: #132 News module
- Not done: #133 Contact module
- Not done: #134 Accounts module
- Not done: #135 Site module and shared platform
- Not done: #136 Directory module (can run in parallel with 5–8)
- Not done: #137 Boundary rules become errors;
max-lines250
Acceptance criteria
- Not done: Every step above is merged.
- Not done:
docs/architecture/describes the code as it is. - Not done: Boundary rules are errors, and CI is green.
Area
frontend, cms, tooling
Priority
high
Generated by Claude Code, opens in a new tab
Issues in this epic
- documentation: Architecture map, conventions, glossary and data model; fix stale docs (issue 128)Done
#128 · Closed Oct 20
#129 · Closed Oct 20
#138 · Closed Oct 21
#120 · Closed Oct 21
- tech-debt: Guard module boundaries (lint warnings, server-only, explicit access checks) (issue 130)Done
#130 · Closed Oct 21
- tech-debt: Events module: one home for event code, one upcoming rule, one category list (issue 131)Done
#131 · Closed Oct 22
#132 · Closed Oct 22
#134 · Closed Oct 22
#135 · Closed Oct 22
#136 · Closed Oct 22
#137 · Closed Oct 22
#521 · Closed Oct 31
#531
- tech-debt: Explicit overrideAccess in the seed, and read the nav globals as a visitor (issue 251)Open
#251
#253
#254
#230
#295
#322
- tech-debt: Fix the 9 places that break the React Compiler lint rules, then turn them on (issue 193)Open
#193
#625
#617
#618 · Closed Nov 3
#615
#616 · Closed Nov 3
#622 · Closed Nov 3
#614
#87 · Closed Aug 27
#753 · Closed Nov 6
#220 · Closed Oct 22
#836
#843