Home › Payload CMS › Payload CMS 3 + Next.js Cursor rules

Payload CMS 3 + Next.js Cursor rules

Cursor rules for Payload CMS 3 inside Next.js: collections and fields config, access control, hooks, Local API, generated types and migrations.

CursorPayload CMS

How to use

Save this as .cursor/rules/payload.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

.cursor/rules/payload.mdcDownload  
---
description: Payload CMS conventions
globs: ["src/collections/**/*.ts", "src/globals/**/*.ts", "src/payload.config.ts", "src/app/**/*.{ts,tsx}"]
alwaysApply: false
---

# Payload CMS 3

- Payload runs inside the Next.js app (`src/app/(payload)` admin, `src/app/(frontend)` site). Config in `src/payload.config.ts`; one file per collection in `src/collections/` and per global in `src/globals/`.
- Every collection defines `slug`, `fields`, `admin.useAsTitle` and explicit `access` (`read`, `create`, `update`, `delete`). Never leave write access open; default to `({ req: { user } }) => Boolean(user)` or a role check.
- Field-level `access` for sensitive fields; `hidden: true` for internal ones.
- After changing collections or fields, run `npm run generate:types` (writes `payload-types.ts`) and import types from there. Don't hand-write document types.
- Server code (RSC, route handlers, server actions) reads data with the Local API: `const payload = await getPayload({ config })`, then `payload.find({ collection, where, depth, limit })`. Pass `overrideAccess: false` and `user` when acting for a user; the default bypasses access control.
- Keep `depth` low (0-2) and select only needed fields for performance.
- Hooks (`beforeChange`, `afterChange`, `beforeValidate`) stay small and idempotent; pass `req` to nested Local API calls so they share the transaction.
- Postgres/SQLite adapters: create migrations with `npx payload migrate:create` and run `npx payload migrate`; don't rely on dev push mode in production.
- Rich text uses the Lexical editor; render with the official `RichText` converter, not `dangerouslySetInnerHTML`.
- Uploads: configure `upload` collections with `mimeTypes` and image sizes; store files in the configured storage adapter, not the repo.

## Done when
`npm run generate:types`, `npx tsc --noEmit` and `npm run build` pass, and new access rules are covered by a test or manual check as a non-admin user.

More: all Payload CMS rules · all Cursor rules

Related rules

Shopify Liquid theme rules

Cursor rules for Shopify Online Store 2.0 themes: sections and blocks, JSON templates, Liquid performance, Theme Check.

CursorShopify

WordPress block theme & blocks rules

Cursor rules for WordPress block themes and custom blocks: theme.json v3, block.json, patterns, and @wordpress/scripts.

CursorWordPress

Drupal 11 module development CLAUDE.md

CLAUDE.md for Drupal 11 sites and custom modules: Composer, Drush, services and dependency injection, config management, and PHPUnit.

Claude Code (CLAUDE.md)Drupal

Sanity Studio + GROQ AGENTS.md

AGENTS.md for Sanity projects: schema types with defineType, typed GROQ queries via TypeGen, Portable Text, previews, and safe content migrations.

AGENTS.mdSanity

Shopify app AGENTS.md

AGENTS.md for Shopify apps built with Shopify CLI and the React Router template: auth, GraphQL Admin API, and webhooks.

AGENTS.mdShopify

WordPress plugin CLAUDE.md

CLAUDE.md for WordPress plugin development: prefixes, hooks, nonces and capabilities, sanitizing, escaping, and wp-env.

Claude Code (CLAUDE.md)WordPress

Get the best new AI prompts every week

One short email a week: the best new prompts and rules for ChatGPT, Claude, Gemini, Midjourney, Cursor and more, plus what changed in the tools. Free, unsubscribe anytime.

Finishes on our newsletter page at beehiiv (opens in a new tab). Or subscribe directly.