tooling: Generate the content-type reference from the Payload config, and fail CI when it is out of date
Back to our planType
enhancement
Summary
A script reads the site's Payload setup and writes one reference page per content type: its fields, who may do what, its hooks, and whether it has drafts. Nobody edits those pages by hand. A check regenerates them on every pull request and fails if the committed pages differ, so a changed content type can never have an old description.
Problem
docs/architecture/data-model.md lists each collection's fields, relations, hooks and field-level access by hand (250 lines). Every change to a collection has to be repeated there, and it isn't always (#517). An agent that wants to know what an event holds either trusts a page that may be stale or reads the config and its hooks again. The owner's direction (2026-11-06, recorded on the epic): when a content type's behavior or properties change, its documentation changes in the same pull request, or the pull request is blocked.
Proposed fix
Follow the decision record from the design sub-issue. The outline:
- A generator in
scripts/that loads the real Payload config without a database (reuseloadConfigfromsrc/platform/payload/testing/accessHarness.ts; don't write a second loader) and writes, for every collection and global, including the ones plugins add:docs/reference/content-types/<slug>.md: what it is for (fromadmin.descriptionwhen set); a table of fields (name, type, required, relation target, options, and notes such as hidden or server-only); access per operation by function name; hooks by phase with the function's name and file; drafts and versions; auth and upload settings; fields a plugin adds.docs/reference/content-types/README.md: the list of pages, one line each.- Each page starts with a line saying it is generated, from what, and how to regenerate it.
- Two commands:
npm run docs:generatewrites the pages;npm run docs:checkregenerates them and fails if anything differs from what is committed. - A CI job named
Knowledge syncthat runsdocs:checkon every pull request. It is not a required check yet; the sync-gate sub-issue makes it one. - Tests first for the functions that turn a field, an access map and a hook list into Markdown.
docs/architecture/data-model.mdkeeps what a script can't know (why the model is shaped this way, the relations diagram, what a hook is for) and links to the generated pages in place of its field lists, as the decision record says.
Output is formatted so the Prettier check passes. A page that would go over 250 lines is split by the content type's tabs or groups.
Acceptance criteria
- Not done:
npm run docs:generaterun twice in a row leaves no diff. - Not done: Every collection and global in the loaded config has a page: the twelve collections and two globals in
src/payload.config.ts, and the ones plugins add (forms, form submissions, redirects, search, MCP API keys, media folders). - Not done: Each page shows fields, access per operation, hooks and the draft setting.
- Not done: Adding a field to a collection without regenerating makes
npm run docs:checkfail with a message that says to runnpm run docs:generate. A test or the PR's "How to test" shows this. - Not done: The generator starts no database and no server, and the CI job reports its run time in the PR.
- Not done:
docs/architecture/data-model.mdno longer repeats field lists. - Not done: What each step of the native-first ladder found is recorded on this issue before custom code is written.
Files likely touched
scripts/ (generator and its tests), package.json (two scripts), docs/reference/content-types/ (new, generated), .github/workflows/ci.yml (one job), docs/architecture/data-model.md, knip.jsonc and .jscpd.json if the new files need an entry.
Must not touch
Behavior under src/ (the generator only reads the config), src/payload-types.ts, src/migrations/, the main ruleset (the sync-gate sub-issue changes required checks).
Open questions
None for the owner.
Area
cms, tooling, ci
Priority
high
Generated by Claude Code, opens in a new tab