prisma/prisma
Client generation
How prisma generate turns a schema.prisma into a typed PrismaClient. Spans @prisma/cli, @prisma/internals, the Wasm PSL parser, the registered generators, and @prisma/ts-builders.
Components
graph LR
Schema[schema.prisma] --> CLI[prisma generate]
CLI --> INT[internals.getDMMF]
INT --> Wasm[prisma-schema-wasm]
Wasm --> DMMF[DMMF AST]
CLI --> GG[internals.getGenerators]
GG --> Reg[client-generator-registry]
Reg -->|prisma-client| GTS[client-generator-ts]
Reg -->|prisma-client-js| GJS[client-generator-js]
Reg -->|external| ExtGen[third-party generator via generator-helper]
GTS --> TSB[ts-builders]
GJS --> TSB
GTS --> Output[(./generated/...)]
GJS --> OutputEnd-to-end flow
- CLI dispatch.
prisma generateis parsed bypackages/cli/src/CLI.tsand dispatched toGenerate.ts. - Schema load.
Generateloads the schema via@prisma/internals(which delegates to@prisma/schema-files-loaderfor multi-file schemas). - DMMF compute.
getDMMF(in@prisma/internals) calls into@prisma/prisma-schema-wasmand returns a DMMF AST. - Generator enumeration.
getGeneratorsreadsgeneratorblocks from the schema, looks each one up in@prisma/client-generator-registry, and resolves them to a runner. Built-in:prisma-client(TS) andprisma-client-js(JS). External: anything that speaks the@prisma/generator-helperIPC. - Per-generator dispatch. For each generator, the CLI hands off the DMMF and the project config. Built-in generators run in-process; external generators are spawned as subprocesses and exchange JSON-RPC over stdio.
- Code emission. Each generator builds TypeScript via
@prisma/ts-buildersand writes files to the path declared in the generator block'soutputdirective.
DMMF
The Datamodel Meta Format is the JSON AST a generator consumes. See Glossary. It's marked internal: no stability guarantees across minor versions. From AGENTS.md:
The DMMF is a Prisma ORM internal API with no guarantees for stability to outside users. We might — and do — change the DMMF in potentially breaking ways between minor versions. 🐲
DMMF changes that break the in-tree generators are caught by snapshot tests in packages/internals/src/__tests__/. Snapshot diffs after an engine bump are the most common signal that DMMF has shifted.
Built-in generators
| Provider value | Generator | Module format target | Status |
|---|---|---|---|
prisma-client |
client-generator-ts |
Modern ESM/TS | Recommended |
prisma-client-js |
client-generator-js |
CJS-first | Maintained |
Both ship in every release. Both must be updated together when constructor options change (see @prisma/client runtime).
External generators
Third-party generators run as separate processes. They speak JSON-RPC over stdio using the contract from @prisma/generator-helper:
getManifest— describe the generator's capabilitiesgenerate— produce output given a DMMF + config
The CLI spawns them, sends getManifest to verify compatibility, then sends generate. The protocol is small enough to implement in any language; popular community generators include zod schema generators, ER diagram generators, and OpenAPI emitters.
Output emission
Generators don't template strings. They use @prisma/ts-builders for fluent TS code construction:
namespaceBuilder.add(
typeAlias('UserCreateInput').setType(
objectType()
.add(property('email', stringType()))
.add(property('name', stringType().optional()))
)
);The textual TypeScript output (formatting, JSDoc, modifier order) is determined by ts-builders' renderer. Changes to formatting affect every generated client.
Output validation
After generation, the CLI optionally verifies the output compiles. The functional test infrastructure in packages/client/tests/functional/ does this on every CI run for many schema shapes. Type-only changes are caught by the tsd-based type tests in packages/client/src/__tests__/types/.
Generator helper IPC
@prisma/generator-helper is the API surface third-party generators consume. The package exports:
- A small JSON-RPC client/server pair
- TypeScript types for
DMMF,GeneratorConfig,GeneratorOptions - A
generatorHandler({ onManifest, onGenerate })helper that wraps stdio
Internal generators (in this repo) bypass IPC and consume the DMMF directly, but the external interface is the same shape.
See also
client-generator-tsandclient-generator-js@prisma/internalsforgetDMMF,getGenerators, and the snapshot harness@prisma/clientfor what generated clients import at runtime- Glossary for DMMF and PSL definitions
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.