documentation: Knowledge note for the shared Payload setup and helpers (platform/payload, lib, seo, email, turnstile, service)
Back to our planType
documentation
Summary
Write the short note on the code every module shares: roles and who may read or write what, drafts and scheduled publishing, the review queue for suggestions, paging, cache refreshes, the background jobs, and the helpers for email, the robot check, links, dates, rate limits and search-engine metadata.
Problem
Every collection is built from these helpers, so the rules a reader sees on a module (staff see drafts, suggestions wait as drafts, publishes are scheduled, limits are counted in memory) are actually defined here. Today the only way to learn them is to read about 80 files.
What the generated reference already shows, so the note doesn't repeat it: The content-type pages show where each access function and hook is defined (many in src/platform/payload/), for example isAdminOrSelf on users, holdSuggestions on posts and events, and the jobs collections and globals. Missing: what each shared rule means and which modules use it.
Proposed fix
Write src/platform/payload/README.md from the template. Owner's direction for every note (2026-11-06, Claude session, recorded on #712 and #719): a note explains the behavior and logic of its content types and code (what shows, where, when, who publishes or changes it, and the special rules), never a list of fields; and every link between fields is stated near the top, so no agent has to work it out from the code.
Links between fields the note states up front (each one checked in the code first):
REVIEW_QUEUE_FIELDS(source, who it's for, review status,externalId,contentHash) are added to events and posts;holdSuggestionssetssuggestedand a draft for non-staff creates, and staff publishing approves; Admin's Duplicate copies no suggestion identity (reviewQueue.ts,admin/SuggestionsFilter.tsx,src/platform/lib/reviewQueue.ts).draftContentAccessand the agents' variant decide drafts and versions per role;readVersionsis set because Payload's default leaks drafts (draftContentAccess.ts,roles.ts,src/platform/lib/roles.ts, #140).contentCollection.ts:draftVersionsturns on autosave and scheduled publish;previewAdminbuilds the preview address from the slug (generatePreviewPath.ts);seoTab.tsis the one SEO tab of pages, posts and events, whose description and image feed cards and share previews.populatePublishedAtsetspublishedAtwhen the request has none (pages, events, FAQ, resources).- The link field stores a reference or a URL, and
resolveLinkis the one place it becomes anhref;documentHrefis the one place a document's address is written (the slughomeat/). keyset.tsandsrc/platform/lib/cursor.ts: sort date plus id as tie-break, the cursor events and news load more with.emailConfirmer.tsis the service contact and sign-up use and verification provides (decision 0008).
Behaviors and rules the note must cover (each with the file or test named):
- Jobs: scheduled publishing runs every minute and the retention queue every 10 minutes, inside the app's one process (
jobRunners.ts,retentionJobs.ts); job stats and edit locks get staff or admin access after Payload builds the config (restrictJobStats.ts,restrictEditLocks.ts). expireCacheTagis how a hook drops a cache tag since Next 16 (expireCacheTag.ts).published.tsfilters on_statuseven for staff callers;authenticatedOrPublished.ts.- The seed runs only in local development, with no switch in production (
isSeedEnabled.ts). - Media: uploads, credits, licenses and the optional source link (
media.ts,src/platform/lib/mediaLicenses.ts). lib/: in-memory sliding-window limits (slidingWindow.ts), the client IP from the proxy header (clientIp.ts), the site timezone and day-only dates (timezone.ts,formatDateTime.ts), the message catalog and durations in words (messages/,formatDuration.ts), retention periods and link lifetimes shared by two modules (retention.ts,linkLifetimes.ts), the email layout with fixed text only (emailLayout.ts), the chart spec (chart/).seo/: noindex for account and token pages, no referrer for token addresses (notIndexed.ts,privateAddress.ts, #280); metadata and Open Graph merging.email/: SMTP from the environment, falling back to the log without it or on a bad config (emailAdapter.ts).turnstile/: the server check reads the secret, the widget appears only when Cloudflare asks, tokens are single use (turnstileVerifier.ts,TurnstileWidget.client.tsx,useRobotCheck.client.ts).service/:runUseCasecatches, logs only the error's class name, and returns a fallback (#521).
Tests to name under "Rules and the tests that protect them": src/platform/payload/*.test.ts, src/platform/lib/**/*.test.ts, src/platform/turnstile/turnstileVerifier.test.ts, and src/payload.config.roles.test.ts, protectedFields, reviewQueue, reviewQueueApi, scheduledPublishing, titleLimit.
Map entry: { "note": "src/platform/payload/README.md", "paths": ["src/platform/payload/**", "src/platform/lib/**", "src/platform/seo/**", "src/platform/email/**", "src/platform/turnstile/**", "src/platform/service/**"] }
src/platform/service/ (3 files) isn't in #719's list; it joins this note because it is the server-side half of the same helpers. If the note would pass 80 lines, split it in two in this issue: src/platform/payload/README.md for payload/, and src/platform/lib/README.md for lib/, seo/, email/, turnstile/ and service/, each with its own map entry and index line, and the index lines kept as short as possible (each one counts toward the budget check).
Acceptance criteria
- Not done:
src/platform/payload/README.mdfollowsdocs/knowledge/note-template.mdand is at most 80 lines. - Not done: If split, each note is at most 80 lines, and every file of the six folders is in exactly one note's paths.
- Not done: It explains behavior and logic, not fields: no field lists, props tables or route lists. It links the generated pages named above for those.
- Not done: Right after its opening sentences, a short list states every link between fields named above (relationships, values copied or derived, mapper inputs and the props they become, hooks that copy a value), each with its file.
- Not done: Every behavior listed above is covered or, if the code turns out different, the note says what the code does and this issue gets a comment saying what changed.
- Not done: Every statement names the file or test it comes from, checked against the code at the branch's base.
- Not done:
docs/knowledge/index.mdgets one short line for the note (a few words after the link). It stays within the budget check. - Not done:
docs/knowledge/map.jsongets the entry above. - Not done:
npm run agent-context -- --writehas been run and its generated rule committed, andnpm run agent-contextpasses. If the budget check fails, this issue is not done; trimming other always-loaded files is not part of this issue. - Not done: Known contradictions: #279: the cache-tag item looks already fixed (
docs/guidelines/payload-cms.md,nextjs-tailwind.mdanddocs/project.mdnow agree onexpireCacheTag), and the sitemap item indocs/roles/seo-specialist.mdlooks fixed too. Confirm both against the code and comment on #279; ifdocs/roles/seo-specialist.mdstill states something false, fix that fact here (for #158 as well). Checkdocs/roles/backend-eng.mdthe same way for #158. #366 and #531 don't apply. - Not done: No code changes. A bug or gap found in the code goes under the note's "Known gaps" and is filed as its own issue (labeled
scope-creep, linked here). - Not done:
Prettier,Knowledge sync,PR PolicyandAgent contextpass.
Files likely touched
src/platform/payload/README.mddocs/knowledge/index.md(one line)docs/knowledge/map.json(one entry).claude/rules/generated/src--platform--payload--README.mddocs/roles/seo-specialist.md(only if a fact is wrong)docs/roles/backend-eng.md(only if a fact is wrong)src/platform/lib/README.md(only if the note is split)
Must not touch
- Code under
src/(the note itself excepted): this issue documents behavior and changes none. - Other notes, their generated rules, and the files the other note issues under #712 list.
docs/knowledge/note-template.mdand the session-start set (CLAUDE.md,AGENTS.md,docs/guidelines/guard-rails.md).docs/architecture/data-model.md,docs/ui/data-types.md,docs/ui/component-set-modules.md: read them and fold this area's facts into the note (decision 0019, section 7); report any drift in them in a comment on #712 instead of editing them, since every note issue reads them.src/modules/README.md,src/platform/README.md,docs/project.md(#725 owns them).docs/guidelines/payload-cms.mdanddocs/guidelines/nextjs-tailwind.md(only checked here; the theme issue owns the token table).
Open questions
- Session-start room. The index line needs room at session start, which #799 makes. This issue is blocked by #799 and is not Ready until it lands; the line then stays within the budget check.
- Dead code first. #728 (the audit, waiting for the owner's keep-or-drop marks) removes unused or unwanted code before a note describes it. This issue is marked blocked by #728; it can start once #728 has settled this area, even if other areas are still open there.
- Size: not set; a cloud session can't read the board. Suggested: M.
Area
tooling, cms
Priority
medium
Generated by Claude Code, opens in a new tab