Skip to content
SprecherEast
Issue 127

Epic: Reorganize the code into business modules

Back to our plan
Open
frontendcmstoolingtech-debtpriority: high

Type

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:

  1. Not done: #128 Architecture map, conventions, glossary, data model; fix stale docs
  2. Not done: #129 Vitest and unit tests for existing rules
  3. Not done: #138 Agent skills: code placement, reuse first, writing tests; architecture checks in PR review
  4. Not done: #120 Upgrade to a Payload-supported Next.js 16.3.x (due about Nov 18)
  5. Not done: #130 Boundary rules as warnings, server-only, explicit access checks
  6. Not done: #131 Events module
  7. Not done: #132 News module
  8. Not done: #133 Contact module
  9. Not done: #134 Accounts module
  10. Not done: #135 Site module and shared platform
  11. Not done: #136 Directory module (can run in parallel with 5–8)
  12. Not done: #137 Boundary rules become errors; max-lines 250

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

See it on GitHub, opens in a new tab