agentleFS
jimmypocockjimmypocock/cursor-rules/.cursor/rules/nextjs.mdc

cursor-rules / rules

Cursor rule8 starsChanged 19 months agoMITView on GitHub

Next.js Application Development Standards

The file

Show its rules and text

We split this nextjs.mdc into the rules it gives an agent

47 rules. About 0 are common, 46 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈46

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the App Router for new projects

    line 16
  2. Distinctive:

    Create reusable components in a dedicated components directory

    line 18
  3. Distinctive:

    Use custom hooks for shared logic

    line 20
  4. Distinctive:

    Keep utility functions in a utils directory

    line 22
  5. Distinctive:

    Use the folder-based routing system effectively

    line 26
  6. Distinctive:

    Create loading and error states for each route

    line 28
  7. Distinctive:

    Use route groups for organizational purposes

    line 29
  8. Distinctive:

    Use dynamic segments for parameterized routes

    line 32
  9. Distinctive:

    Use React Server Components by default

    line 36
  10. Distinctive:

    Keep components focused on single responsibilities

    line 38
  11. Distinctive:

    Create reusable UI components in a component library

    line 40
  12. Distinctive:

    Use React Server Components for server-side data fetching

    line 46
  13. Distinctive:

    Use suspense boundaries for loading states

    line 52
  14. Distinctive:

    Use Image component for optimized images

    line 56
  15. Distinctive:

    Use dynamic imports for code splitting

    line 58
  16. Distinctive:

    Use React.memo for expensive components

    line 61
  17. Distinctive:

    Use React Context for shared state when appropriate

    line 66
  18. Distinctive:

    Use local state for component-specific state

    line 68
  19. Distinctive:

    Avoid excessive global state

    line 71
  20. Distinctive:

    Use React Query for server state management

    line 72
  21. Distinctive:

    Use CSS Modules or Tailwind CSS for styling

    line 76
  22. Distinctive:

    Create responsive designs with mobile-first approach

    line 78
  23. Distinctive:

    Use CSS variables for theming

    line 79
  24. Distinctive:

    Create a consistent component design system

    line 81
  25. Very specific:

    Use NextAuth.js or Clerk for authentication

    line 86
  26. Distinctive:

    Create proper authorization middleware

    line 87
  27. Distinctive:

    Create well-structured API routes

    line 95
  28. Distinctive:

    Use appropriate HTTP status codes

    line 97
  29. Distinctive:

    Use appropriate response formats

    line 102
  30. Distinctive:

    Use semantic HTML for better accessibility

    line 106
  31. Distinctive:

    Create a sitemap.xml and robots.txt

    line 107
  32. Distinctive:

    Add structured data where applicable

    line 109
  33. Distinctive:

    Ensure proper heading hierarchy

    line 110
  34. Distinctive:

    Write unit tests for components and utilities

    line 115
  35. Distinctive:

    Create integration tests for pages and features

    line 116
  36. Distinctive:

    Use React Testing Library for component testing

    line 118
  37. Distinctive:

    Create proper test mocks

    line 120
  38. Distinctive:

    Test accessibility with appropriate tools

    line 121
  39. Distinctive:

    Use Vercel or similar platforms for deployment

    line 125
  40. Distinctive:

    Create proper CI/CD pipelines

    line 127
  41. Distinctive:

    Run tests before deployment

    line 128
  42. Distinctive:

    Use feature flags for controlled releases

    line 130
  43. Distinctive:

    Create proper rollback procedures

    line 131
  44. Distinctive:

    Use next-intl or similar for translations

    line 135
  45. Distinctive:

    Create language switcher components

    line 137
  46. Distinctive:

    Use appropriate ARIA attributes

    line 147
  47. Distinctive:

    Test with screen readers

    line 150

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
nextjs.mdc
---
description: Next.js Application Development Standards
globs: 
alwaysApply: false
---
---
Description: Next.js Application Development Standards
Globs: **/*.tsx, **/*.ts, **/pages/**/*, **/app/**/*, **/components/**/*
---

# Next.js Development Standards
@base.mdc
@typescript.mdc

## Project Structure
- Use the App Router for new projects
- Structure pages logically by feature or route
- Create reusable components in a dedicated components directory
- Group related functionality in feature directories
- Use custom hooks for shared logic
- Implement services for API interactions
- Keep utility functions in a utils directory
- Separate UI components from data fetching

## App Router Best Practices
- Use the folder-based routing system effectively
- Implement layouts for shared UI across routes
- Create loading and error states for each route
- Use route groups for organizational purposes
- Leverage parallel routes for complex layouts
- Implement intercepting routes for modals and slideovers
- Use dynamic segments for parameterized routes
- Implement proper route handlers for API endpoints

## Component Architecture
- Use React Server Components by default
- Mark client components with 'use client' directive when needed
- Keep components focused on single responsibilities
- Implement proper prop validation with TypeScript
- Create reusable UI components in a component library
- Leverage composition over inheritance
- Implement proper error boundaries
- Organize components by domain or feature

## Data Fetching
- Use React Server Components for server-side data fetching
- Implement proper caching strategies
- Leverage SWR or React Query for client-side data fetching
- Handle loading and error states gracefully
- Optimize fetch requests with appropriate cache headers
- Implement pagination for large data sets
- Use suspense boundaries for loading states
- Implement proper error handling for failed requests

## Performance Optimization
- Use Image component for optimized images
- Implement font optimization with next/font
- Use dynamic imports for code splitting
- Implement route prefetching for faster navigation
- Optimize third-party scripts with Script component
- Use React.memo for expensive components
- Implement proper bundling strategies
- Leverage Edge runtime for performance-critical paths

## State Management
- Use React Context for shared state when appropriate
- Implement Redux or Zustand for complex state management
- Use local state for component-specific state
- Leverage URL state for sharable state
- Implement proper state persistence strategies
- Avoid excessive global state
- Use React Query for server state management
- Implement proper loading and error states

## Styling Approaches
- Use CSS Modules or Tailwind CSS for styling
- Implement consistent design tokens
- Create responsive designs with mobile-first approach
- Use CSS variables for theming
- Implement dark mode support
- Create a consistent component design system
- Leverage CSS-in-JS solutions sparingly

## Authentication & Authorization
- Implement secure authentication strategies
- Use NextAuth.js or Clerk for authentication
- Create proper authorization middleware
- Protect API routes with authentication checks
- Implement proper role-based access control
- Handle authentication errors gracefully
- Secure cookies and tokens properly
- Implement proper session management

## API Development
- Create well-structured API routes
- Implement proper input validation
- Use appropriate HTTP status codes
- Implement consistent error handling
- Create API documentation
- Version APIs when necessary
- Implement rate limiting for public APIs
- Use appropriate response formats

## SEO Optimization
- Implement proper metadata for each page
- Use semantic HTML for better accessibility
- Create a sitemap.xml and robots.txt
- Implement proper OpenGraph tags
- Add structured data where applicable
- Ensure proper heading hierarchy
- Optimize for Core Web Vitals
- Implement proper canonical URLs

## Testing
- Write unit tests for components and utilities
- Create integration tests for pages and features
- Implement end-to-end tests for critical flows
- Use React Testing Library for component testing
- Implement Cypress or Playwright for E2E testing
- Create proper test mocks
- Test accessibility with appropriate tools
- Implement visual regression testing

## Deployment & CI/CD
- Use Vercel or similar platforms for deployment
- Implement preview deployments for PRs
- Create proper CI/CD pipelines
- Run tests before deployment
- Implement proper environment variable management
- Use feature flags for controlled releases
- Create proper rollback procedures
- Monitor performance after deployment

## Internationalization
- Use next-intl or similar for translations
- Implement proper locale detection
- Create language switcher components
- Support RTL languages when needed
- Implement proper date and number formatting
- Create localized routes
- Test internationalized content
- Implement proper fallbacks for missing translations

## Accessibility
- Follow WCAG guidelines
- Implement keyboard navigation
- Use appropriate ARIA attributes
- Create accessible forms
- Implement proper focus management
- Test with screen readers
- Create high-contrast modes
- Implement proper error messaging

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.