Skip to Content
JobWzrd Docs

Deployment profiles — VPS and Cloudflare, from one source

Goal (owner, 2026-11-18): the same product deployable to a VPS and to Cloudflare, at the same time, without forking the application. This document defines what "both" means, what is shared, what is allowed to differ, and what is forbidden because it would quietly produce two different products.

1. What "at the same time" can and cannot mean

ReadingPossible?
Two deployments of the same build artifact family, each with its own databaseyes — this is the design
One deployment whose data lives in two databases at onceno — no sync layer is being built, and D1 cannot replicate Convex
One database, two frontendsonly if both frontends talk to the same backend; that is the current state (Convex), not the target
Automatic failover between Convex and D1no — different storage models, different write semantics; a manual cutover is the design

So: two products from one source, separate data, one API contract. A user on the VPS instance and a user on the Cloudflare instance are different users with different rows. Nothing in the design syncs them, and nothing should pretend to.

2. The two profiles

vps (today)cloudflare (target)
Frontend hostNode standalone container (app/Dockerfile), port 8080Cloudflare Pages, static export
Frontend renderNext server: proxy.ts rewrites + nonce CSP at request timestatic files + _headers + a Pages Function for /api/auth/*
Frontend configruntime env (FRONTEND_*, CSP_*)build-time NEXT_PUBLIC_* (inlined)
BackendConvex (hosted or self-hosted)Worker + D1 + R2 + Queues + Cron
DatabaseConvex's document store41 SQLite tables (DATA-MODEL-PROPOSAL.md)
ObjectsConvex file storageR2
AuthBetter Auth + Bearer JWT, cookies proxied same-originsame, via a Pages Function proxy
RealtimeConvex subscriptionsbounded polling (no subscriptions on D1)
Capsserver-owned mutationsguarded batch() statements
Deploy commanddocker build -f app/Dockerfile … && compose upwrangler pages deploy + wrangler deploy

Both profiles must satisfy the same contract, publish the same honesty rules, and render the same screens. Differences are host capabilities, never product behaviour.

3. The portability boundary: one contract, two implementations

server/openapi.yaml (58 paths) is the boundary. Rules:

  1. The frontend never branches on the target. No if (isCloudflare) in a component, a service or the store. The only target-aware code is configuration: apiBase(), backendOn(), and the host assets (proxy.ts vs _headers + Functions).
  2. Every backend implementation satisfies the same path set, request bodies and response envelopes — including the outcome field on send and the error envelope codes. A behaviour that exists only on one profile is a contract change and needs a spec delta.
  3. A conformance suite runs the same assertions against both backends. Until it exists, "parity" is an opinion. It is B12 in migration.md.
  4. Honesty rules are profile-independent: dry-run defaults, caps visible and real, a parked/unknown draft never reported as "not sent", no claim of an effect that did not happen.

4. Config, and the one asymmetry that is accepted

The VPS build reads its backend at runtime; the Pages build bakes it at build time. That asymmetry is unavoidable (static HTML cannot consult the environment) and it is accepted — with guards:

  • The VPS image refuses to ship against the shared development deployment (lib/deploymentGuard.ts, NEXT_PUBLIC_REQUIRE_DEPLOYMENT=1).
  • A Pages build with no backend env is allowed and honest (demo mode), but a Pages build with a wrong host must fail visibly, not fall back (migration.md F2.4/F15.3).
  • One place per profile decides the base URL; nothing else reads the env.

5. What would make the two profiles diverge (and is therefore forbidden)

TemptationWhy it is refused
A D1-only route (/api/v1/corpus/...) used by the frontendbreaks the 58-path contract and forces a frontend fork
Real-time-only UI on VPS (live subscriptions)the Cloudflare profile cannot serve it; polling must be the common path
Storing a token in KV only on Cloudflarethe VPS profile has no KV; tokens stay in the database/account table
A "Cloudflare mode" flag in the storeconfiguration, not product logic
Two schema sources of truthConvex schema stays as-is (frozen); D1 schema lives in backend/migrations and is reconciled by tools/check_table_inventory.py
Copying server/ into backend/different runtimes; the contract is shared, the code is not

6. Cutover between profiles (per deployment, not global)

A deployment moves from vps to cloudflare by: building with the new base URL (F2.3), deploying the Pages bundle, pointing the API seam at the Worker (B1), and re-authenticating users (owner decision O3). Rollback is the reverse and is irreversible once D1 has taken its first write of real data — the data does not travel back. A VPS deployment may simply stay where it is; nothing about the Cloudflare work forces a VPS instance to move.

7. CI matrix (what "both" costs)

Every change that touches the contract, the frontend shell or a service must pass:

JobRuns
app-vpsnpm run check && npm test && npm run build (standalone)
app-pagesPAGES_EXPORT=1 npm run check && npm test && npm run build + route/asset assertions
server-convexnpm run check && npm test (existing)
backend-d1npm run check && npm test + sqlite_master coverage test (later)
contractthe openapi parity test; later the cross-backend conformance suite

A change that is green on one profile and red on the other is not done.

8. Open decisions

#QuestionWhere it is answered
P1Does the VPS profile keep the Convex backend indefinitely, or migrate too?owner — no code depends on the answer; the vps profile composes either way
P2Self-hosted Convex on the VPS, or Convex Cloud?deployment choice, not code
P3Does the Pages app ever call Convex directly (no proxy)?no — cookies must stay first-party
P4Conformance suite: shell script or a real test runner?B12

On this page