-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy path.cursorrules
More file actions
301 lines (235 loc) · 7.6 KB
/
.cursorrules
File metadata and controls
301 lines (235 loc) · 7.6 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
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
# React Ecommerce Boilerplate - Cursor Rules
## Project Overview
This is a comprehensive ecommerce boilerplate built with:
- **Monorepo**: Turborepo for managing multiple packages
- **Frontend**: Next.js 14+ with App Router, PandaCSS for styling
- **Backend**: NestJS + Prisma + GraphQL (Apollo Server)
- **Database**: PostgreSQL
- **SDK**: React context providers with Axios client and React Query hooks
- **Design System**: PandaCSS-based component library with theming
## Working with This Project
### Architecture Overview
```
/apps
/web → Customer-facing ecommerce (Next.js 14+)
/admin → Admin dashboard (Next.js 14+)
/server → Backend API (NestJS + Prisma + GraphQL)
/docs → Developer documentation (Markdown)
/packages
/design-system → PandaCSS components with theming
/sdk → React providers, API client, and hooks
/eslint-config-custom → Shared ESLint config
/tsconfig → Shared TypeScript config
```
### Key Technologies
1. **Backend (NestJS + Prisma)**
- Database: PostgreSQL with Prisma ORM
- API: GraphQL with Apollo Server
- Auth: JWT + OAuth (Google, GitHub)
- All resolvers use Prisma for database access
2. **SDK Package**
- Name: `@react-shop/sdk`
- Provides: `SdkProvider`, `ApiProvider`, `QueryProvider`
- Services organized by domain: `services/auth/`, `services/products/`, etc.
- Each service has `queries.ts` and `mutations.ts`
- Uses Axios client with automatic token management
3. **Design System**
- Name: `@react-shop/design-system`
- Styling: PandaCSS (zero-runtime)
- Themes: Light/dark mode with semantic tokens
- Components: Layout, Typography, Forms, Ecommerce-specific
### Development Workflow
1. **Starting Development**
```bash
yarn install
yarn dev # Starts all apps in parallel
```
2. **Database Migrations**
```bash
cd apps/server
yarn prisma migrate dev --name migration_name
yarn prisma generate
```
3. **Adding New Components to Design System**
- Create component in `packages/design-system/src/components/`
- Use PandaCSS styling with `css()` or `styled()`
- Export from `packages/design-system/src/components/index.ts`
4. **Adding New Services to SDK**
- Create folder in `packages/sdk/src/services/`
- Add `queries.ts` with React Query hooks using `useQuery`
- Add `mutations.ts` with React Query hooks using `useMutation`
- Use `useApiClient()` hook to access Axios instance
- Export from service `index.ts` and main `services/index.ts`
5. **Backend Development**
- Create modules in `apps/server/src/`
- Each module has: service, resolver, DTOs
- Use PrismaService for database operations
- GraphQL schema in `apps/server/src/graphql/schemas/schema.gql`
### Code Patterns
1. **SDK Service Pattern**
```typescript
// queries.ts
import { useQuery } from '@tanstack/react-query';
import { useApiClient } from '../../providers/ApiProvider';
export const useListItems = () => {
const { client } = useApiClient();
return useQuery({
queryKey: ['items'],
queryFn: async () => {
const { data } = await client.post('', {
query: `query { items { id name } }`,
});
return data.data.items;
},
});
};
```
2. **NestJS Resolver Pattern**
```typescript
@Resolver('Item')
export class ItemResolver {
constructor(private itemService: ItemService) {}
@Query('items')
@UseGuards(JwtAuthGuard)
async getItems(@CurrentUser() user: any) {
return this.itemService.getItems();
}
}
```
3. **PandaCSS Component Pattern**
```typescript
import { styled } from '../../../styled-system/jsx';
export const Component = styled('div', {
base: {
p: '4',
borderRadius: 'md',
},
});
```
### Important Notes
- **Always use the SDK providers** - Wrap apps with `<SdkProvider>`
- **Use semantic tokens** - Prefer `bg.surface` over `white`
- **Follow feature structure** - Organize by domain, not by type
- **Update documentation** - Add docs for new features in `apps/docs/`
- **Type safety** - Always use TypeScript, no `any` types
- **Prisma first** - Use Prisma for all database operations
## Commit Convention Rule
### When Finishing a New Feature
**ALWAYS create a commit using Conventional Commits with simple, concise messages.**
### Format
```
<type>: <simple description>
```
### Types
- `feat` - New feature
- `fix` - Bug fix
- `docs` - Documentation changes
- `style` - Code style changes (formatting, no logic change)
- `refactor` - Code refactoring
- `perf` - Performance improvements
- `test` - Adding or updating tests
- `chore` - Maintenance tasks (dependencies, config)
### Rules
1. **Keep it simple** - No need for long explanations
2. **Use imperative mood** - "add" not "added", "fix" not "fixed"
3. **No period at the end** - Keep it clean
4. **Max 50 characters** for the subject line
5. **One feature per commit** - Don't bundle multiple features
### Examples
✅ **Good:**
```
feat: add product search functionality
fix: cart total calculation
docs: update SDK usage examples
refactor: extract auth logic to service
chore: update dependencies
```
❌ **Bad:**
```
feat: Added a new product search functionality with filters and sorting options that allows users to...
fixed the bug
update
WIP
changes
```
### When to Commit
- ✅ After completing a feature
- ✅ After fixing a bug
- ✅ After updating documentation
- ✅ After refactoring code
- ❌ Don't commit incomplete work with "WIP"
- ❌ Don't commit debugging code or console.logs
### Multi-Part Features
For features spanning multiple commits, use scope:
```
feat(products): add list endpoint
feat(products): add detail endpoint
feat(products): add search functionality
```
### Breaking Changes
If introducing breaking changes, add `!` after type:
```
feat!: migrate from services to sdk package
refactor!: change API response format
```
Or add BREAKING CHANGE in body:
```
feat: migrate to new SDK architecture
BREAKING CHANGE: Package renamed from @react-shop/services to @react-shop/sdk
```
## Additional Rules
### Code Quality
1. **Always run linter** before committing
2. **Fix linter errors** - Don't ignore them
3. **Write meaningful variable names** - No `x`, `y`, `temp`
4. **Add JSDoc comments** for complex functions
5. **Extract magic numbers** to named constants
### Testing
1. **Write tests** for new features (when applicable)
2. **Run tests** before committing
3. **Mock SDK** in component tests
### Documentation
1. **Update README** when adding major features
2. **Add examples** in `apps/docs/` for new APIs
3. **Document breaking changes** clearly
4. **Update IMPLEMENTATION_STATUS.md** when completing todos
### Don't Do
- ❌ Don't commit directly to `main` without review
- ❌ Don't commit with failing tests
- ❌ Don't commit with linter errors
- ❌ Don't commit `console.log` statements
- ❌ Don't commit commented-out code
- ❌ Don't commit TODO comments without context
- ❌ Don't use `any` type in TypeScript
- ❌ Don't skip error handling
## Quick Reference
### Start Development
```bash
pnpm install
pnpm dev
```
### Database Commands
```bash
cd apps/server
pnpm prisma migrate dev
pnpm prisma studio
pnpm prisma generate
```
### Add New Package
```bash
pnpm add <package> --filter <workspace-name>
```
### Build for Production
```bash
pnpm build
```
### Run Linter
```bash
pnpm lint
```
## Resources
- [Documentation](./apps/docs/README.md)
- [Features Overview](./FEATURES.md)
- [Implementation Status](./IMPLEMENTATION_STATUS.md)
- [SDK Documentation](./packages/sdk/README.md)
- [Design System](./packages/design-system/README.md)