Open-Source Wikis

/

Prisma

/

Features

/

Client generation

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 --> Output

End-to-end flow

  1. CLI dispatch. prisma generate is parsed by packages/cli/src/CLI.ts and dispatched to Generate.ts.
  2. Schema load. Generate loads the schema via @prisma/internals (which delegates to @prisma/schema-files-loader for multi-file schemas).
  3. DMMF compute. getDMMF (in @prisma/internals) calls into @prisma/prisma-schema-wasm and returns a DMMF AST.
  4. Generator enumeration. getGenerators reads generator blocks from the schema, looks each one up in @prisma/client-generator-registry, and resolves them to a runner. Built-in: prisma-client (TS) and prisma-client-js (JS). External: anything that speaks the @prisma/generator-helper IPC.
  5. 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.
  6. Code emission. Each generator builds TypeScript via @prisma/ts-builders and writes files to the path declared in the generator block's output directive.

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 capabilities
  • generate — 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

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Client generation – Prisma wiki | Factory