68cdfd42b1
* docs: add Repository + DTO pattern guidance for Prisma type isolation Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * docs: add 'Why this pattern?' section explaining benefits of Repository + DTO Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> * docs: condense Repository + DTO pattern guidance for readability Co-Authored-By: eunjae@cal.com <hey@eunjae.dev> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
63 lines
1.3 KiB
Markdown
63 lines
1.3 KiB
Markdown
# Coding Standards & Best Practices
|
|
|
|
|
|
|
|
## Import Guidelines
|
|
|
|
### Type Imports
|
|
|
|
```typescript
|
|
// ✅ Good - Use type imports for TypeScript types
|
|
import type { User } from "@prisma/client";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
// ❌ Bad - Regular import for types
|
|
import { User } from "@prisma/client";
|
|
```
|
|
|
|
|
|
|
|
## Code Structure
|
|
|
|
### Early Returns
|
|
|
|
- Prefer early returns to reduce nesting: `if (!booking) return null;`
|
|
|
|
### Composition Over Prop Drilling
|
|
|
|
- Use React children and context instead of passing props through multiple components
|
|
|
|
### ORM and Types
|
|
|
|
- Never import `@calcom/prisma/client` in features, services, UI, or handlers.
|
|
- Use repository DTOs or domain types instead.
|
|
- See "Repository + DTO Pattern and Method Conventions" in the knowledge base for details and examples.
|
|
|
|
### Security Rules
|
|
|
|
```typescript
|
|
// ❌ NEVER expose credential keys
|
|
const user = await prisma.user.findFirst({
|
|
select: {
|
|
credentials: {
|
|
select: {
|
|
key: true, // ❌ NEVER do this
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ✅ Good - Never select credential.key field
|
|
const user = await prisma.user.findFirst({
|
|
select: {
|
|
credentials: {
|
|
select: {
|
|
id: true,
|
|
type: true,
|
|
// key field is excluded for security
|
|
}
|
|
}
|
|
}
|
|
});
|
|
```
|