Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/design/03-domain-model/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ distinct type, with composition behaviours a Service doesn't have.

### App root

The **root** is a position: the outermost module, the one the entry default-exports and nothing provisions. The **root module** and the **root node** are other names for that position. A node built with `module()` can hold it: an entry that default-exports one is still accepted as the root.
The **root** is a position: the outermost module, the one the entry default-exports, or the `composer` section of `prisma.config.ts` holds as `app`, and nothing provisions. The **root module** and the **root node** are other names for that position. A node built with `module()` can hold it: an entry that default-exports one is still accepted as the root. The section's `app` accepts only an app root.

The **app root** is a type: `AppRootNode`, built with `appRoot()`. It is the only node this repository's guidance puts in the root position. It takes what `module()` takes minus `deps` and `expose`, because nothing provisions it, so nothing can wire into it or consume from it. Its body receives `input`, `environment` and `provision`. Its `provision()` is the only one that accepts a [value resource](#value-resource): in a `module()` body, provisioning one fails to compile with an error that names `appRoot()`. `provision()` refuses an app root, at compile time and at Load, so it is never nested. In code: `appRoot()`, `AppRootNode`, `AppRootContext`, and `isRoot()` on every module node, which answers `true` only for an app root, even when a `module()` node holds the root position.

Expand Down
11 changes: 7 additions & 4 deletions docs/design/10-domains/deploy-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ covers those three
export of the entry module, to an environment (default: `production`). The entry is
`entry` in the `composer` section of `prisma.config.ts`, resolved against
that file's directory; `--entry <path>` overrides it, resolved against the
working directory. With neither, the command fails with `CONFIG.ENTRY_MISSING`.
working directory. The section can instead hold the root itself as `app`,
read from a native import of `prisma.config.ts`; `app` and `entry` are
exclusive and `--entry` overrides either. With none of them, the command
fails with `CONFIG.ENTRY_MISSING`.
The entry is an input to the tool, not an application fact ([ADR-0003](../90-decisions/ADR-0003-deploy-derives-everything-from-the-root-node.md)).
- **`prisma deploy list`** — list every node the app has deployed in an
environment (default: `production`), one row per node of the application topology the
Expand Down Expand Up @@ -106,7 +109,7 @@ bun APIs can only deploy under bun, since loading the graph imports that module
the extension registries and the deploy's one state store (ADR-0017).
Extension factories validate their own environment during config
evaluation, erroring with the exact variable name — before any slow work.
2. **Import the entry module.** Its default export must be the app's root: an app root built with `appRoot()`, or a module built with `module()`. The graph reachable from it is what deploys. A service is not independently deployable: the CLI refuses it with `COMPOSE.ROOT_NOT_MODULE`, naming the fix (wrap it: `appRoot('name', ({ provision }) => { provision(...); })`). Anything else is `COMPOSE.ENTRY_EXPORT_INVALID`. Every command that loads the entry, including the ones that only read the app's name from it, runs this check.
2. **Import the entry module, or the config that holds the app.** Its default export must be the app's root: an app root built with `appRoot()`, or a module built with `module()`. The graph reachable from it is what deploys. A service is not independently deployable: the CLI refuses it with `COMPOSE.ROOT_NOT_MODULE`, naming the fix (wrap it: `appRoot('name', ({ provision }) => { provision(...); })`). Anything else is `COMPOSE.ENTRY_EXPORT_INVALID`. Every command that loads the entry, including the ones that only read the app's name from it, runs this check. When the section holds the root as `app` and no `--entry` is given, the command imports `prisma.config.ts` natively instead and takes `composer.app` from that import: a failed import is `COMPOSE.CONFIG_UNLOADABLE`, an import with no `composer` export or whose `app` is not an app root is `COMPOSE.CONFIG_EXPORT_INVALID`, and a root whose name differs from the `app` in the section the command was handed is `CONFIG.APP_MISMATCH` ([ADR-0049](../90-decisions/ADR-0049-composers-configuration-is-the-composer-section-of-prisma-config.md)).
3. **Resolve the name.** The root node's name (every node is named — ADR-0006),
unless `--name` overrides it — CI's per-run ephemeral deploys use this so a
name never collides with a standing demo. The resolved name is the root's
Expand Down Expand Up @@ -291,8 +294,8 @@ them:
- **Topology emission** — the serialized-topology artifact for agents/tooling;
when it lands it must strip the machine-specific `build.module` (ADR-0004).
- **Freshness checks** — detecting stale (not just missing) built output.
- **Entry discovery** — the entry comes from the config's `entry` or `--entry`;
with neither, the command fails with `CONFIG.ENTRY_MISSING`. Nothing searches
- **Entry discovery** — the root comes from the config's `app` or `entry`, or `--entry`;
with none of them, the command fails with `CONFIG.ENTRY_MISSING`. Nothing searches
the directory for an entry module.

## CLI behavior notes
Expand Down
11 changes: 7 additions & 4 deletions docs/design/10-domains/local-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Dev re-runs [deploy's pipeline](deploy-cli.md#the-pipeline) with these deltas:
A recorded database the last session stopped is started here: on a warm
start the converge may change nothing and never call the Database
provider.
5. **Lower + converge** — in a new worker thread of the `prisma` process, one per converge ([ADR-0067](../90-decisions/ADR-0067-prisma-dev-converges-in-a-worker-thread.md)). The worker imports the `composer` section of `prisma.config.ts`, the app entry and the app's converge entry, calls `lower()` with the extension's `localTarget.providers()` layer and `devState()` (Alchemy's built-in file store, exported by `@prisma/composer/local-target`), and plans and applies with the environment name as Alchemy's stage. Providers provision emulator instances (a running service, a database, a bucket) by talking to the emulators; the converge ends, the worker ends, and the Compute emulator keeps serving. The worker runs no adapter. The main thread passes it, in memory, what Load read from the app configuration, the plain platform variable texts (`plainVariableText`), the named secrets (the app secrets under the names of the graph's platform secrets), each resolved container, the preflight payloads and the first Load's node addresses. It passes the local providers `plainVariableText` and `namedSecrets`. No stack file and no app configuration file is written. For the worker's lifetime the main thread holds the one-converge flag and the process's working directory, and it reports the worker's events and its redacted output.
5. **Lower + converge** — in a new worker thread of the `prisma` process, one per converge ([ADR-0067](../90-decisions/ADR-0067-prisma-dev-converges-in-a-worker-thread.md)). The worker imports the `composer` section of `prisma.config.ts`, the app entry (or takes the root from the section's `app`) and the app's converge entry, and does not converge, returning `config-changed`, when the section's extension ids, state extension, `entry` or adapter sources differ from the first converge's. It also returns `config-changed` when a service's build declaration differs from the one the main thread took at start, because the main thread assembles and serves from that one. On `config-changed`, and on any edit to `prisma.config.ts` itself, the `prisma dev` command stops the session and runs itself again in a new process, since the main thread cannot load the config or the app again ([ADR-0049](../90-decisions/ADR-0049-composers-configuration-is-the-composer-section-of-prisma-config.md)). It then calls `lower()` with the extension's `localTarget.providers()` layer and `devState()` (Alchemy's built-in file store, exported by `@prisma/composer/local-target`), and plans and applies with the environment name as Alchemy's stage. Providers provision emulator instances (a running service, a database, a bucket) by talking to the emulators; the converge ends, the worker ends, and the Compute emulator keeps serving. The worker runs no adapter. The main thread passes it, in memory, what Load read from the app configuration, the plain platform variable texts (`plainVariableText`), the named secrets (the app secrets under the names of the graph's platform secrets), each resolved container, the preflight payloads and the first Load's node addresses. It passes the local providers `plainVariableText` and `namedSecrets`. No stack file and no app configuration file is written. For the worker's lifetime the main thread holds the one-converge flag and the process's working directory, and it reports the worker's events and its redacted output.
6. **Attach** — new, dev-only: through `localTarget.attach`, render the front
door (every service's endpoint) and watch for rebuilds, loop. Ctrl-C,
SIGTERM or a failure stops the app's service processes and database
Expand Down Expand Up @@ -540,7 +540,7 @@ The preflight returns two things. Its payload reaches the converge's worker thre

The worker thread of a `prisma dev` converge runs no adapter. The main thread passes it, in memory, what Load read from the app configuration, `plainVariableText`, the first Load's node addresses, and the reads of platform variables in the graph it started with. It passes the texts the dev preflight found at start, on the first converge and on every rebuild, after checking each against the known secrets. It also passes the named secrets: the app secrets under the secrets keys of the graph's platform secrets. No file and no environment variable carries any of these. The local target fills a plain `$platform` marker from `plainVariableText`, and a secret marker from the named secrets. The local service reads the same text at its own boot and decodes it by the marker's schema, through the same code as on the platform.

A rebuild runs no dev preflight, so a read of a platform variable that a code change adds would have no value. `prisma dev` therefore sends each converge's worker thread the reads of the graph it started with (`valueReads`: reader, node and path) and each read node's address and `props`. The worker, which has just loaded the app as it is on disk, compares them with its own graph's before it converges. If either differs, it does not converge; `prisma dev` emits the `value-reads-changed` event with the nodes whose reads were added, removed or changed, and pauses rebuilds until it is restarted. If the first converge sees a difference, which usually means an app file changed while `prisma dev` was starting, and otherwise that a module body builds a different graph each time it runs, `prisma dev` stops and names the reads that changed. For a rebuild the CLI prints a warning: `The platform variables the app reads changed since dev started: reads of "shop.smtpPort" were added, reads of "shop.emailFrom" were removed, and "shop.sender" was changed. Restart dev to apply them; rebuilds are paused until then.` An edit that adds or removes a node fails the rebuild with a message that says to restart `prisma dev`.
A rebuild runs no dev preflight, so a read of a platform variable that a code change adds would have no value. `prisma dev` therefore sends each converge's worker thread the reads of the graph it started with (`valueReads`: reader, node and path) and each read node's address and `props`. The worker, which has just loaded the app as it is on disk, compares them with its own graph's before it converges. If either differs, it does not converge; `prisma dev` emits the `value-reads-changed` event with the nodes whose reads were added, removed or changed, and the `dev` operation pauses rebuilds; the `prisma dev` command restarts itself in a new process. If the first converge sees a difference, which usually means an app file changed while `prisma dev` was starting, and otherwise that a module body builds a different graph each time it runs, `prisma dev` stops with `DEV.CHANGED_WHILE_STARTING`, names the reads that changed, and the command starts again. For a rebuild the CLI prints a warning, then restarts: `The platform variables the app reads changed since dev started: reads of "shop.smtpPort" were added, reads of "shop.emailFrom" were removed, and "shop.sender" was changed. Restarting dev.` An edit that adds or removes a node makes the worker return `config-changed` before it converges, and the `prisma dev` command restarts itself.

The local `Deployment` provider gives each service only the variables its own input reads: the `$platform` markers in its input document, at any depth. For a service that runs its artifact, it reads the input document for this from the unpacked artifact's `compute.bootstrap.json`, with the reader `@internal/lowering` exports next to the packer. It ignores a `COMPOSER_<ADDRESS>_INPUT` entry in `env.json` for such a service, whether or not the artifact holds a document, and does not put that key into the process's environment, because the artifact's bootstrap passes the document to `run()`. For a service that runs a dev server, which has no artifact, the compute descriptor's `reserve` writes the input document as a `COMPOSER_<ADDRESS>_INPUT` variable, which the local target keeps in `env.json` with the service's other rows. This isolation is a requirement of the local target only. On Prisma Cloud every deployment receives every variable of its class.

Expand Down Expand Up @@ -569,7 +569,10 @@ Deploy's rule holds: every failure names its fix.
| a `@prisma/dev` server fails to start | the underlying error, sanitized — connection-URL credentials are masked before embedding |
| port conflict on a persisted allocation | which service, which port, and how to free or re-allocate (`--fresh`) |
| required secret unset or empty | hard error listing every missing variable, the service that needs it, the schema's message, and where an adapter in `secrets` reads it; an optional one is not an error |
| an adapter returns different values at a rebuild than at start | that the values changed and rebuilds are paused until dev restarts |
| an adapter returns different values at a rebuild than at start | that the values changed; `prisma dev` restarts itself (the `dev` operation pauses) |
| `prisma.config.ts` changed, a file only it imports changed (with an `entry`), a file it imports changed the section's extensions, state store, `entry` or adapters, a node was added or removed, or a service's build changed | `config-changed`, naming the file and what changed; `prisma dev` restarts itself (the `dev` operation pauses) |
| a restarted `prisma dev` fails to start | that it could not restart; it tries again when a file in the app's directory next changes |
| the first converge finds the app changed since dev loaded it | `DEV.CHANGED_WHILE_STARTING`; `prisma dev` starts again, and after three such starts waits for a file to change |
| a service exits before it listens, or does not listen within the readiness timeout | the address, the port, the exit code if it exited, and the log path; `dev` stops the app's services before it returns the failure |
| an emulator does not accept connections (retried briefly; an error response from the emulator is never retried) | `DEV.EMULATOR_UNREACHABLE`, with the emulator's URL, from `dev` and `log` alike |
| `PRISMA_COMPOSER_SERVICE_READY_TIMEOUT_MS` is not a positive whole number | `DEV.SERVICE_READY_TIMEOUT_INVALID`, with the value |
Expand Down Expand Up @@ -622,7 +625,7 @@ The design's founding claim was proven against open-chat — a real, pre-existin
no `watch` entries reports `[dev] <address> has no watchable inputs` at
startup and needs its rebuilds triggered manually.
- **A topology edit reconverges, but the session's own view of the app is
the one it started with.** The main thread imports the entry module once, so after an edit to `module.ts` or a `service.ts` the converge's worker thread (which imports the app again) converges the new wiring while the session keeps the graph, the bundles and the dev servers it loaded. Edits that keep the set of nodes and the platform variables the app reads — wiring, inputs, bindings — apply fully; adding or removing a node, or passing on a root input field the first Load did not read, fails the rebuild and needs `prisma dev` restarted, and a changed read of a platform variable pauses rebuilds until then.
the one it started with.** The main thread imports the entry module once, so after an edit to `module.ts` or a `service.ts` the converge's worker thread (which imports the app again) converges the new wiring while the session keeps the graph, the bundles and the dev servers it loaded. Edits that keep the set of nodes and the platform variables the app reads — wiring, inputs, bindings — apply fully; passing on a root input field the first Load did not read fails the rebuild and needs `prisma dev` restarted, and adding or removing a node, a changed read of a platform variable, or a changed build declaration restarts `prisma dev` in a new process.
- **An ORM database migrates to its `targetRef` on every converge.** `prisma dev` runs as the environment `dev`, so an app that computes `targetRef` from the environment name, `resolve([environment.name], ([name]) => (name === 'dev' ? '@contract' : name))`, migrates its local database to the contract it just emitted; an app that names a ref under `dev` needs that ref committed. A migration the ORM refuses fails the rebuild with the ORM's error under one Composer line, and the running app is left as it was. A ref whose policies differ from the local database's is refused the same way as in a deploy; whoever administers the database (locally, the developer) applies them with `prisma db migrate --to <ref> --permit-policy-change --db <url>`, taking the URL from `prisma dev url <address>` while `prisma dev` runs.
- **App-owned migrations are not run by `dev`** (by design — ADR-0022, spec
§ 4's `OrmMigration` line is for framework-run migrations only). An app that
Expand Down
Loading
Loading