Skip to main content
rule

nextjs · patrickjs — Cursor rule: what it does, how to install

This rule guides Next.js work with TypeScript and Tailwind UI. Use it when shaping project structure, components, routes, forms, and data loading.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/nextjs.mdc
Open on GitHub

What nextjs does

The rule is aimed at Next.js projects using the App Router. It directs route-specific components to app, shared components to components, and helpers to lib; directory names use lowercase kebab case. Server Components are the default, while client components must be marked with use client and placed behind Suspense with a fallback.

It covers image handling with WebP, size data, and lazy loading, plus restrained use of useEffect and setState. Data fetching should include caching, loading states, and error handling. Forms use server-side checks and Zod; routes can use dynamic and parallel patterns. The rule targets *.tsx, *.ts, src/**/*.ts, and src/**/*.tsx. Form guidance depends on Zod.

What it helps with

  • organize a Next.js project around the App Router
  • decide when a component should run on the server
  • add loading and error states to routes
  • shape data fetching with caching
  • validate forms with Zod

Example prompts for the agent

  • Review this screen against the Next.js App Router rules.
  • Tell me whether this component needs use client or can stay server-rendered.
  • Add loading, error, and server-side validation states to this form with Zod.

How to install nextjs

Manually: put the files in place

.cursor/rules/nextjs.mdc

Frontmatter: description, globs, alwaysApply

Step by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules

Questions about nextjs

How do I install nextjs in Cursor?

Copy the rule file to .cursor/rules/nextjs.mdc.

What does the nextjs rule do?

It sets conventions for Next.js with TypeScript and Tailwind UI, covering folders, Server Components, routing, data fetching, forms, and client state.

Which files does the nextjs rule apply to?

It applies to *.tsx, *.ts, src/**/*.ts, and src/**/*.tsx.

Source text

nextjs.mdc · CC0-1.0
---
description: "Next.js with TypeScript and Tailwind UI best practices"
globs: **/*.tsx, **/*.ts, src/**/*.ts, src/**/*.tsx
alwaysApply: false
---
# Next.js Best Practices

## Project Structure
- Use the App Router directory structure
- Place components in `app` directory for route-specific components
- Place shared components in `components` directory
- Place utilities and helpers in `lib` directory
- Use lowercase with dashes for directories (e.g., `components/auth-wizard`)

## Components
- Use Server Components by default
- Mark client components explicitly with 'use client'
- Wrap client components in Suspense with fallback
- Use dynamic loading for non-critical components
- Implement proper error boundaries
- Place static content and interfaces at file end

## Performance
- Optimize images: Use WebP format, size data, lazy loading
- Minimize use of 'useEffect' and 'setState'
- Favor Server Components (RSC) where possible
- Use dynamic loading for non-critical components
- Implement proper caching strategies

## Data Fetching
- Use Server Components for data fetching when possible
- Implement proper error handling for data fetching
- Use appropriate caching strategies
- Handle loading and error states appropriately

## Routing
- Use the App Router conventions
- Implement proper loading and error states for routes
- Use dynamic routes appropriately
- Handle parallel routes when needed

## Forms and Validation
- Use Zod for form validation
- Implement proper server-side validation
- Handle form errors appropriately
- Show loading states during form submission

## State Management
- Minimize client-side state
- Use React Context sparingly
- Prefer server state when possible
- Implement proper loading states

© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules

Similar IDE rules

All IDE rules for Frontend and UI →

nextjs by other authors comes first.

nextjs official github Enforces Next.js 16 App Router standards in GitHub Copilot. Prevents runtime errors with server-client boundaries and asynchronous request APIs. ★ 40,451repo stars react-nextjs-development sickn33 Walks a React or Next.js 14+ build through eight phases, from scaffolding to a Vercel deploy. Handy when a project starts from scratch or moves to the App Router. CX Codex +1 2,000installs nextjs-tailwind official github This rule guides GitHub Copilot on Next.js, TypeScript, and Tailwind CSS projects. Use it when asking for changes to routes, components, data handling, or styling. ★ 40,451repo stars nextjs-app-router-fundamentals wsimmonds A skill that walks the agent through Next.js App Router: Pages Router migration, nested layouts, metadata, dynamic routes. Useful when moving to app/. CX Codex +1 2,200installs nextjs-dynamic-routes-params wsimmonds A skill that steers the agent through App Router dynamic segments and the params prop in Next.js 15+. Useful when a page depends on an ID or slug from the URL. CX Codex +1 303installs nextjs-developer https://github.com/Jeffallan Configures Next.js 14+ application architecture using App Router, React Server Components, and Server Actions. Useful when setting up SSR streaming, SEO metadata, and Vercel deployments. CX Codex +1 5,800installs nextjs-cache-architecture mohamed-hossam1 Structures caching architecture in Next.js 16+ App Router projects. It sets up the "use cache" directive, a typed tag registry, and Suspense boundaries. CX Codex +1 5,000installs

From the same set210

optimize-dry-solid-principles-cursorrules-prompt-f A Cursor rule that steers the assistant toward DRY and SOLID edits, respect for the existing architecture and questions before coding. ★ 41,024repo stars node-express A Cursor rule for Node.js and Express.js projects, covering API design, security, databases, testing, and deployment. ★ 41,024repo stars nextjs15-supabase-cursorrules-prompt-file A Cursor rule that keeps the agent inside a Next.js 15, Supabase and TypeScript strict stack — from session checks to RLS and Stripe keys. ★ 41,024repo stars nextjs15-react19-vercelai-tailwind-cursorrules-prompt-file Defines architecture standards for Next.js 15, React 19, Tailwind CSS, and Vercel AI SDK in Cursor. Guides component design, async runtime APIs, and typed form handling. ★ 41,024repo stars nextjs-vercel-typescript-cursorrules-prompt-file A Cursor rule that sets code style and file structure for Next.js projects with TypeScript, Vercel middleware and a KV database. ★ 41,024repo stars nextjs-vercel-supabase-cursorrules-prompt-file Configures Cursor for building the BA Copilot app with Next.js App Router, Vercel AI, Supabase, and bpmn-js. Keeps the AI aligned with the chosen stack. ★ 41,024repo stars nextjs-typescript-tailwind-cursorrules-prompt-file A Cursor rule that hands the agent the conventions of a Next.js, TypeScript and Tailwind CSS project. Useful when new code has to match what is already there. ★ 41,024repo stars nextjs-typescript-cursorrules-prompt-file A Cursor rule that pins the Next.js and TypeScript stack and the agent's working order: plan first, one file at a time, fixed reply format. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor