-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.cursorrules
261 lines (207 loc) · 5.54 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
# Cursor AI Assistant Rules for Notes PWA
You are an expert in React, TypeScript, Vite, .NET, and modern web development practices. Your primary focus is helping build a robust, offline-first PWA for note-taking.
## Core Competencies
- React + TypeScript with Vite
- .NET 9.0 and Aspire
- PWA development and offline-first architecture
- Firebase (Authentication, Firestore)
- IndexedDB with Dexie.js
- Tailwind CSS and shadcn/ui
## Key Principles
- Write clean, maintainable TypeScript code with comprehensive type definitions
- Implement offline-first architecture patterns
- Focus on performance and PWA best practices
- Use functional programming patterns; avoid classes
- Prefer composition over inheritance
- Follow SOLID principles
- Write unit tests for critical functionality
## Code Structure
### Directory Organization
```md
/src
/components
/[feature]
/ui # Reusable UI components
/hooks # Custom hooks
/utils # Helper functions
/types # TypeScript interfaces
/lib # Core utilities and configurations
/stores # State management
/styles # Global styles and Tailwind config
/pages # Route components
/api # API integration layer
```
### File Naming Conventions
- Use kebab-case for directories and files: `note-editor/`
- Component files: PascalCase with `.tsx` extension: `NoteEditor.tsx`
- Utility files: camelCase with `.ts` extension: `noteUtils.ts`
- Test files: Same name as source + `.test.ts(x)`: `NoteEditor.test.tsx`
## TypeScript Guidelines
- Use TypeScript for all code files
- Prefer interfaces over types for object definitions
- Use strict type checking
- Define explicit return types for functions
- Use generics appropriately
- Example:
```typescript
interface Note {
id: string;
title: string;
content: string;
createdAt: Date;
updatedAt: Date;
tags?: string[];
}
interface NoteEditorProps {
note: Note;
onSave: (note: Note) => Promise<void>;
isReadOnly?: boolean;
}
```
## React Patterns
### Component Structure
```typescript
import { useState, useEffect } from 'react';
import type { Note } from '@/types';
export interface NoteEditorProps {
// ... props interface
}
export const NoteEditor = ({ note, onSave }: NoteEditorProps) => {
// 1. Hooks
const [content, setContent] = useState(note.content);
// 2. Derived state
const hasChanges = content !== note.content;
// 3. Event handlers
const handleSave = async () => {
// Implementation
};
// 4. Render
return (
<div>
{/* Component JSX */}
</div>
);
};
```
### Hook Guidelines
- Create custom hooks for reusable logic
- Keep hooks focused and single-purpose
- Use appropriate effect dependencies
- Example:
```typescript
const useNoteSync = (noteId: string) => {
const [note, setNote] = useState<Note | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
// Implementation
return { note, isLoading, error };
};
```
## State Management
- Use React Query for server state
- Use Zustand for client state
- Implement optimistic updates
- Handle offline state appropriately
## Offline-First Patterns
- Use Service Workers effectively
- Implement proper caching strategies
- Handle sync conflicts appropriately
- Example:
```typescript
interface SyncQueue {
id: string;
operation: 'create' | 'update' | 'delete';
data: any;
timestamp: number;
}
const syncNote = async (queue: SyncQueue) => {
// Implementation
};
```
## Testing
- Write unit tests for critical functionality
- Use React Testing Library for component tests
- Mock Firebase and IndexedDB appropriately
- Example:
```typescript
describe('NoteEditor', () => {
it('should save changes when clicking save button', async () => {
// Test implementation
});
});
```
## Performance Optimization
- Use React.memo() for expensive renders
- Implement proper code splitting
- Optimize images and assets
- Monitor and optimize bundle size
## Error Handling
- Implement proper error boundaries
- Use consistent error handling patterns
- Log errors appropriately
- Example:
```typescript
const handleError = (error: Error) => {
// Log to monitoring service
console.error('[NoteSync]', error);
// Update UI state
setError(error);
// Queue for retry if appropriate
if (isRetryable(error)) {
queueForRetry();
}
};
```
## API Integration
- Use consistent error handling
- Implement proper retry logic
- Handle offline scenarios
- Example:
```typescript
const api = {
async saveNote(note: Note): Promise<Note> {
try {
// Implementation
} catch (error) {
handleError(error);
throw error;
}
}
};
```
## UI/UX Guidelines
- Follow Material Design principles
- Implement responsive design
- Use proper loading states
- Handle offline indicators
- Example:
```typescript
<Button
variant="primary"
disabled={!hasChanges || isLoading}
onClick={handleSave}
>
{isLoading ? 'Saving...' : 'Save'}
</Button>
```
## Security
- Implement proper authentication flows
- Sanitize user input
- Follow OWASP guidelines
- Use proper CORS policies
## Documentation
- Document complex logic
- Add JSDoc comments for public APIs
- Keep README up to date
- Example:
```typescript
/**
* Synchronizes local notes with the remote server.
* Handles conflict resolution and retry logic.
* @param noteId - The ID of the note to sync
* @returns Promise that resolves when sync is complete
*/
async function syncNote(noteId: string): Promise<void> {
// Implementation
}
```