-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.cursorrules
366 lines (302 loc) · 9.68 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# .cursorrules
## Core Principles
1. **Team Workflow**:
- Only work on assigned features
- Don't modify unrelated code
- Ask team before making cross-feature changes
- Write clean, readable, maintainable code
2. **Supabase-First Development**:
- Always use Supabase features over custom implementations
- Leverage built-in functionality:
- Auth: Use Supabase Auth for all authentication/authorization
- Database: Use PostgreSQL features and RLS policies
- Real-time: Use Supabase's real-time subscriptions
- Edge Functions: Use Supabase Edge Functions for serverless logic
- Storage: Use Supabase Storage for file handling
- Before implementing custom solutions:
- Check Supabase documentation for existing features
- Consult team about Supabase capabilities
- Document why Supabase features weren't suitable (if custom solution needed)
3. **Architecture Overview**:
```plaintext
AutoCRM/
├── src/ # Application source
│ ├── features/ # Feature modules
│ │ ├── shared/ # Shared utilities
│ │ │ ├── components/ # Shared components
│ │ │ ├── styles/ # Global styles
│ │ │ │ ├── components/ # Component styles
│ │ │ │ ├── themes/ # Theme definitions
│ │ │ │ └── global/ # Global styles
│ │ │ └── utils/ # Shared utilities
│ │ └── types/ # Global types
│ ├── core/ # Base implementations
│ │ ├── supabase/ # Supabase integration
│ │ ├── api/ # API clients
│ │ └── config/ # App configuration
│ └── types/ # Global types
├── supabase/ # Supabase configuration
│ ├── migrations/ # Database migrations
│ │ └── [timestamp]_name.sql
│ ├── functions/ # Edge Functions
│ │ └── [function-name]/
│ │ ├── index.ts
│ │ └── schema.ts
│ ├── seed.sql # Seed data
│ └── config.toml # Supabase config
├── public/ # Static assets
├── dist/ # Build output
└── .env.* # Environment files
├── .env.example
├── .env.development
└── .env.production
```
## Feature Organization
1. **Feature Module Structure**:
```plaintext
feature-name/
├── components/ # UI Components
│ ├── FeatureComponent.tsx
│ └── index.ts # Barrel export
├── services/ # Business Logic
│ ├── FeatureService.ts
│ └── index.ts
├── hooks/ # Custom Hooks
│ ├── useFeature.ts
│ └── index.ts
├── store/ # State Management
│ ├── feature.store.ts
│ └── index.ts
├── types/ # Feature Types
│ ├── feature.types.ts
│ └── index.ts
├── __tests__/ # Tests
│ ├── components/
│ ├── hooks/
│ └── services/
├── __mocks__/ # Test mocks
└── index.ts # Public API
```
2. **Feature Boundaries**:
- Self-contained modules
- Clear public API through index.ts
- Cross-feature communication via stores only
- Feature-specific types in feature directory
## Naming & Type System
1. **File Naming**:
- Components: PascalCase.tsx (UserProfile.tsx)
- Services: PascalCase + 'Service'.ts (UserService.ts)
- Hooks: camelCase + 'use' prefix (useAuth.ts)
- Types: PascalCase + '.types.ts' (User.types.ts)
- Tests: Original + '.test.ts' (UserService.test.ts)
- Directories: kebab-case (user-management/)
2. **Type Organization**:
- Global: `@/types/`
```typescript
database.types.ts # Supabase schema
supabase.types.ts # Client types
common.types.ts # Shared utilities
```
- Feature: `@/features/[feature]/types/`
```typescript
state.types.ts # Store types
models.types.ts # Domain models
api.types.ts # API types
```
3. **Database Naming**:
- Tables: plural_snake_case (user_profiles)
- Columns: singular_snake_case (first_name)
- Keys: table_name_id (user_id)
- Indexes: idx_table_column (idx_users_email)
## Import & Path System
1. **Path Aliases**:
```typescript
// vite.config.ts
resolve: {
alias: {
'@': '/src',
'@features': '/src/features',
'@shared': '/src/shared',
'@core': '/src/core',
'@types': '/src/types'
}
}
```
2. **Import Organization**:
```typescript
// External packages
import React from 'react'
import { useQuery } from '@tanstack/react-query'
// Core & shared
import { Button } from '@/shared/components'
import { BaseService } from '@/core/base'
// Feature imports
import { UserProfile } from '@/features/user-management'
// Types
import type { User } from '@/types/models'
```
3. **Import Rules**:
- Use absolute imports with @/ prefix
- Import from feature's public API
- No deep imports into other features
- Group imports by category
## State Management
1. **Store Pattern**:
```typescript
interface FeatureState {
data: Data[]
loading: boolean
error: Error | null
}
interface FeatureActions {
fetch: () => Promise<void>
reset: () => void
}
```
2. **State Organization**:
- Feature state in feature/store
- Global state in core/store
- Local state with React hooks
- Cross-feature state via events
## Technical Integration
1. **Supabase Integration**:
- Database:
```sql
-- migrations/[timestamp]_create_users.sql
create table public.users (
id uuid references auth.users primary key,
created_at timestamptz default now(),
updated_at timestamptz default now()
);
-- Enable RLS
alter table public.users enable row level security;
-- Create policies
create policy "Users can view own data" on public.users
for select using (auth.uid() = id);
```
- Edge Functions:
```typescript
// functions/process-data/index.ts
import { serve } from 'https://deno.land/[email protected]/http/server.ts'
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
serve(async (req) => {
const supabase = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? ''
)
// Implementation
})
```
- Client Setup:
```typescript
// src/lib/supabase.ts
import { createClient } from '@supabase/supabase-js'
import type { Database } from '@/types/database.types'
export const supabase = createClient<Database>(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_ANON_KEYw
)
```
- Real-time Subscriptions:
```typescript
// In components/features
const subscription = supabase
.channel('table_db_changes')
.on(
'postgres_changes',
{ event: '*', schema: 'public', table: 'table_name' },
(payload) => {
// Handle change
}
)
.subscribe()
```
- Error Handling Pattern:
```typescript
try {
const { data, error } = await supabase.from('table').select()
if (error) throw error
} catch (error) {
logger.error('Operation failed', { error })
}
```
- Security:
- RLS policies for all tables
- Edge Functions for sensitive operations
- Proper auth token handling
- Regular security audits
2. **React Patterns**:
- Functional components
- Error boundaries
- Suspense for loading
- React Query for data
3. **UI Component System**:
- Use shadcn components as primary UI building blocks
- Only use direct TailwindCSS when shadcn components don't exist
- Extend shadcn components instead of creating new patterns
- Example shadcn usage:
```typescript
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
function LoginForm() {
return (
<form>
<Input type="email" placeholder="Email" />
<Button type="submit">Login</Button>
</form>
)
}
```
- TailwindCSS for custom styling only:
```typescript
const styles = {
customLayout: 'grid grid-cols-[1fr_2fr]', // No shadcn equivalent
specialText: 'font-mono tracking-tight' // Custom typography
}
```
## Quality Assurance
1. **Testing Structure**:
```plaintext
feature/
├── __tests__/
│ ├── components/
│ └── services/
└── __fixtures__/
```
2. **Error Handling**:
- Error boundaries
- Toast notifications
- Logging system
- Monitoring setup
3. **Performance**:
- Component memoization
- Query caching
- Bundle optimization
- Load time monitoring
4. **Accessibility**:
- ARIA attributes
- Keyboard navigation
- Screen reader support
- Contrast validation
## Version Control
1. **Git Workflow**:
```plaintext
type(scope): concise summary
- Detailed change 1
- Detailed change 2
```
2. **Branch Structure**:
- feature/feature-name
- fix/issue-description
- release/version
## Configuration
1. **Environment**:
```plaintext
VITE_SUPABASE_URL=url
VITE_SUPABASE_ANON_KEY=key
VITE_ENABLE_FEATURE_X=true
```
2. **Feature Flags**:
- Runtime controls
- Environment-based
- Feature toggles