Multiple Apps, Turborepo
Use Alchemy to deploy multiple interconnected applications in a single repository.
In this guide, we’ll walk through how to:
- Set up a simple monorepo with two applications: a
backendand afrontend - Import and bind to the
backendapplication from thefrontendapplication - Deploy, destroy, and dev all applications in the monorepo.

-
Set up the
deployanddevtasks to run in dependency order (backend → frontend):turbo.json {"$schema": "https://turborepo.com/schema.json","ui": "tui","tasks": {"deploy": {"dependsOn": ["^deploy"],"cache": false},"dev": {"persistent": true,"cache": false},}} -
Set up the
destroytask to run in reverse dependency order (frontend → backend):turbo.json {"$schema": "https://turborepo.com/schema.json","ui": "tui","tasks": {..."backend#destroy": {"dependsOn": ["frontend#destroy"],"cache": false},"frontend#destroy": {"cache": false}}} -
Update the
backendapp to useimport.meta.dirnameto locate theentrypointso that it can be run from any directory (e.g. imported fromapps/frontend).apps/backend/alchemy.run.ts import alchemy from "alchemy";import { D1Database, Worker } from "alchemy/cloudflare";import path from "node:path";const app = await alchemy("backend");const db = await D1Database("db");export const backend = await Worker("worker", {entrypoint: path.join("src", "worker.ts"),entrypoint: path.join(import.meta.dirname, "src", "worker.ts"),bindings: {db,API_KEY: alchemy.secret.env.API_KEY,},});console.log({ url: backend.url });await app.finalize(); -
Install
alchemyand configuredev,deployanddestroyin thebackendapp.apps/backend/package.json {"name": "backend","private": true,"type": "module","scripts": {"build": "tsc -b","dev": "alchemy dev --app backend","deploy": "alchemy deploy --app backend","destroy": "alchemy destroy --app backend"},"dependencies": {"alchemy": "catalog:"}} -
Export
backend/alchemy.run.tsas./alchemy.apps/backend/package.json "exports": {".": {"bun": "./src/index.ts","import": "./lib/src/index.js",},"./alchemy": {"bun": "./alchemy.run.ts","import": "./lib/alchemy.run.js""types": "./alchemy.run.ts"}}, -
Add the
backendservice as aworkspace:*dependency in thefrontendapp.apps/frontend/package.json {"name": "frontend","private": true,"type": "module","dependencies": {"backend": "workspace:*","alchemy": "catalog:"}} -
Import
backend/alchemyand bind to the exportedbackendWorker:apps/frontend/alchemy.run.ts import alchemy from "alchemy";import { Vite } from "alchemy/cloudflare";import { backend } from "backend/alchemy";const app = await alchemy("frontend");export const frontend = await Vite("website", {bindings: {backend,},});console.log({url: frontend.url,});await app.finalize(); -
Use
--app frontendin your frontend’sdev,deployanddestroyscripts:apps/frontend/package.json {"name": "frontend","private": true,"type": "module","scripts": {"build": "tsc -b","dev": "alchemy dev --app frontend","deploy": "alchemy deploy --app frontend","destroy": "alchemy destroy --app frontend"},"dependencies": {"backend": "workspace:*","alchemy": "catalog:"}} -
Run
bun devfrom the root to start the development server for thefrontendapp.Terminal window bun devTerminal window npm run devTerminal window yarn devTerminal window pnpm devYou should see a turborepo TUI with a pane for each app.

-
When ready, run
bun deployfrom the root to deploy thefrontendapp.Terminal window bun run deployTerminal window npm run deployTerminal window yarn deployTerminal window pnpm run deploy
-
(Optional) Tear down both apps:
Terminal window bun run destroyTerminal window npm run destroyTerminal window yarn run destroyTerminal window pnpm run destroy