Appearance
Rule: Use Prisma as the ORM
Status
Accepted
Scope
This rule applies to TypeScript API applications that use a relational database.
Context
Working directly with SQL for every database operation creates repetitive boilerplate and makes database models and schema changes harder to manage. Using an ORM simplifies the developer experience and database management by providing typed models, common database operations, relationship handling, and migration tooling.
An ORM can also hide SQL complexity and make some performance optimizations or database-specific features harder to express. The chosen ORM must therefore still allow SQL when the ORM abstraction is not the right fit.
Decision
We MUST use an ORM to access relational databases in TypeScript API applications. We choose Prisma because it is one of the most widely used ORMs in the TypeScript ecosystem and provides a productive typed API while still supporting raw SQL when necessary.
Rules
- Prisma MUST be the default ORM for relational database access in TypeScript API applications.
- Prisma's typed API SHOULD be used for common CRUD and relationship operations.
- Prisma schemas and migration files MUST be reviewed and committed with the application code.
- Raw SQL MAY be used for complex queries, performance-critical operations, or database-specific features that the typed API does not express well.
- Raw SQL MUST use parameterized query APIs. Untrusted input MUST NOT be concatenated into SQL strings.
Application-layer and module boundaries for Prisma access are outside the scope of this rule and will be defined separately.
Rationale
Prisma improves developer productivity and maintainability for routine database work while reducing the amount of handwritten mapping and CRUD code. Its adoption in the TypeScript ecosystem also makes it easier to find existing knowledge, tooling, and developer support.
The raw SQL capability preserves control for queries where an ORM would hide important performance or database-specific details.
Consequences
This decision gives TypeScript API projects a consistent database tool and a clear workflow for managing schema changes. Teams must still understand the SQL generated by Prisma and review query performance when needed. The application also becomes coupled to Prisma's API and conventions.
Exceptions
A project MAY use another ORM or direct SQL when Prisma cannot satisfy a documented technical requirement. The exception MUST explain the requirement and the chosen alternative.