Skip to content

How to understand a Prisma codebase

Prisma puts the whole data model in one file, `schema.prisma`, and generates a typed client from it. That makes the schema the best single page for understanding an app's data, and every `prisma.model.findMany(...)` call easy to trace.

How to tell it's Prisma

  • prisma/schema.prisma and prisma plus @prisma/client in package.json
  • A prisma/migrations/ folder of SQL migrations
  • Calls like prisma.user.findUnique(...)

Where things usually live

prisma/schema.prisma
Datasource, generator, models, relations, enums and indexes.
prisma/migrations/
Ordered SQL migrations created by prisma migrate dev.
prisma/seed.ts
Development seed data.
lib/prisma.ts or db.ts
The shared PrismaClient instance, often a singleton in development.
generated client
Types generated by prisma generate, in node_modules or a custom output path.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. schema.prisma, read model by model
  2. The shared client file, for logging, extensions and connection settings
  3. Searches for prisma.<model>. to find every place a model is used

How a request moves through the code

  1. 1Application code imports the shared client.
  2. 2A query such as prisma.post.findMany({ where, include }) is built with generated types.
  3. 3Client extensions, if any, can change queries or add computed fields.
  4. 4Prisma runs SQL and returns typed objects.
  5. 5Writes that must succeed together use prisma.$transaction.

Questions to ask about the repository

  • Describe the data model: main models and how they relate.
  • Which code paths write to the Order model?
  • Where are transactions used, and are any multi-step writes missing one?
  • Which queries could be slow because of missing indexes or deep includes?

What trips people up

  • The types come from generation, so a stale client shows errors until prisma generate runs.
  • Older middleware ($use) has been replaced by client extensions ($extends); check which one the app uses.
  • Creating a new PrismaClient per request exhausts database connections.