Skip to content

ADR 0012: Hosted multi-tenancy and client deployment tiers

Accepted. 2026-11-25. Architecture direction; implementation follows in later milestones.

ADR 0011 establishes Commitment Desk at app.commitmentdesk.com, with Inbox as the first module. The product is sold to assessing offices and firms, while self-hosting remains part of the open-source offer. The data model carries tenant_id on tenant-owned rows, and the plan expects one tenant in self-host and many in hosted deployments.

The current implementation still assumes a single hosted origin and a single tenant context per session. Users are unique per tenant (users_tenant_email_idx), but findByEmail is unscoped and returns one row, so the same email in multiple tenants is ambiguous. WEB_BASE_URL is a single value used for magic links and same-origin checks. There is no tenant provisioning, invitation, billing, quota, export/deletion, or cross-tenant test suite yet.

Two hosting models were considered: a centralized multi-tenant SaaS, or per-client Cloudflare accounts with deployments and domains owned by each client.

Default to a centralized, logically multi-tenant SaaS on the vendor’s Cloudflare account. Offer dedicated managed and self-hosted deployments only where justified.

  • One Worker, one D1 database initially, and one R2 bucket with tenant-prefixed keys. Shard the database only when size or operational metrics require it.
  • All clients use app.commitmentdesk.com; tenant identity comes from the authenticated session, not the hostname. Inbox is the first module at the application root.
  • Every tenant-owned query and write is scoped by tenant_id at the repository boundary. R2 keys include tenant_id. Audit events remain tenant-scoped.
  • Standard clients share maintenance, migrations, and observability. Backups and restores are database-level and therefore all-tenant.
  • Cross-tenant access must fail. Add a cross-tenant test suite before onboarding external clients.
  • Do not use Durable Objects for tenant data isolation or as the system of record. D1 remains the relational store. Durable Objects may later coordinate per-tenant rate limits, webhook retries, or jobs.
  • Separate Worker, D1 database, and R2 bucket per client, provisioned by infrastructure-as-code in the vendor’s Cloudflare account.
  • Hosted at client.commitmentdesk.com or a client-owned custom domain.
  • Provides per-client backup/restore, retention, deletion, quotas, and a stronger isolation story for procurement.
  • Scheduled upgrades and migrations, not independent version forks.
  • The client runs the open-source application in its own Cloudflare account, and later the M3 Node/Docker adapter, with its own domain, storage, and Cloudflare costs.
  • The vendor provides a supported deployment package, documentation, and optional paid support; it does not operate the client’s account by default.
  • Supported releases receive security fixes; there are no indefinite forks.

Per-client Cloudflare accounts are not the default. They turn the business into managed hosting, create version drift, complicate support and incident response, and undermine SaaS economics. They remain a procurement escape hatch.

  • Standard SaaS uses one application host, app.commitmentdesk.com, for all tenants. Do not launch with per-tenant subdomains.
  • When a client needs a distinct URL, start with client.commitmentdesk.com through wildcard DNS. Add custom hostnames (for example assessing.town.gov) through Cloudflare for SaaS only when demand justifies the plan and per-hostname costs.
  • Custom domains require per-tenant allowed origins, host-to-tenant resolution, magic-link redirects based on the request host, and host-only session cookies. WEB_BASE_URL and requireSameOrigin must become tenant- and request-aware. Custom domains are not a DNS-only change.
  • If a client owns its Cloudflare account, it should use its own domain and the self-host/BYO tier, not a subdomain of commitmentdesk.com. org1.commitmentdesk.com would remain in the vendor zone and confuse ownership.
  • Transactional email normally comes from commitmentdesk.com. Sending as a client domain requires that client’s SPF, DKIM, and DMARC.
  • Tenant identity comes from the authenticated session. A user belongs to one tenant in the current model.
  • Before external SaaS onboarding, resolve the unscoped findByEmail path. Choose either globally unique emails across the hosted deployment or an explicit tenant membership/selection model. Same-email users in multiple tenants must not be silently mapped to an arbitrary tenant.
  • Invitations, user management, role administration, and tenant provisioning are prerequisites for SaaS launch. The current admin pages manage reference data and API keys, not tenant lifecycle.
  • Include tenant_id in logs, metrics, and audit events; never log captured payloads or attachment contents.
  • Document DPA, retention, deletion, export, incident response, backups, and restore testing before accepting client data.
  • Evaluate data-residency requirements per contract. Clients with strict residency or isolation requirements use the dedicated or self-host tiers.
  • Use scoped Cloudflare API tokens per environment, least privilege, and CI secrets or OIDC. No global API keys or secrets in the repository.
  • Per-client Cloudflare accounts as the default hosted model: support and version-drift burden, unclear ownership, and poor SaaS economics.
  • Per-tenant subdomains at launch: wildcard TLS, host-to-tenant mapping, cookie/origin changes, and client-name leakage for little benefit.
  • Durable Objects as the multi-tenant data store or isolation boundary: the wrong tool for relational data, adding complexity without replacing D1 controls.
  • A separate D1 database for every standard tenant: operational overhead and migration complexity at the long tail; reserve dedicated databases for the dedicated tier.
  • Custom domains at launch: defer until demand and until the origin and authentication changes are implemented.
  • No runtime change in this ADR; the current single-tenant login and local deployment remain.
  • Follow-up work before hosted onboarding: tenant provisioning, invitations and user management, isolation tests, billing and quotas, export and deletion, backup and restore, security documentation, and tenant-aware origin handling if custom domains are added.
  • The standard tier remains the simplest path; dedicated and self-host are explicit products with separate support expectations.
  • ADR 0011’s single platform application host remains correct for the standard tier.
  • A cross-tenant test suite proves that tenant A cannot read, mutate, or infer tenant B records through API or web routes.
  • Standard login selects the tenant from the session; duplicate-email behavior is explicit and tested.
  • A dedicated deployment smoke test covers its own host, D1, R2, backups, and magic links.
  • Custom-domain work, when introduced, verifies TLS, host-to-tenant mapping, allowed origins, cookie scope, and magic-link redirects.
  • CI scans for committed secrets and uses scoped deployment credentials.