feat: add best practices documentation as cursor project rules

This commit is contained in:
javayhu 2025-02-22 00:16:40 +08:00
parent 5dc5c09306
commit c49410f040
10 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,9 @@
---
description: Best practices for using Vercel AI SDK
globs: **/*.{ts,tsx}
---
- Use the AI SDK to simplify OpenAI API integration
- Implement proper error handling and rate limiting for API calls
- Utilize streaming responses for improved user experience in chat applications
- Follow OpenAI's guidelines for responsible AI usage and data privacy

View File

@ -0,0 +1,9 @@
---
description: Best practices for using Drizzle ORM with database
globs: **/*.{ts}
---
- Use Drizzle's type-safe query builder for better code completion and safety.
- Implement migrations using Drizzle Kit for database schema management.
- Utilize Drizzle's relation system to define and query relationships.
- Use Drizzle's transaction API for complex, atomic operations.

View File

@ -0,0 +1,9 @@
---
description: Best practices for Next.js applications and routing
globs: **/*.{ts,tsx}
---
- Utilize Next.js 15's new features like Server Actions for improved performance and security
- Implement proper error handling with `error.tsx` and `not-found.tsx` for better user experience
- Use `next-safe-action` for secure form submissions and API calls
- Leverage `next-themes` for easy theme management and dark mode support

View File

@ -0,0 +1,9 @@
---
description: Best practices for using Radix UI components
globs: **/*.{ts,tsx}
---
- Use Radix UI primitives for building custom, accessible components
- Follow Radix UI's composition patterns for consistent component structure
- Implement proper ARIA attributes and keyboard navigation for accessibility
- Utilize Radix UI's built-in state management for complex components

View File

@ -0,0 +1,9 @@
---
description: Best practices for React component development
globs: **/*.{ts,tsx,js,jsx}
---
- Use functional components with hooks instead of class components
- Implement proper state management using `useState` and `useReducer`
- Utilize `useCallback` and `useMemo` for performance optimization
- Leverage `react-hook-form` for efficient form handling and validation

View File

@ -0,0 +1,9 @@
---
description: Best practices for form handling with React Hook Form
globs: **/*.{ts,tsx}
---
- Use the `useForm` hook with TypeScript for better type safety.
- Implement validation using Zod or Yup for complex form schemas.
- Utilize the `Controller` component for controlled inputs.
- Use `formState` to handle form state changes efficiently.

View File

@ -0,0 +1,9 @@
---
description: Best practices for integrating Stripe payments
globs: **/*.{ts,tsx}
---
- Use `@stripe/stripe-js` for client-side Stripe integration
- Implement proper error handling and user feedback for payment flows
- Utilize Stripe's Elements for secure and customizable payment forms
- Follow Stripe's best practices for PCI compliance and security

View File

@ -0,0 +1,9 @@
---
description: Best practices for styling with Tailwind CSS
globs: **/*.{ts,tsx,css}
---
- Use utility-first approach for rapid development and maintainability
- Implement responsive design using Tailwind's responsive modifiers
- Utilize `tailwind-merge` for efficient class merging and overriding
- Leverage `tailwindcss-animate` for easy animation implementation

View File

@ -0,0 +1,9 @@
---
description: TypeScript coding standards and type safety guidelines
globs: **/*.{ts,tsx}
---
- Enable strict mode in your `tsconfig.json` for better type checking.
- Use interfaces for object shapes and types for unions or intersections.
- Leverage type inference where possible to reduce type annotations.
- Use generics for reusable components and functions.

View File

@ -0,0 +1,9 @@
---
description: Best practices for schema validation with Zod
globs: **/*.{ts,tsx}
---
- Define clear and reusable schemas for data validation
- Use Zod's type inference for TypeScript integration and type safety
- Implement custom validation rules using Zod's `refine` method
- Utilize Zod with `react-hook-form` for seamless form validation