Home › Strapi › Strapi 5 headless CMS Cursor rules

Strapi 5 headless CMS Cursor rules

Cursor rules for Strapi 5 backends: content-type schemas, Document Service API, controllers and services, policies, population, and generated types.

CursorStrapi

How to use

Save this as .cursor/rules/strapi.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/strapi.mdcDownload  
---
description: Strapi 5 backend conventions
globs: ["src/**/*.{ts,js,json}", "config/**/*.{ts,js}"]
alwaysApply: false
---

# Strapi 5

## Commands
`npm run develop` (admin + autoreload; content-type builder only works here) · `npm run build` · `npm run start` · regenerate types: `npm run strapi ts:generate-types`.

## Rules
- Content types live in `src/api/<name>/content-types/<name>/schema.json`; components in `src/components/<category>/`. Schema changes through the Content-Type Builder in develop mode or by editing `schema.json` and restarting; never change the database by hand.
- Strapi 5 identifies entries by `documentId` (string), not numeric `id`. Use it in routes, relations and client code.
- Server code uses the Document Service API: `strapi.documents('api::article.article').findMany({ filters, populate, sort, pagination, status: 'published' })`, `.findOne({ documentId })`, `.create`, `.update`, `.publish`. Don't use the deprecated Entity Service or raw Knex unless a measured need exists.
- Keep controllers thin (`factories.createCoreController` + overrides) and put business logic in services. Sanitize output with `this.sanitizeOutput` and validate query input with `this.validateQuery` in custom controllers.
- Population is explicit: request only the relations and fields needed (`populate: { cover: { fields: ['url', 'alternativeText'] } }`). Never `populate: '*'` deeply in public endpoints.
- Access control: Users & Permissions roles for public/authenticated, plus route policies in `src/policies/` for ownership checks. Never expose admin-only fields; mark them `private: true` in the schema.
- Lifecycle side effects (webhooks, cache purge) go in document service middlewares or lifecycles with idempotent handlers.
- Config reads env via `env('KEY')` in `config/*.ts`; secrets (`APP_KEYS`, `JWT_SECRET`, DB creds) only in `.env`, never committed.
- Plugins installed via npm and enabled in `config/plugins.ts`; don't patch `node_modules`.

## Done when
`npm run build` passes, types regenerated if schemas changed, and the affected REST/GraphQL endpoint returns the expected shape.

More: all Strapi rules · all Cursor rules

Related 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

Shopify Hydrogen storefront Cursor rules

Cursor rules for Shopify Hydrogen storefronts: route loaders with the Storefront API, GraphQL fragments and codegen, caching strategies, cart actions, and SEO.

CursorShopify

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

Medusa v2 commerce AGENTS.md

AGENTS.md for Medusa v2 commerce backends: custom modules and data models, workflows with compensation, API routes, subscribers, module links, and admin widgets.

AGENTS.mdMedusa (commerce)

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.