Prisma
Audited from github.com/prisma/prisma
Prisma is an open-source next-generation ORM for Node.js and TypeScript that provides type-safe database access, schema migrations, and query generation.
- Language
- TypeScript
- Database
- PostgreSQL
- Hosting
- Docker
- License
- Apache-2.0
- Running for
- 6 years
- Team
- 1M+ MAU
Why this architecture
Declarative schema modeling combined with modular driver adapters allows Prisma to generate fully type-safe database clients that run consistently from Node servers to edge runtimes.
Tech stack by layer
8 technologies · audited Sep 17, 2026- JavaScriptClient code generators, CLI formatting scripts, and telemetry reporting helpers.
- TypeScriptCore language power across the compiler, schema parser, AST models, and client generators.
- Node.jsPrimary runtime environment targeting Node.js 20.19 or higher across monorepo packages.
- PostgreSQLRelational target with full support for migrations, schema introspection, and connection pools.
- MySQLSupported relational database target tested continuously in docker-compose test fixtures.
- SQLiteEmbedded file-based database target used for lightweight development and edge runtimes.
- MongoDBDocument database target managed through dedicated mongo-family and mongo-target packages.
Prisma architecture diagram
Open SVGDiagram as text
- schema.prisma (data models) → Generator (schema AST to TS types): prisma generate
- Generator (schema AST to TS types) → Prisma Client (typed queries): typed client
- Application code (TypeScript · Node.js 20.19+) → Prisma Client (typed queries): queries
- Prisma Client (typed queries) → Driver adapters (pg · planetscale · d1): SQL
- Driver adapters (pg · planetscale · d1) → PostgreSQL: driver
- Driver adapters (pg · planetscale · d1) → MySQL: driver
- Driver adapters (pg · planetscale · d1) → SQLite: driver
- Prisma Client (typed queries) → MongoDB: mongo target
- Prisma CLI (migrate · introspect) → PostgreSQL: migrations
Key architectural decisions
5 decisions- 01
Tiered numeric package hierarchy enforces unidirectional architectural dependencies
Packages in pnpm-workspace.yaml are strictly structured into numeric tiers (0-config, 1-framework, 2-sql, 3-targets, 9-public), preventing cyclic dependencies and enforcing strict layering from shared core up to public entrypoints.
- 02
Driver adapter architecture enables universal serverless and edge compatibility
Prisma Client delegates database transport to modular driver adapters (pg, @prisma/adapter-pg, @prisma/adapter-planetscale, @prisma/adapter-d1), allowing queries to execute natively on Cloudflare Workers, Vercel Edge, and Node.js without binary engines.
- 03
Declarative schema modeling with deterministic type generation
Developers define data models in schema.prisma. The generator compiles the schema AST directly into strongly typed TypeScript interfaces that provide compile-time auto-completion and type safety.
- 04
Biome and dependency-cruiser for high-speed automated code quality guardrails
The repository replaced legacy ESLint setups with Biome (biome.jsonc) for sub-second linting and formatting, backed by dependency-cruiser (dependency-cruiser.config.mjs) to enforce package boundary invariants.
- 05
Comprehensive multi-engine integration test harness in Docker
docker-compose.yaml provisions concurrent database instances for PostgreSQL, MySQL 8, MariaDB, SQL Server, and MongoDB, ensuring that query generation passes parity tests across all SQL dialects.
How Prisma is built
How Prisma is structured
Prisma is structured as a layered TypeScript monorepo managed with pnpm (pnpm-workspace.yaml, package.json). The repository enforces a strict numerical tiered architecture that prevents circular dependencies and provides clear separation between compilation, intermediate representations, and target database connectors:
packages/0-config/andpackages/0-shared/: Foundational types, shared utilities, logging infrastructure, and build configuration helpers consumed across all subsequent tiers.packages/1-framework/: Core schema modeling libraries, intermediate representation AST parsers, and validation engines that process Prisma schema files.packages/2-sql/,packages/2-document/, andpackages/2-mongo-family/: Dialect-specific query planning abstractions that translate generic ORM operations into SQL statements or document database commands.packages/3-targets/andpackages/3-extensions/: Database engine adapters and extension interfaces connecting the framework to concrete runtime drivers.packages/9-public/: The top-level public packages published to npm, including@prisma/clientand theprismaCLI.
Frontend
Prisma is primarily a developer tool and library ecosystem rather than a customer-facing web application. However, developer-facing interactive tools are maintained within the ecosystem:
apps/lsp-playground/: An interactive language server playground for testing Prisma schema autocompletion, hover documentation, and syntax diagnostics in web browsers.- Schema documentation and developer guides are authored in
docs/using Markdown and MDX.
Backend & APIs
The core Prisma toolchain runs on Node.js 20.19+ (package.json) and is implemented in TypeScript. The system operates in two distinct phases:
- Build / Generation Phase: The CLI parses
schema.prisma, validates model relationships, field attributes (@id,@default,@relation), and generator configurations. It synthesizes a strongly typed@prisma/clientpackage directly into the consumer'snode_modules(or a custom output directory), generating bespoke TypeScript typings tailored to the user's specific database schema. - Runtime Query Execution: At runtime, client queries (such as
prisma.user.findMany({ include: { posts: true } })) construct query plans. Prisma's query compiler translates nested relation queries into optimized SQL statements using JOINs or batched lookups, validates return shapes, and deserializes database rows into typed JavaScript objects.
Modern versions of Prisma leverage JavaScript Driver Adapters (@prisma/adapter-pg, @prisma/adapter-neon, @prisma/adapter-planetscale, @prisma/adapter-d1). Instead of requiring native Rust binary query engines on the target host, driver adapters allow the client to delegate TCP connections and TLS handshakes to standard JavaScript database drivers, unlocking native execution on Cloudflare Workers, Vercel Edge Functions, and AWS Lambda.
Data & persistence
Prisma provides an abstraction layer across major relational and document database engines:
- Relational Databases: Comprehensive support for PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server, and CockroachDB. The engine manages schema migrations (
prisma migrate), introspects existing production databases (prisma db pull), and optimizes query ASTs for specific dialect quirks. - Document Databases: MongoDB support is isolated within
packages/2-mongo-family/, translating Prisma operations into MongoDB BSON queries and aggregation pipelines. - Connection Management: Connection pooling, transaction timeouts, and retry logic are managed through unified driver interfaces, supporting both direct connection pools and connection poolers such as PgBouncer or Prisma Accelerate.
Build, test & deploy
The development and integration pipeline uses modern, performant tooling:
- Package Management: Dependencies and monorepo workspaces are managed via pnpm (
pnpm@10.15.1), enforcing strict isolation between workspace packages. - Code Quality: Fast linting and code formatting run via Biome (
biome.jsonc), whiledependency-cruiser(dependency-cruiser.config.mjs) continuously asserts that packages in lower tiers never import from higher tiers. - Matrix Testing:
docker-compose.yamlorchestrates local database services (PostgreSQL 16, MySQL 8, MariaDB, SQL Server, and MongoDB). GitHub Actions workflows run extensive end-to-end integration suites across all supported database versions.
Self-hosting notes
As an embedded library and client generator, Prisma does not require standalone server infrastructure to operate. Applications using Prisma deploy the generated @prisma/client code directly alongside their application server (Node.js, Next.js, Fastify, Express, or serverless functions). Database credentials are provided via environment variables (DATABASE_URL), and database migration commands (prisma migrate deploy) typically run as automated pre-deployment pipeline steps.
What to copy (and what not to)
Architectural patterns to emulate from Prisma:
- Strictly tiered package organization: Enforcing numeric tier prefixes in monorepo packages (
0-configto9-public) creates a self-documenting dependency graph that prevents spaghetti imports and cyclic dependencies. - Driver adapter decoupling for edge portability: Decoupling the high-level query compiler from low-level network transports enables a single ORM to run on traditional server clusters and edge serverless runtimes.
- Declarative schema as the single source of truth: Deriving database schemas, TypeScript interfaces, and runtime validators from a single declarative schema file guarantees that documentation, database migrations, and application code stay synchronized.
Avoid attempting to write a universal ORM abstraction that spans both relational and document databases unless your project is prepared to maintain multiple parallel query compilation engines, as relational joins and document aggregations have fundamentally different query semantics.
Sources & repo audit
- Audited
- Sep 17, 2026
- Commit
- 1c434a7
- License
- Apache-2.0
- package.json (pnpm 10 workspace scripts, Node 20.19+ engine requirement, Biome)
- pnpm-workspace.yaml (Layered package hierarchy from 0-config to 9-public)
- docker-compose.yaml (Test database matrix: PostgreSQL, MySQL, MariaDB, SQL Server, MongoDB)
- docs/Architecture Overview.md (Internal compiler architecture, AST models, and code generation)
Independent analysis of repository at github.com/prisma/prisma. Spotted an inaccuracy? Use the claim form to request a correction.
Show this stack on your README or website
[](https://stackitfast.com/project/prisma)Paste it into your README. It shows your current stack and links to this page.
Scaffold it with your agent
Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with Prisma's architecture.
- 1Copy the promptThe full markdown spec, with every layer and decision.
- 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
- 3Paste and scaffoldUse it as the first instruction; review before you ship.
# MISSION: Scaffold "Prisma" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **Prisma**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: Prisma
- **What It Does**: Prisma is an open-source next-generation ORM for Node.js and TypeScript that provides type-safe database access, schema migrations, and query generation.
- **Domain & Category**: Next-Generation Node.js & TypeScript ORM
- **Production Scale**: 1M+ MAU
- **Development Mode**: CLASSIC
- **Architectural Rationale**: Declarative schema modeling combined with modular driver adapters allows Prisma to generate fully type-safe database clients that run consistently from Node servers to edge runtimes.
- **Live Website Reference**: https://www.prisma.io
- **Source Repository**: https://github.com/prisma/prisma
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: TypeScript, JavaScript, PostgreSQL, MySQL, SQLite, MongoDB, pnpm, Docker
- **Primary Language(s)**: TypeScript, JavaScript
- **License of the reference repo**: Apache-2.0
- **Frontend**: JavaScript — Client code generators, CLI formatting scripts, and telemetry reporting helpers.
- **Backend & APIs**: TypeScript — Core language power across the compiler, schema parser, AST models, and client generators.; Node.js — Primary runtime environment targeting Node.js 20.19 or higher across monorepo packages.
- **Data & persistence**: PostgreSQL — Relational target with full support for migrations, schema introspection, and connection pools.; MySQL — Supported relational database target tested continuously in docker-compose test fixtures.; SQLite — Embedded file-based database target used for lightweight development and edge runtimes.; MongoDB — Document database target managed through dedicated mongo-family and mongo-target packages.
- **Infrastructure & deploy**: pnpm — Workspace package manager managing strict dependency resolution and monorepo linking.; Docker — Docker Compose environment provisioning local PostgreSQL, MySQL, and Mongo test services.
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/prisma/prisma @ 1c434a7)
1. **Tiered numeric package hierarchy enforces unidirectional architectural dependencies**: Packages in pnpm-workspace.yaml are strictly structured into numeric tiers (0-config, 1-framework, 2-sql, 3-targets, 9-public), preventing cyclic dependencies and enforcing strict layering from shared core up to public entrypoints.
2. **Driver adapter architecture enables universal serverless and edge compatibility**: Prisma Client delegates database transport to modular driver adapters (pg, @prisma/adapter-pg, @prisma/adapter-planetscale, @prisma/adapter-d1), allowing queries to execute natively on Cloudflare Workers, Vercel Edge, and Node.js without binary engines.
3. **Declarative schema modeling with deterministic type generation**: Developers define data models in schema.prisma. The generator compiles the schema AST directly into strongly typed TypeScript interfaces that provide compile-time auto-completion and type safety.
4. **Biome and dependency-cruiser for high-speed automated code quality guardrails**: The repository replaced legacy ESLint setups with Biome (biome.jsonc) for sub-second linting and formatting, backed by dependency-cruiser (dependency-cruiser.config.mjs) to enforce package boundary invariants.
5. **Comprehensive multi-engine integration test harness in Docker**: docker-compose.yaml provisions concurrent database instances for PostgreSQL, MySQL 8, MariaDB, SQL Server, and MongoDB, ensuring that query generation passes parity tests across all SQL dialects.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
- Structure as a Turborepo monorepo with strict package boundaries:
- `apps/web`: Application UI, routing, layouts, and server endpoints.
- `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
- `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
- `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
- Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
- Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
- Isolate interactive UI state to leaf components. Keep core pages lightweight and performant.
4. **Design System & Aesthetics**:
- Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
- Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
- Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
- Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (PostgreSQL, MySQL, SQLite, MongoDB): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.Frequently asked about Prisma
What is Prisma built with?
Prisma is written in TypeScript and JavaScript as a pnpm monorepo, providing an ORM, schema compiler, migration engine, and query generator for Node.js and edge runtimes.
Does Prisma work in serverless and edge environments?
Yes. Through Prisma Driver Adapters, Prisma Client connects over standard JavaScript database drivers or HTTP/WebSocket transports, running on Cloudflare Workers, Fastly, and Vercel.
Which databases does Prisma support?
Prisma supports PostgreSQL, MySQL, MariaDB, SQLite, Microsoft SQL Server, CockroachDB, and MongoDB.
How does Prisma guarantee type safety?
Prisma parses the declarative schema.prisma file and generates a custom TypeScript client tailored specifically to your models, ensuring queries and relation selections are validated at compile time.
One email a month: new deep dives and stack trends
New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.
Similar architectures
- GiteaClassicLightweight Self-Hosted Git Service · 20+ peopleShares TypeScript · SQLite · PostgreSQL
- GotifyClassicSelf-Hosted Real-Time Push Server · 2-5 PeopleShares TypeScript · SQLite · MySQL
- NextcloudClassicSelf-Hosted Collaborative Productivity Suite · 20+ peopleShares JavaScript · TypeScript · MySQL
- VaultwardenClassicLightweight Self-Hosted Password Vault · Solo / 2-5 peopleShares SQLite · PostgreSQL · MySQL
- StrapiClassicHeadless CMS · 20+ peopleShares TypeScript · PostgreSQL · SQLite
- AtuinClassicShell History Sync · 2-5 peopleShares SQLite · PostgreSQL · MySQL