forked from wishonia/wishonia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.cursorrules
162 lines (139 loc) · 3.75 KB
/
.cursorrules
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Project-specific rules for Cursor AI
[project]
name = "wishonia"
framework = "next.js"
version = "15.0"
router = "app"
style = "tailwind"
typescript = true
package_manager = "pnpm"
# Logging guidelines
[logging]
usage = """
import { logger } from '@/lib/logger'
✅ DO:
- Simple logs:
logger.info('Operation completed')
logger.debug('Debug details', { userId: 123, action: 'signup' })
- Error logs (auto-sent to Sentry):
logger.error('Operation failed', error)
logger.error('Operation failed', {
error,
metadata: { operation: 'signup' }
})
- Structured data:
logger.info('Search results', { results, count, query })
logger.warn('Rate limit', rateLimitData)
❌ DON'T:
- Use console.log/warn/error directly
- Log sensitive data (passwords, tokens)
- Create new logger instances
"""
# Define the project's architecture and conventions
[architecture]
server_components = [
"app/**/page.tsx",
"app/**/layout.tsx",
"app/**/template.tsx"
]
client_components = [
"components/**/*.tsx",
"app/**/components/*.tsx"
]
hooks = ["lib/hooks/**/*.ts"]
utils = ["lib/**/*.ts"]
config = ["config/**/*.ts"]
types = ["types/**/*.ts"]
# Component and Authentication Guidelines
[components]
server = """
IMPORTANT: Server Components (pages)
- Never add 'use client' to page.tsx files
- No hooks or browser APIs
- Fetch data server-side when possible
- Import client components as needed
Auth Usage:
In the page.tsx file, import the session from next-auth/next and redirect to the signin page if the user is not authenticated.
import { getServerSession } from "next-auth/next"
import { authOptions } from "@/lib/auth"
const session = await getServerSession(authOptions)
if (!session?.user) {
redirect(`/signin?callbackUrl=/my-page`)
}
"""
client = """
When to use client components:
- Uses hooks (useState, useEffect, etc.)
- Needs browser APIs
- Has user interactions
- Uses client-side libraries
Location: app/my-feature/components/InteractiveComponent.tsx
Auth Usage:
import { useSession } from 'next-auth/react'
const { data: session } = useSession()
"""
# Next.js App Router conventions
[next]
routing = """
- Use app directory for all routes
- page.tsx files are automatically server components
- loading.tsx for loading states
- error.tsx for error handling
- layout.tsx for shared layouts
"""
data_fetching = """
- Use server components for data fetching when possible
- Leverage React Server Components for better performance
- Use route handlers (route.ts) for API endpoints
"""
# Type Safety and Database
[code_quality]
types = """
- Use TypeScript strict mode
- Import Prisma types directly from @prisma/client
- Create interfaces for component props
- Avoid 'any' type
- Always prefer schema.prisma types over creating new ones
Example:
import { Post, User } from '@prisma/client'
"""
best_practices = """
✅ DO:
- Keep pages as server components
- Create separate client components for interactivity
- Use self-documenting names
- Choose simple implementations
- Use proper auth imports based on component type
❌ DON'T:
- Mix client and server code in same component
- Create new types when Prisma types exist
- Use cryptic or abbreviated names
"""
# Performance guidelines
performance = """
- Keep pages as server components when possible
- Use client components only when necessary
- Implement proper code splitting
- Use React Suspense boundaries wisely
"""
# File patterns to ignore
[ignore]
patterns = [
"node_modules",
".next",
"build",
"dist",
"public/assets",
".git"
]
# Testing guidelines
[testing]
jest = """
- Always set @jest-environment node at the top of test files
- Write tests that can safely run against production
- Use real implementations instead of mocks where possible
Example header:
/**
* @jest-environment node
*/
"""