Skip to content

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

  • payload in package.json and a payload.config.ts
  • collections/*.ts exporting CollectionConfig objects
  • 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

  1. payload.config.ts, to see every collection
  2. The collection file you care about, especially access and hooks
  3. Front-end pages that query Payload through the Local API

How a request moves through the code

  1. 1A request arrives through the REST or GraphQL API, the admin panel, or a Local API call in server code.
  2. 2Collection access functions decide whether the operation is allowed.
  3. 3beforeValidate, beforeChange and field hooks run.
  4. 4The database adapter writes the document.
  5. 5afterChange hooks 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 afterChange hooks 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: false is passed.
  • payload-types.ts is generated; stale types mean the generate command hasn't been run.