Home › Next.js › Next.js App Router (TypeScript) rules

Next.js App Router (TypeScript) rules

Cursor project rules for Next.js 15 App Router apps with TypeScript, Server Components, and Tailwind.

CursorNext.js

How to use

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

.cursor/rules/nextjs.mdcDownload  
---
description: Next.js App Router conventions
globs: ["app/**/*.{ts,tsx}", "components/**/*.tsx", "lib/**/*.ts"]
alwaysApply: false
---

# Next.js App Router

## Architecture
- Default to React Server Components. Add `"use client"` only for state, effects, browser APIs, or event handlers, and push it to the smallest leaf component.
- Fetch data in Server Components or route handlers, never in `useEffect` for initial page data.
- Mutations go through Server Actions in `app/**/actions.ts` with `"use server"`; validate every input with zod.
- Keep secrets in server-only modules; import `server-only` at the top of `lib/server/*`.

## Files and routing
- One route segment per folder: `page.tsx`, `layout.tsx`, `loading.tsx`, `error.tsx`, `not-found.tsx`.
- Export `generateMetadata` (or `metadata`) from every public page.
- Use `next/image` for images and `next/link` for internal links.

## TypeScript
- `strict: true`. No `any`; use `unknown` and narrow.
- Type props inline with `type Props = {...}`; avoid `React.FC`.

## Styling
- Tailwind utility classes; extract a component, not a custom CSS class, when markup repeats.

## Before finishing
- Run `pnpm lint && pnpm typecheck && pnpm build`. Fix every error; do not silence with `// @ts-ignore`.

Related rules

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Universal vibe-coding guardrails

Always-on Cursor rules that keep any AI agent careful: plan first, small diffs, verify, never fake it.

CursorAny stack

Next.js CLAUDE.md

A CLAUDE.md for Claude Code working in a Next.js + Prisma + Tailwind codebase.

Claude Code (CLAUDE.md)Next.js

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.