PluginBench
Rule

nextjs

via PatrickJS/awesome-cursorrules

Next.js with TypeScript and Tailwind UI best practices

What is nextjs?

Establishes project structure, component patterns, and performance optimization guidelines for Next.js applications using the App Router. Use this rule to maintain consistency across server/client components, data fetching, routing, and form validation in TypeScript-based Next.js projects.

  • Enforce App Router directory structure with organized component, utility, and shared component placement
  • Establish Server Component defaults with explicit 'use client' marking and Suspense boundaries for client components
  • Optimize performance through image optimization, dynamic loading, and RSC-first patterns
  • Implement data fetching best practices with proper error handling and caching strategies
  • Guide form validation using Zod with server-side validation and error state management
  • Minimize client-side state through server state preference and React Context discipline

Applies to

File patterns this rule matches.

**/*.tsx
**/*.ts
src/**/*.ts
src/**/*.tsx
Rule definition (reference)

Source of truth, from the repository.

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

Related rules

Best practices and folder structure for Next.js App Router development.

**/*
41k
via PatrickJS/awesome-cursorrules

Next.js + Material UI + Tailwind CSS + shadcn/ui + Aeternity UI development guide

**/*
41k
via PatrickJS/awesome-cursorrules

Expert guidance for Next.js, React, and Tailwind CSS development with TypeScript best practices.

**/*
41k
via PatrickJS/awesome-cursorrules

Expert guidance for Next.js 14, React, TypeScript, and Web3 stack development

**/*
41k
via PatrickJS/awesome-cursorrules

Next.js development guidance with SEO optimization and code quality standards.

**/*
41k
via PatrickJS/awesome-cursorrules

Next.js + Supabase + Shadcn + PWA development rules with code quality, build tracking, and project documentation standards.

**/*
41k
via PatrickJS/awesome-cursorrules