DomainScoreCursor Rules
GitHub

1/23/2025

A comprehensive guide and rules for developing Next.js applications using Tailwind CSS for styling and TypeScript for type safety. This setup ensures a modern, efficient, and scalable web development environment.



# Next.js (Tailwind, TypeScript)

# Next.js with Tailwind CSS and TypeScript

## Overview
This document outlines the best practices and rules for developing Next.js applications using Tailwind CSS and TypeScript. The goal is to ensure that the codebase is maintainable, scalable, and adheres to modern web development standards.

## Key Features
- **Next.js**: Utilized for server-side rendering and static site generation.
- **Tailwind CSS**: Used for utility-first CSS styling, ensuring responsive and customizable designs.
- **TypeScript**: Enhances code quality and developer productivity through static typing.

## Coding Standards
- **Functional Components**: Prefer functional components over class components.
- **TypeScript**: Use TypeScript for all components and utilities to ensure type safety.
- **Tailwind CSS**: Apply Tailwind CSS classes directly within JSX for styling.

## Preferred Libraries
- **Next.js**: For routing and server-side rendering.
- **Tailwind CSS**: For styling components.
- **TypeScript**: For type checking and enhancing developer experience.

## File Structure
- **components/**: Reusable UI components.
- **pages/**: Next.js pages.
- **styles/**: Tailwind CSS configuration and global styles.
- **types/**: TypeScript type definitions.

## Performance Optimization
- **React.memo**: Use for optimizing functional components.
- **Lazy Loading**: Implement for components and routes to improve load times.
- **useEffect Optimization**: Ensure dependencies are correctly managed to prevent unnecessary re-renders.

## Testing Requirements
- **Jest and React Testing Library**: For unit and integration testing.
- **Test Coverage**: Aim for at least 80% test coverage.
- **Snapshot Testing**: Use for UI components to detect unintended changes.

## Documentation
- **JSDoc**: Use for documenting functions and components.
- **README.md**: Include in each main directory with both English and Chinese versions.

## Error Handling
- **try/catch**: Use for handling asynchronous operations.
- **Error Boundaries**: Implement global error boundaries to catch runtime errors.

## Conclusion
By following these guidelines, developers can ensure that their Next.js applications are robust, maintainable, and scalable. Tailwind CSS and TypeScript further enhance the development experience by providing powerful styling and type safety features.