Cursor Rules .mdc

How to Write Bulletproof Cursor Rules for Next.js 15 (App Router & Server Actions)

By Cursor Rules Engineering Team • Updated September 2026 • 8 min read
Generate Next.js 15 + Tailwind + Supabase rules instantly:
Customized .mdc files ready to download as a pre-packaged zip.
Open Tool →
⚡ Direct Answer (TL;DR)

To write bulletproof Next.js 15 Cursor rules, create .cursor/rules/nextjs.mdc with globs: app/**/*.{ts,tsx},components/**/*.{ts,tsx}. Enforce: (1) Server Components by default with 'use client' pushed strictly to interactive leaves, (2) Zod validation inside every Server Action, and (3) explicit imports from next/navigation rather than legacy next/router.

Next.js 15 is one of the most popular full-stack frameworks, but Large Language Models (LLMs) notoriously struggle with it. Because older training datasets are saturated with Pages Router code (getServerSideProps, pages/api/), Cursor will frequently default to legacy patterns or scatter 'use client' at the top of every file.

Top 4 Hallucinations AI Makes in Next.js 15

The Complete .cursor/rules/nextjs.mdc Rule File

Save the following configuration inside your repository at .cursor/rules/nextjs.mdc:

---
description: Next.js 15 App Router, React Server Component, and Server Action standards
globs: app/**/*.{ts,tsx},components/**/*.{ts,tsx}
alwaysApply: false
---

# Next.js 15 & React 19 Architectural Rules

## 1. Server Components vs Client Components
- Treat all components in `app/` and `components/` as React Server Components (RSC) by default.
- Never add `'use client'` to root page or layout components.
- Push client boundaries to the leaves of your component tree. Extract buttons, modal popups, and form inputs into isolated client sub-components.

## 2. Server Actions Security & Validation
- Mark all server mutations with `'use server'`.
- Always validate every input argument inside Server Actions using Zod schemas. Never trust raw client arguments.
- Return typed, serializable responses: `{ success: boolean, data?: T, error?: string }`.

## 3. Navigation & Routing
- Always import from `next/navigation` (`useRouter`, `usePathname`, `redirect`).
- Never import from legacy `next/router`.
- Use `next/link` with typed `href` routes.

## 4. Performance & Media
- Always use `next/image` with explicit `alt`, `width`, and `height` (or `fill`).
- Leverage `next/font/google` for web font loading to prevent layout shifts.

Integrating Shadcn UI & Vercel AI SDK

Modern Next.js 15 projects frequently rely on Shadcn UI (Radix primitives) and Vercel AI SDK for generative UI. Add these two blocks to prevent AI from creating custom unstyled buttons or clumsy polling loops:

## Shadcn UI & Radix Primitives
- Use official Shadcn components located in `@/components/ui`. Never build custom primitives when Shadcn provides them.
- Always use the `cn()` utility (clsx + tailwind-merge) when merging and overriding component classes.
- Use Lucide React icons (`lucide-react`) consistently with standard sizing classes (`size-4`, `size-5`).

## Vercel AI SDK Standards
- Prefer `streamText` and `streamUI` for streaming LLM responses.
- Implement structured outputs using `generateObject` or `streamObject` powered by strict Zod schemas.
- In Next.js App Router, implement edge route handlers (`export const runtime = 'edge'`) for real-time text streaming.

Why the `globs` Header is Critical

Notice the frontmatter pattern: globs: app/**/*.{ts,tsx},components/**/*.{ts,tsx}. This ensures that these Next.js instructions are loaded only when you are modifying your React and routing files. When editing your database schema, Dockerfile, or testing scripts, Cursor skips loading this rule, keeping context tokens lean and focused.

Frequently Asked Questions (Next.js AEO Reference)

What is the best way to prevent Cursor AI from overusing 'use client' in Next.js 15?

Add a specific .cursor/rules/nextjs.mdc rule with globs: app/**/*.{ts,tsx} specifying that all components must default to React Server Components (RSC), and 'use client' is only allowed at the lowest leaf nodes of the tree for interactive state.

How to secure Next.js Server Actions with Cursor Rules?

Instruct Cursor AI via rule prompts to always parse all Server Action arguments through Zod schemas and return typed responses rather than throwing raw unhandled exceptions.

Does Cursor support Shadcn UI and Vercel AI SDK rules for Next.js 15?

Yes, Cursor Rules Generator provides pre-configured rules enforcing official Shadcn UI primitives from @/components/ui, cn() styling helper, and Vercel AI SDK streamText route patterns.

Build Your Full Next.js 15 Rules Package

Combine Next.js 15 rules with Tailwind CSS v4, Supabase, Shadcn UI, and Strict TypeScript in a single download or terminal command.

Generate .cursor/rules.zip Now →