These conventions outline our development standards for Next.js projects, specifically focusing on projects using the app router for components and the pages router for API calls.
- Prioritize package usage over custom code
- Maintain low code complexity
- Follow clean, efficient, and well-structured code patterns
- Use modern React and Next.js best practices
- Use
.jsx
extension for React components - Place non-page files in bracketed folders within app router:
(components)
(utils)
(hooks)
- etc.
- Prioritize using established packages over writing custom code
- Opt for low complexity solutions instead of extensive custom implementations
- Provide complete file code without referencing existing code
- Remove unnecessary code and avoid over-engineering
- Split files when it improves architecture
- Use lodash utility functions to enhance code readability
- Implement
Promise.all
for concurrent API requests - Follow Next.js performance best practices
- Optimize component rendering and data fetching
- Use backticks (`) for text quotations to prevent code breaks
- Follow consistent formatting and naming conventions
- Implement proper error handling
- Include appropriate TypeScript types when applicable
Before implementing any solution, developers should:
-
Examine Requirements
- Review user/client request thoroughly
- Analyze existing codebase if applicable
- Identify core functionality needs
-
Evaluate Structure
- Determine new/modified file requirements
- Plan component hierarchy
- Consider data flow patterns
-
Optimize Architecture
- Identify code structure improvements
- Look for optimization opportunities
- Apply Next.js best practices
-
Package Assessment
- Research relevant packages/libraries
- Evaluate build size impact
- Consider maintenance implications
-
Code Review
- Check for unnecessary complexity
- Identify potential optimizations
- Look for removable code
Before submitting code, ensure:
- All new files use correct extensions
- Components are properly organized in bracketed folders
- Package dependencies are documented
- Code is optimized for performance
- Error handling is implemented
- Edge cases are considered
- Solution follows low complexity principles
project/
├── app/
│ ├── (components)/
│ │ └── ExampleComponent.jsx
│ ├── (utils)/
│ │ └── helpers.js
│ └── page.jsx
└── pages/
└── api/
└── example.js
// pages/api/example.js
export default async function handler(req, res) {
try {
// Implementation
} catch (error) {
res.status(500).json({ error: error.message });
}
}
// app/(components)/ExampleComponent.jsx
'use client';
import { useState } from 'react';
export default function ExampleComponent() {
// Implementation
}
These conventions should be reviewed and updated regularly to ensure they remain aligned with evolving best practices and team needs.