How to understand a Payload CMS codebase
Payload is a code-first CMS: collections, fields, access rules and hooks are TypeScript config, and Payload generates the admin panel and APIs. Payload 3 installs into a Next.js app, so the CMS and the website can share one repository.
How to tell it's Payload CMS
payloadinpackage.jsonand apayload.config.tscollections/*.tsexportingCollectionConfigobjects- An
app/(payload)/route group in a Next.js app
Where things usually live
- payload.config.ts
- Database adapter, collections, globals, plugins, editor, admin settings.
- collections/
- One file per collection:
slug,fields,access,hooks. - globals/
- Singleton documents such as site settings.
- access/
- Reusable access-control functions.
- hooks/
- Reusable field and collection hooks.
- payload-types.ts
- Generated TypeScript types for every collection.
- app/(payload)/
- Admin panel and API routes mounted in Next.js.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
payload.config.ts, to see every collection- The collection file you care about, especially
accessandhooks - Front-end pages that query Payload through the Local API
How a request moves through the code
- A request arrives through the REST or GraphQL API, the admin panel, or a Local API call in server code.
- Collection
accessfunctions decide whether the operation is allowed. beforeValidate,beforeChangeand field hooks run.- The database adapter writes the document.
afterChangehooks run side effects such as revalidating pages or sending emails.
Questions to ask about the repository
- Which collections can anonymous users read, and why?
- What do the
afterChangehooks do in each collection? - How does the front end fetch content: Local API, REST or GraphQL?
What trips people up
- The Local API skips access control by default unless
overrideAccess: falseis passed. payload-types.tsis generated; stale types mean the generate command hasn't been run.