Best practices for Next.js 14 Best Practices
.cursorrules in your project root# Next.js 14 Best Practices ===================================== ## Core Principles ------------------- 1. **Separation of Concerns**: Keep components, pages, and API routes organized and focused on a single responsibility. 2. **Reusability**: Design components to be reusable across the application. 3. **Performance Optimization**: Prioritize page loading speed and optimize images, fonts, and other assets. 4. **Accessibility**: Ensure all pages and components are accessible and follow Web Content Accessibility Guidelines (WCAG 2.1). ## Code Style Guidelines ----------------------- ### Naming Conventions 1. **Component Names**: Use PascalCase for component names (e.g., `HeaderComponent`). 2. **Variable Names**: Use camelCase for variable names (e.g., `userName`). 3. **File Names**: Use kebab-case for file names (e.g., `header-component.js`). ### Typing 1. **Type Annotations**: Use TypeScript type annotations for all variables, function parameters, and return types. 2. **Type Definitions**: Define types for custom components, interfaces, and enums. ### Code Organization 1. **Component Structure**: Keep components in a separate directory (e.g., `components/`). 2. **Page Structure**: Keep pages in a separate directory (e.g., `pages/`). 3. **API Route Structure**: Keep API routes in a separate directory (e.g., `api/`). ## Best Practices ------------------ ### Component Development 1. **Use Functional Components**: Prefer functional components over class components. 2. **Use Hooks**: Use React Hooks for state management and side effects. 3. **Avoid Prop Drilling**: Use context API or a state management library to avoid prop drilling. ### Performance Optimization 1. **Use `next/image`**: Use the `next/image` component for image optimization. 2. **Use `next/font`**: Use the `next/font` component for font optimization. 3. **Use Code Splitting**: Use code splitting to reduce bundle sizes. ### Security 1. **Validate User Input**: Validate user input to prevent XSS attacks. 2. **Use Environment Variables**: Use environment variables to store sensitive data. 3. **Use Authentication**: Implement authentication and authorization mechanisms. ### Testing 1. **Write Unit Tests**: Write unit tests for components and API routes. 2. **Write Integration Tests**: Write integration tests for pages and user flows. 3. **Use a Testing Library**: Use a testing library like Jest or Cypress. ## Common Pitfalls to Avoid --------------------------- 1. **Over-Engineering**: Avoid over-engineering components or features. 2. **Tight Coupling**: Avoid tight coupling between components or modules. 3. **Unused Code**: Remove unused code and dependencies. 4. **Inconsistent Code Style**: Avoid inconsistent code style and formatting. 5. **Unoptimized Images**: Avoid using unoptimized images or assets. By following these best practices, you can ensure your Next.js 14 application is scalable, maintainable, and performant.
Comprehensive Cursor rules for Next.js 14+ with App Router, including routing, layouts, and API patterns.
Cursor rules for TypeScript with strict type checking, advanced patterns, and best practices.
Cursor rules for Tailwind CSS development with responsive design, custom components, and dark mode.
Cursor
coding
AI coding rules customize how Cursor generates and refactors code for your project. Follow these steps to install Next.js 14 Best Practices.
.cursor/rules, for Windsurf use .windsurfrulesComprehensive Cursor rules for Next.js 14+ with App Router, including routing, layouts, and API patterns.
Cursor rules for TypeScript with strict type checking, advanced patterns, and best practices.
Cursor rules for Tailwind CSS development with responsive design, custom components, and dark mode.