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.prismaandprismaplus@prisma/clientinpackage.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
PrismaClientinstance, often a singleton in development. - generated client
- Types generated by
prisma generate, innode_modulesor a customoutputpath.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
schema.prisma, read model by model- The shared client file, for logging, extensions and connection settings
- Searches for
prisma.<model>.to find every place a model is used
How a request moves through the code
- Application code imports the shared client.
- A query such as
prisma.post.findMany({ where, include })is built with generated types. - Client extensions, if any, can change queries or add computed fields.
- Prisma runs SQL and returns typed objects.
- Writes 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
Ordermodel? - 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 generateruns. - Older middleware (
$use) has been replaced by client extensions ($extends); check which one the app uses. - Creating a new
PrismaClientper request exhausts database connections.