You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: add repository method conventions to knowledge base (calcom#24443)
- Add comprehensive repository method naming conventions
- Include examples for method naming patterns
- Document separation of concerns between repositories and services
- Emphasize reusability and generic method naming
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: .agents/knowledge-base.md
+218Lines changed: 218 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -306,6 +306,224 @@ import { Button } from "@calcom/ui/components/button";
306
306
-**Tests**: Same as source file + `.test.ts` or `.spec.ts`
307
307
-**Avoid**: Dot-suffixes like `.service.ts`, `.repository.ts` (except for tests, types, specs)
308
308
309
+
## Repository Method Conventions
310
+
311
+
Repositories should follow consistent naming and design patterns to promote reusability and maintainability.
312
+
313
+
### Method Naming Rules
314
+
315
+
**1. Don't include the repository's entity name in method names**
316
+
317
+
Method names should be concise and avoid redundancy since the repository class name already indicates the entity type.
318
+
319
+
```typescript
320
+
// ✅ Good - Concise method names
321
+
classBookingRepository {
322
+
findById(id:string) { ... }
323
+
findByUserId(userId:string) { ... }
324
+
create(data:BookingCreateInput) { ... }
325
+
delete(id:string) { ... }
326
+
}
327
+
328
+
// ❌ Bad - Redundant entity name in methods
329
+
classBookingRepository {
330
+
findBookingById(id:string) { ... }
331
+
findBookingByUserId(userId:string) { ... }
332
+
createBooking(data:BookingCreateInput) { ... }
333
+
deleteBooking(id:string) { ... }
334
+
}
335
+
```
336
+
337
+
**2. Use `include` or similar keywords for methods that fetch relational data**
338
+
339
+
When a method retrieves additional related entities, make this explicit in the method name using keywords like `include`, `with`, or `andRelations`.
340
+
341
+
```typescript
342
+
// ✅ Good - Clear indication of included relations
343
+
classEventTypeRepository {
344
+
findById(id:string) {
345
+
returnprisma.eventType.findUnique({
346
+
where: { id },
347
+
});
348
+
}
349
+
350
+
findByIdIncludeHosts(id:string) {
351
+
returnprisma.eventType.findUnique({
352
+
where: { id },
353
+
include: {
354
+
hosts: true,
355
+
},
356
+
});
357
+
}
358
+
359
+
findByIdIncludeHostsAndSchedule(id:string) {
360
+
returnprisma.eventType.findUnique({
361
+
where: { id },
362
+
include: {
363
+
hosts: true,
364
+
schedule: true,
365
+
},
366
+
});
367
+
}
368
+
}
369
+
370
+
// ❌ Bad - Unclear what data is included
371
+
classEventTypeRepository {
372
+
findById(id:string) {
373
+
returnprisma.eventType.findUnique({
374
+
where: { id },
375
+
include: {
376
+
hosts: true,
377
+
schedule: true,
378
+
},
379
+
});
380
+
}
381
+
382
+
findByIdForReporting(id:string) {
383
+
returnprisma.eventType.findUnique({
384
+
where: { id },
385
+
include: {
386
+
hosts: true,
387
+
},
388
+
});
389
+
}
390
+
}
391
+
```
392
+
393
+
**3. Keep methods generic and reusable - avoid use-case-specific names**
394
+
395
+
Repository methods should be general-purpose and describe what data they return, not how or where it's used. This promotes code reuse across different features.
0 commit comments