|
| 1 | +--- |
| 2 | +title: Monorepos |
| 3 | +description: Deploy several apps from one repository with a root-level Prisma Compute config. |
| 4 | +url: /compute/monorepos |
| 5 | +metaTitle: Deploy a monorepo | Prisma Compute |
| 6 | +metaDescription: Configure, build, and deploy multiple apps from a monorepo with prisma.compute.ts and Prisma Compute. |
| 7 | +--- |
| 8 | + |
| 9 | +Prisma Compute can deploy several apps from one repository. Put one `prisma.compute.ts` at the repository root, declare each deployable app under `apps`, and use the app's key as its CLI target. |
| 10 | + |
| 11 | +Each target becomes a separate Compute app with its own deployments and URL. The targets share one Prisma project and deploy to the same branch, so a preview branch can contain your whole application. |
| 12 | + |
| 13 | +Before you start, install the monorepo's dependencies and complete the sign-in and project-linking steps in [Get started](/compute/getting-started). Run commands from the repository root unless a step says otherwise. |
| 14 | + |
| 15 | +## Example repository |
| 16 | + |
| 17 | +This guide uses a Next.js frontend and a Hono API: |
| 18 | + |
| 19 | +```text title="Repository structure" |
| 20 | +acme-shop/ |
| 21 | +├── apps/ |
| 22 | +│ ├── api/ |
| 23 | +│ │ ├── src/index.ts |
| 24 | +│ │ └── package.json |
| 25 | +│ └── web/ |
| 26 | +│ ├── app/ |
| 27 | +│ ├── next.config.ts |
| 28 | +│ └── package.json |
| 29 | +├── package.json |
| 30 | +├── pnpm-workspace.yaml |
| 31 | +└── prisma.compute.ts |
| 32 | +``` |
| 33 | + |
| 34 | +Your apps can use different supported frameworks and can depend on shared workspace packages. Each app must still have a working build from its configured root. |
| 35 | + |
| 36 | +## 1. Add the Compute config |
| 37 | + |
| 38 | +Create `prisma.compute.ts` at the monorepo root: |
| 39 | + |
| 40 | +```ts title="prisma.compute.ts" |
| 41 | +import { defineComputeConfig } from "@prisma/compute-sdk/config"; |
| 42 | + |
| 43 | +export default defineComputeConfig({ |
| 44 | + apps: { |
| 45 | + web: { |
| 46 | + root: "apps/web", |
| 47 | + framework: "nextjs", |
| 48 | + }, |
| 49 | + api: { |
| 50 | + root: "apps/api", |
| 51 | + framework: "hono", |
| 52 | + entry: "src/index.ts", |
| 53 | + httpPort: 3000, |
| 54 | + }, |
| 55 | + }, |
| 56 | +}); |
| 57 | +``` |
| 58 | + |
| 59 | +Here, `web` and `api` are **target keys**. They identify the apps in CLI commands and become the deployed app names unless you set `name` explicitly. |
| 60 | + |
| 61 | +Paths have two different bases: |
| 62 | + |
| 63 | +- `root` is relative to `prisma.compute.ts`. |
| 64 | +- `entry` and build output paths are relative to that app's `root`. |
| 65 | + |
| 66 | +`httpPort` must match the port the deployed server listens on. A server you start yourself must also listen on `0.0.0.0`, not only `localhost`. |
| 67 | + |
| 68 | +The Next.js app in this example also enables standalone output: |
| 69 | + |
| 70 | +```ts title="apps/web/next.config.ts" |
| 71 | +export default { output: "standalone" }; |
| 72 | +``` |
| 73 | + |
| 74 | +The CLI can load this config without a local SDK installation. Install `@prisma/compute-sdk` as a root development dependency if you want editor autocomplete and type checking. See the [configuration reference](/compute/configuration) for every field, environment inputs, custom build settings, and the JSON config format. |
| 75 | + |
| 76 | +## 2. Verify every app locally |
| 77 | + |
| 78 | +Build each target from the repository root before deploying: |
| 79 | + |
| 80 | +```npm title="Terminal" |
| 81 | +npx @prisma/cli@latest app build web |
| 82 | +npx @prisma/cli@latest app build api |
| 83 | +``` |
| 84 | + |
| 85 | +`app build` always builds one target. If you omit the target at the monorepo root, the CLI returns `COMPUTE_CONFIG_TARGET_REQUIRED` and lists the available targets. |
| 86 | + |
| 87 | +From inside a configured `root`, the CLI infers the target, so this builds `api` too: |
| 88 | + |
| 89 | +```npm title="Terminal" |
| 90 | +cd apps/api |
| 91 | +npx @prisma/cli@latest app build |
| 92 | +``` |
| 93 | + |
| 94 | +If roots overlap, the deepest matching root wins. Prefer non-overlapping roots unless that behavior is intentional. |
| 95 | + |
| 96 | +## 3. Deploy one app |
| 97 | + |
| 98 | +Pass the target key as the positional argument: |
| 99 | + |
| 100 | +```npm title="Terminal" |
| 101 | +npx @prisma/cli@latest app deploy web |
| 102 | +``` |
| 103 | + |
| 104 | +To deploy the API instead: |
| 105 | + |
| 106 | +```npm title="Terminal" |
| 107 | +npx @prisma/cli@latest app deploy api |
| 108 | +``` |
| 109 | + |
| 110 | +You can also run the command from inside an app's `root` and omit the target: |
| 111 | + |
| 112 | +```npm title="Terminal" |
| 113 | +cd apps/web |
| 114 | +npx @prisma/cli@latest app deploy |
| 115 | +``` |
| 116 | + |
| 117 | +:::warning |
| 118 | + |
| 119 | +The positional `web` in `app deploy web` selects `apps.web` from the config. `--app web` has a different purpose: it overrides the deployed app name. It does not select a config target. |
| 120 | + |
| 121 | +::: |
| 122 | + |
| 123 | +## 4. Deploy the whole monorepo |
| 124 | + |
| 125 | +When your current directory is not inside a configured app root, a bare deploy covers the whole config. With the example structure, run this from the monorepo root: |
| 126 | + |
| 127 | +```npm title="Terminal" |
| 128 | +npx @prisma/cli@latest app deploy |
| 129 | +``` |
| 130 | + |
| 131 | +The CLI deploys every target in config order. Project-, branch-, database-, and production-level options apply to the whole run. For example, this deploys every app to the same preview branch: |
| 132 | + |
| 133 | +```npm title="Terminal" |
| 134 | +npx @prisma/cli@latest app deploy --branch feature/search |
| 135 | +``` |
| 136 | + |
| 137 | +A deploy-all run rejects per-app overrides such as `--app`, `--framework`, `--entry`, `--http-port`, `--region`, `--env`, and `PRISMA_APP_ID`. Put stable per-app values in `prisma.compute.ts`, or select one target before using an override: |
| 138 | + |
| 139 | +```npm title="Terminal" |
| 140 | +npx @prisma/cli@latest app deploy api --env apps/api/.env.preview |
| 141 | +``` |
| 142 | + |
| 143 | +Targets deploy in order and the run stops at the first failure. The error tells you which targets are already live, which target failed, and which targets were not attempted. Fix the failure and rerun the command to converge the repository. |
| 144 | + |
| 145 | +## Command summary |
| 146 | + |
| 147 | +| Goal | Run from the monorepo root | |
| 148 | +| --- | --- | |
| 149 | +| Build one app | `npx @prisma/cli@latest app build web` | |
| 150 | +| Deploy one app | `npx @prisma/cli@latest app deploy web` | |
| 151 | +| Deploy every app | `npx @prisma/cli@latest app deploy` | |
| 152 | +| Deploy every app to a preview branch | `npx @prisma/cli@latest app deploy --branch feature/search` | |
| 153 | + |
| 154 | +## Deploy on push with GitHub |
| 155 | + |
| 156 | +The [GitHub integration](/compute/github) reads the same root config. On each push, Prisma discovers the targets and starts one build per app. Each build uses its target's `root`, framework, entrypoint, port, region, and build settings. |
| 157 | + |
| 158 | +Connect the linked project once: |
| 159 | + |
| 160 | +```npm title="Terminal" |
| 161 | +npx @prisma/cli@latest git connect |
| 162 | +``` |
| 163 | + |
| 164 | +For a custom CI pipeline, set `PRISMA_SERVICE_TOKEN` and `PRISMA_PROJECT_ID`, then name the config target positionally: |
| 165 | + |
| 166 | +```bash title="CI" |
| 167 | +PRISMA_SERVICE_TOKEN=... PRISMA_PROJECT_ID=... \ |
| 168 | + npx @prisma/cli@latest app deploy web \ |
| 169 | + --branch "${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}" \ |
| 170 | + --json \ |
| 171 | + --no-interactive |
| 172 | +``` |
| 173 | + |
| 174 | +Run one command per target when your pipeline needs independent jobs. Use a bare `app deploy` when one job should deploy the entire monorepo. |
| 175 | + |
| 176 | +## What to read next |
| 177 | + |
| 178 | +- [Configuration](/compute/configuration): all config fields and precedence rules. |
| 179 | +- [GitHub integration](/compute/github): deploy-on-push and preview branches. |
| 180 | +- [Environment variables](/compute/environment-variables): production, preview, and branch-specific values. |
| 181 | +- [Deployments](/compute/deployments): inspect, promote, and roll back deployments. |
0 commit comments