|
1 | 1 | ## Prisma Repository – Agent Field Notes |
2 | 2 |
|
| 3 | +> **Meta note**: This is the primary agent knowledge base file. `CLAUDE.md` and `GEMINI.md` are symlinks to this file—always edit `AGENTS.md` directly. When learning something new about the codebase that would help with future tasks, update this file immediately. |
| 4 | +
|
3 | 5 | - **Repository scope**: Monorepo for Prisma ORM, CLI, client, tests, etc. Many packages use TypeScript, Rust and WebAssembly (via engines), TSX, and Jest; automation relies on `pnpm`. Expect large fixture directories and generated files. |
4 | | -- **Workspace layout**: Managed via pnpm workspaces and Turborepo (`turbo.json`). Node 20+/22+/24+ and pnpm ≥10.15 are required (see root `package.json`). Top-level scripts (`pnpm build`, `pnpm dev`, `pnpm test`) delegate into `scripts/ci/publish.ts`; package-specific commands run with `pnpm --filter @prisma/<pkg> <script>`. |
5 | | -- **Key packages**: `packages/cli` (Prisma CLI entry point), `packages/migrate` (migrate/db namespace + fixtures), `packages/client` (client runtime), `packages/client-generator-ts` (new `prisma-client` generator), `packages/client-generator-js` (traditional `prisma-client-js` generator), `packages/client-engine-runtime` (the core part of the new Rust binary free client based on Wasm query compiler, used by `ClientEngine` class in `packages/client`), `packages/config` (`PrismaConfigInternal` + loader), `packages/internals` (shared CLI + engine glue), `packages/engines` (Rust binaries download wrapper), `packages/integration-tests` (matrix suites), and numerous driver adapters under `packages/adapter-*`. |
| 6 | +- **Workspace layout**: Managed via pnpm workspaces and Turborepo (`turbo.json`). Node 20+/22+/24+ and pnpm ≥10.15 are required (see root `package.json`). Top-level scripts (`pnpm build`, `pnpm dev`, `pnpm test`) delegate into `scripts/ci/publish.ts`; package-specific commands run with `pnpm --filter @prisma/<pkg> <script>`. Turborepo caches builds; run `pnpm build` from root to build all packages in dependency order. |
| 7 | +- **Key packages**: `packages/cli` (Prisma CLI entry point), `packages/migrate` (migrate/db namespace + fixtures), `packages/client` (client runtime), `packages/client-generator-ts` (new `prisma-client` generator), `packages/client-generator-js` (traditional `prisma-client-js` generator), `packages/client-engine-runtime` (the core part of the new Rust binary free client based on Wasm query compiler, used by `ClientEngine` class in `packages/client`), `packages/config` (`PrismaConfigInternal` + loader), `packages/internals` (shared CLI + engine glue), `packages/engines` (Rust binaries download wrapper), `packages/integration-tests` (matrix suites), `packages/query-plan-executor` (standalone query plan executor service for Prisma Accelerate), and numerous driver adapters under `packages/adapter-*`. |
6 | 8 | - **Driver adapters & runtimes**: `packages/bundled-js-drivers` plus the `adapter-*` packages ship experimental JS driver adapters (Planetscale, Neon, libsql, D1, etc.) built on helpers in `driver-adapter-utils`; migrate/client fixtures exercise them, so adapter changes typically require fixture/test updates. |
7 | | -- **Build & tooling**: Typescript-first repo with WASM/Rust assets (downloaded by `@prisma/engines`). Multiple `tsconfig.*` drive bundle vs runtime builds. Lint via `pnpm lint`, format via `pnpm format`. Maintenance scripts live in `scripts/` (e.g. `bump-engines.ts`, `bench.ts`, `ci/publish.ts` orchestrates build/test/publish flows). |
| 9 | +- **Build & tooling**: Typescript-first repo with WASM/Rust assets (downloaded by `@prisma/engines`). Multiple `tsconfig.*` drive bundle vs runtime builds. Lint via `pnpm lint`, format via `pnpm format`. Maintenance scripts live in `scripts/` (e.g. `bump-engines.ts`, `bench.ts`, `ci/publish.ts` orchestrates build/test/publish flows). Build configuration uses esbuild via `helpers/compile/build.ts` with configs in `helpers/compile/configs.ts`. Most packages use `adapterConfig` which bundles to both CJS and ESM with type declarations. |
8 | 10 | - **Testing & databases**: `TESTING.md` covers Jest/Vitest usage. Most suites run as `pnpm --filter @prisma/<pkg> test <pattern>`. DB-backed tests expect `.db.env` and Docker services from `docker/docker-compose.yml` (`docker compose up -d`). Client functional tests sit in `packages/client/tests/functional`—run them via `pnpm --filter @prisma/client test:functional` (with typechecking) or `pnpm --filter @prisma/client test:functional:code` (code only); `helpers/functional-test/run-tests.ts` documents CLI flags to target providers, drivers, etc. Client e2e suites require a fresh `pnpm build` at repo root, then `pnpm --filter @prisma/client test:e2e --verbose --runInBand`. The legacy `pnpm --filter @prisma/client test` command primarily runs the older Jest unit tests plus `tsd` type checks. Migrate CLI suites live in `packages/migrate/src/__tests__`, the CLI runs both Jest (legacy suites) and Vitest (new subcommand coverage) via `pnpm --filter prisma test`, and end-to-end coverage lives in `packages/integration-tests`. |
9 | 11 | - **Docs & references**: `ARCHITECTURE.md` contains dependency graphs (requires GraphViz to regenerate), `docker/README.md` explains local DB setup, `examples/` provides sample apps, and `sandbox/` hosts debugging helpers like the DMMF explorer. |
10 | 12 |
|
| 13 | +- **Client architecture (Prisma 7)**: |
| 14 | + - `ClientEngine` in `packages/client/src/runtime/core/engines/client/` orchestrates query execution using WASM query compiler. |
| 15 | + - Two executor implementations: `LocalExecutor` (driver adapters, direct DB) and `RemoteExecutor` (Accelerate/Data Proxy). |
| 16 | + - `QueryInterpreter` in `packages/client-engine-runtime/src/interpreter/` executes query plans against `SqlQueryable` (driver adapter interface). |
| 17 | + - Query flow: `PrismaClient` → `ClientEngine.request()` → query compiler → `executor.execute()` → `QueryInterpreter.run()` → driver adapter. |
| 18 | + - `ExecutePlanParams` interface defines what's passed through the execution chain. |
| 19 | + |
| 20 | +- **Adding PrismaClient constructor options**: |
| 21 | + - Runtime types: `PrismaClientOptions` in `packages/client/src/runtime/getPrismaClient.ts`. |
| 22 | + - Validation: `packages/client/src/runtime/utils/validatePrismaClientOptions.ts` (add to `knownProperties` array and `validators` object). |
| 23 | + - Engine config: `EngineConfig` interface in `packages/client/src/runtime/core/engines/common/Engine.ts`. |
| 24 | + - Generated types: Update both `packages/client-generator-js/src/TSClient/PrismaClient.ts` (`buildClientOptions` method) and `packages/client-generator-ts/src/TSClient/file-generators/PrismaNamespaceFile.ts` (`buildClientOptions` function). |
| 25 | + - Use `@prisma/ts-builders` for generating TypeScript type declarations. |
| 26 | + |
| 27 | +- **Creating new packages**: |
| 28 | + - Create directory under `packages/`, add `package.json`, `tsconfig.json`, `tsconfig.build.json`, and `helpers/build.ts`. |
| 29 | + - Package is auto-discovered via `pnpm-workspace.yaml` glob `packages/*`. |
| 30 | + - For type-only packages, use `adapterConfig` from `helpers/compile/configs.ts`. |
| 31 | + - Add as dependency to consuming packages using `"workspace:*"` version. |
| 32 | + - **Important**: Add resolution path to `tsconfig.build.bundle.json` under `compilerOptions.paths` for go-to-definition to work in editors. |
| 33 | + - **Important**: If the package has tests, add it to `.github/workflows/test-template.yml`. Most utility packages go in the `others` job (Linux, no Docker) and `no-docker` job (Windows/macOS). Look at existing packages for patterns. |
| 34 | + |
11 | 35 | - **Prisma 7 direction**: Migration from `schema.prisma` datasource URLs / `env()` to `prisma.config.ts`. Commands, tests, and fixtures should read connection settings from `PrismaConfigInternal.datasource` (or driver adapters) rather than CLI flags or environment loading. SQLite datasource URLs now resolve relative to the config file and not to the schema. |
12 | 36 | - **Test helpers**: `ctx.setConfigFile('<name>')` (from `__helpers__/prismaConfig.ts`) overrides the config used for the next CLI invocation and is automatically reset after each test, so no explicit cleanup is needed. Many migrate fixtures now provide one config per schema variant (e.g. `invalid-url.config.ts` next to `prisma/invalid-url.prisma`) and tests swap them via `ctx.setConfigFile(...)`. `ctx.setDatasource`/`ctx.resetDatasource` continue to override connection URLs when needed. |
13 | 37 |
|
|
28 | 52 | - `@prisma/internals` exports CLI utilities: `arg`, `loadSchemaContext` (less used now). |
29 | 53 | - `packages/migrate/src/__tests__/__helpers__/context.ts` sets up Jest helpers including config contributors. |
30 | 54 | - `packages/config` defines `PrismaConfigInternal`; inspect when validating config assumptions. |
| 55 | + - `@prisma/ts-builders` provides a fluent API for generating TypeScript code (interfaces, types, properties with doc comments). |
| 56 | + - `@prisma/driver-adapter-utils` defines core interfaces: `SqlQuery`, `SqlQueryable`, `SqlDriverAdapter`, `SqlDriverAdapterFactory`. |
| 57 | + - `@prisma/client-engine-runtime` exports query interpreter, transaction manager, and related utilities. |
31 | 58 |
|
32 | 59 | - **Workflow reminders**: |
33 | 60 | - Respect existing structure: modifications often require updating both command implementation and tests/fixtures. |
34 | 61 | - Keep changes ASCII unless a file already uses Unicode (docs sometimes include emojis). |
35 | 62 | - For new fixtures, prefer minimal config mirroring existing ones to ensure cross-platform compatibility. |
| 63 | + - When adding features that span multiple packages, build from root (`pnpm build`) to ensure correct dependency order. |
| 64 | + - Type-only imports from workspace packages work at runtime but IDE may show errors until `pnpm install` refreshes the workspace graph. |
| 65 | + - Test files named `*.test.ts` are excluded from build output via esbuild config; place tests alongside source files. |
| 66 | + - **Update this file** (`AGENTS.md`) whenever you learn something new about the codebase that would be valuable for future tasks. |
0 commit comments