-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.cursorrules
More file actions
133 lines (112 loc) · 4.57 KB
/
.cursorrules
File metadata and controls
133 lines (112 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Cursor Rules for Random ID App
## Tech Stack
- **Framework**: Next.js with App Router and Server Actions
- **Database**: PostgreSQL with Prisma ORM
- **Forms**: React Hook Form with Zod validation
- **UI Components**: Radix UI with Tailwind CSS
- **Authentication**: Custom JWT implementation
- **Package Manager**: Yarn (always use yarn, never npm)
## Feature Development Flow
When creating a new feature, follow this standardized flow:
1. **Create Prisma Schema** in `prisma/schema.prisma`
2. **Create Zod Schema** in `src/schema/[feature].ts` for validation
3. **Create Admin CRUD Pages** in `app/admin/[feature]/`:
- `page.tsx` - Server-side entry point (authentication, data fetching)
- `actions.ts` - Server actions (getAll with pagination, deleteById)
- `[Feature]Table.tsx` - Client component with paginated list
4. **Create Form Pages** in `app/admin/[feature]/[id]/`:
- Use `[id]` pattern where `id='new'` for create, otherwise update
- `page.tsx` - Server-side entry point
- `actions.ts` - Server actions (create, update, getById)
- `[Feature]Form.tsx` - Client form component with Zod validation
## Code Conventions
### Server Actions
- Always return consistent response format: `{ success: boolean, data?: any, error?: string }`
- Use pagination, search, and sorting for list endpoints
- Handle errors gracefully with try-catch blocks
- Use Prisma types generated from schema
- Example:
```typescript
return { success: true, data: result };
// or
return { success: false, error: error.message };
```
### Forms
- Use shared form components from `src/components/forms/` to avoid repetition
- Implement dual-purpose forms (create/edit) using ID detection
- Always validate with Zod schemas before submission
- Use react-hook-form for form management
- Pattern for dual-purpose forms:
```typescript
const isNew = params.id === 'new';
if (isNew) {
// Create mode
} else {
// Edit mode - fetch existing data
}
```
### Data Tables
- Implement search, sorting, and pagination
- Use `usePagination` hook for state management
- Include action buttons for edit/delete operations
- Example:
```typescript
const { page, pageSize, setPage } = usePagination();
```
### File Naming
- Components: PascalCase (e.g., `UserForm.tsx`, `JokesTable.tsx`)
- Server actions: camelCase (e.g., `actions.ts`)
- Schemas: camelCase (e.g., `user.ts`, `joke.ts`)
- Pages: lowercase with extensions (e.g., `page.tsx`)
### Type Usage
- Prefer Prisma-generated types from database schema
- Use Zod schemas for validation and type checking
- Almost every table should have a corresponding Zod schema
## Design System
Follow the Trendy Bollywood design system (see DESIGN_GUIDE.md):
- Use Outfit font family exclusively
- Primary weight: `font-light` (300) for most text
- Use `font-extralight` (200) for large display headings
- Amber color palette for brand elements (amber-800 to amber-900)
- Stone/Gray palette for neutrals
- No rounded corners (rectangular shapes)
- Subtle borders with 50% opacity
- Generous whitespace and padding
- Uppercase text with wide tracking (`tracking-wider` or `tracking-widest`)
## Package Management
- Always use `yarn` for installing dependencies
- Run `yarn install` to install packages
- Use `yarn add [package]` for new dependencies
- Use `yarn add -D [package]` for dev dependencies
## Code Review Checklist
Before committing, always run:
- `yarn lint`
- `yarn typecheck`
## Database Setup
1. Run migrations: `yarn prisma migrate dev`
2. Generate client: `yarn prisma generate`
3. Seed database if needed: `yarn prisma db seed`
## Common Patterns
### Admin CRUD Structure
```
app/admin/[feature]/
├── page.tsx # Server component (auth + data fetching)
├── actions.ts # Server actions (getAll, deleteById)
└── [Feature]Table.tsx # Client component (paginated table)
app/admin/[feature]/[id]/
├── page.tsx # Server component (auth + initial data)
├── actions.ts # Server actions (create, update, getById)
└── [Feature]Form.tsx # Client component (react-hook-form + zod)
```
### Generic Components
- Use shared form components from `src/components/forms/` to avoid repetition
- Check existing forms for patterns before creating new ones
## Best Practices
- Always handle authentication in server components
- Use server actions for all data mutations
- Implement proper error handling with try-catch
- Use TypeScript strictly - leverage Prisma and Zod types
- Follow the established folder structure for consistency
- Test CRUD operations thoroughly
- Verify form validation works correctly
- Check pagination and search functionality