Chapter
07 · TypeScript + Prisma
Prisma models storage; TypeScript models intent. Keep them related but distinct.
Mental Model
- Prisma schema = DB truth. TypeScript types = app contracts.
- Do not leak Prisma client types as public API; define app-facing types.
- Relations and seeds reflect reality; types express usage.
File Classification
Layer: Data modeling
Runtime: Build / server
Prisma: ✅ In schema/actions
App types: ✅ In types/
JSX: ❌ Never
Cross-entity imports: ❌ Avoid
Canonical Example (Types vs Prisma)
// prisma/schema.prisma
model Project {
id String @id @default(cuid())
name String
createdAt DateTime @default(now())
}
// app/(index)/projects/types/index.ts
export type Project = {
id: string;
name: string;
};
Quick Rules
- Prisma types stay near actions; app types live in types/.
- Use Pick/Omit/Partial on app types, not Prisma client types.
- Seeds mirror real relations; db push for proto, migrate for prod.