Deployment
The app is one Bun server: the CRM, the API routes and the campaign runtime. Any host that runs a Docker image works (Fly.io, Railway, Render, a VM).
1. Database (Supabase)#
Create a Supabase project.
Copy the session pooler connection string (Project Settings → Database). The app keeps long-lived connections; the transaction pooler isn't needed.
Apply the schema:
shbun run db:plan -- --name initial # writes migrations/ (commit it)DATABASE_URL=<prod url> bun run db:migrateFor later changes, edit
crm.config.json, thenbun run crm:gen,bun run db:plan -- --name <change>, commit, and rundb:migrateagainst production. Prisma refuses destructive changes unless you pass explicit--deleteor--renamedecisions:--delete Deal.budgetto drop a field,--rename Deal.proposalAmount:Deal.contractAmountto keep its data under a new name.db:planstarts from thedbref (migrations/app/refs/db.json), whichbun run db:pushmoves forward. If you applied the last migration to your local database withdb:migrateinstead, the ref is still one migration behind, and the new plan branches off the old one;db:migratethen refuses it withMIGRATION.PATH_UNREACHABLE. Plan from the last migration and move the ref yourself:shbun run db:plan -- --name <change> --from <last migration's folder name>bun run db:migrate # your local databasebun --bun x prisma migration ref set db <the new marker hash db:migrate printed>Commit
refs/db.jsonwith the migration.
2. Signing in#
This is for auth: clerk(). Signing in covers the other choices.
Create a production instance, add your domain, and copy its keys. Under
Restrictions, limit sign-ups to your team (the CRM also enforces
access from crm.config.json).
3. Environment#
Set what your adapters need from .env.example. At minimum
DATABASE_URL, your auth provider's keys, APP_URL and APP_SECRET. The server logs which optional
features are on at startup, and refuses to start in production without the
required variables.
4. Run the image#
docker build -t my-crm .docker run -p 3000:3000 --env-file .env.production my-crm
Health check: GET /healthz.
Fly.io example:
fly launch --no-deployfly secrets import < .env.productionfly deploy
Any number of instances can run: what is due is kept in the database, and two of them never send the same email (see Campaigns).
Without Docker:
bun install --frozen-lockfilebun run buildbun run start
Vercel#
A Spool also deploys to Vercel with the TanStack Start preset (vercel.json). Vercel's
preset needs the app packaged by Nitro, so vite.config.ts calls vercel() from
@swirls/spools/vite. On Vercel, where VERCEL is set, it emits a Bun function in
.vercel/output. Every other build is the dist/ server above. Set the environment
variables on the Vercel project before the first deploy.
vercel() copies the CipherStash packages into the function whole, because they are
native. Name a native package of your own with vercel({ traceDeps: ['my-native*'] }).
A function is not a long-lived server, and the framework knows it is on Vercel without
SERVERLESS=1. The timers are off and cron jobs call the routes in the next section
instead:
Campaigns. The
vercel.jsonhere calls/api/cron/sequencesevery ten minutes. It needsCRON_SECRET, which Vercel Cron sends as a bearer token. Without it only emails with no wait are sent, and the Workflows page says so. See Campaigns.Mailbox sync and scheduled posts. Add
/api/cron/mail-syncand/api/cron/marketingtocronsinvercel.jsonif you use them. They are left out of the starter's, because a schedule your Vercel plan doesn't allow fails the deployment.Cold starts. Vercel puts an idle function away after a couple of minutes, and the next request then waits for it to start again (around three seconds for this app). A CRM with a handful of users is idle most of the time, so keep one instance ready with a cron job that calls
/api/cron/warmevery minute:json{ "crons": [{ "path": "/api/cron/warm", "schedule": "* * * * *" }] }A schedule this frequent needs a paid Vercel plan.
bun run build checks the browser files Vercel serves (.vercel/output/static) for server
code, as it checks dist/client everywhere else.
A host with no long-lived process#
On any other such host, set SERVERLESS=1. The server then keeps no timers, and cron jobs
call these instead, with CRON_SECRET as a bearer token:
| Route | What it does |
|---|---|
/api/cron/sequences |
Sends the sequence emails that are due. See Campaigns |
/api/cron/mail-sync |
Reads teammates' mailboxes. See Mailbox |
/api/cron/marketing |
Publishes the scheduled posts that are due. See Marketing |
/api/cron/warm |
Does one small database read, to keep an instance from going cold |
Files need a bucket or FlashDrive, because localBlobs() needs a disk that lasts.
Your own door#
An app with endpoints for people who are not teammates (Building your own door) needs, wherever it runs:
TRUST_PROXY, socallerAddresstells callers apart. On Vercel setTRUST_PROXY=1: its edge is the one proxy, and it setsX-Forwarded-For. Behind one reverse proxy (nginx, Caddy, a load balancer) that appends the caller's address toX-Forwarded-For, set it to1; behind a CDN and then a load balancer,2. Never set it higher than the proxies you have: a caller could then name any address they like. Without it, or with a value that isn't a whole number from 1 to 10,callerAddressanswersnull: the address can't be known, and your endpoint skips its limit by address or refuses.- An offline token key. With
clerk(), setCLERK_JWT_KEY(the instance's PEM public key, from the Clerk dashboard's API keys) soverifyTokenchecks tokens without asking Clerk. Without it the server fetches the instance's keys itself, at most once a minute for a key id it hasn't seen and once an hour otherwise, shared by every request, and refuses a token naming a key the instance doesn't have before asking anything. - Its front end's origins in a setting of yours, for
verifyToken'sauthorizedParties: with none, every token is refused outside development and tests. - Limits in front of its routes. Put a request-rate limit for them in the platform in front
(Vercel's firewall, Cloudflare, nginx
limit_req) as well as your ownhitLimit, so a flood is turned away before it reaches the server at all.
5. Swirls#
Deploy swirls/ and set its secrets (see Swirls), with
crm_app::CRM_APP_URL set to your APP_URL.
Checklist#
-
bun run db:migrate(orbun run db:harden) has run, so RLS is on and the Supabase API roles have no access - Supabase → Settings → API → Exposed schemas doesn't include
public -
TRUST_PROXYmatches the number of proxies in front of the app - With a door of your own: its front end's origins set, and
CLERK_JWT_KEYwithclerk() -
accessincrm.config.jsonlists your domain or emails - Sign-ups restricted at your auth provider
-
APP_SECRETandSWIRLS_APP_TOKENare 32+ random characters, unique per environment - On Vercel or another serverless host:
CRON_SECRETset and cron jobs for/api/cron/sequences,/api/cron/mail-syncand, if you schedule posts,/api/cron/marketing - Email domain verified and the delivery webhook (
/api/webhooks/email) configured - Supabase backups enabled