Architecture
Release, rollout, and migration contract
Status: Accepted for platform development
Applies to: Feelcouch Projects runtime, control plane, tenant applications, and tenant databases
This contract keeps one-person operation practical: build one artifact, validate it once, and promote it with controlled scope. Client-specific behavior is data and entitlement configuration, never a source-code fork.
Architectural invariants
Tenant deployment generation and operator validation are described in tenant topology.
| Concern | Required model |
|---|---|
| Source and runtime | One repository, one release line, one immutable OCI image digest |
| Platform data | One platform database for tenant registry, plans, rollout state, and operational metadata |
| Tenant data | One database and one least-privilege PostgreSQL role per tenant in the same cluster |
| Product access | Typed core, pro, or agency plan entitlements |
| Tenant behavior | Validated, versioned configuration stored in the platform database |
| Database evolution | Prisma Migrate as the current release line's schema writer with expand/contract compatibility; Liquibase only after an approved baseline cutover |
| Delivery scope | global, cohort, or single_tenant |
| Client customization | Theme, locale, modules, content, integrations, and entitlements; no code forks |
The runtime resolves the tenant from a trusted hostname and authenticated session, reads only the tenant registry from the platform database, and then connects with that tenant's dedicated database role. A request cannot select an arbitrary database name.
Typed plans and configuration
Plan names are stable API values rather than display strings:
export type Plan = "core" | "pro" | "agency";
export type Entitlement =
| "custom_domain"
| "email_fallback"
| "advanced_automation"
| "white_label"
| "multi_workspace";
export interface TenantReleaseConfig {
schemaVersion: number;
tenantId: string;
plan: Plan;
entitlements: readonly Entitlement[];
releaseChannel: "stable" | "canary";
}
The server derives effective entitlements from the purchased plan plus explicit, auditable overrides. The browser never grants features by hiding or showing controls. Every configuration write validates against an immutable schema version before activation.
Runtime release N must read configuration schema N and N-1. A configuration migration creates the new representation before the old representation is removed. Unknown plan or entitlement values fail closed and produce an operator alert.
Rollout targets
| Target | Purpose | Selection |
|---|---|---|
single_tenant |
Internal canary, incident fix, or explicit customer pilot | Immutable tenant ID |
cohort |
Controlled expansion by plan, region, release channel, or stable hash bucket | Saved, auditable cohort definition |
global |
All eligible tenants after canary evidence | Current active tenant registry |
A target changes activation metadata, not the image. All targets reference the same verified image digest. Target membership is snapshotted when a rollout starts so a changing query cannot silently widen the deployment.
Release sequence
- Run the fast gate: source-language policy, formatting/lint, types, focused unit and security tests, Prisma migration validation, and production build.
- Build the OCI image once. Attach dependency metadata, SBOM, provenance, version, and Git commit.
- Back up the platform database and every database in the rollout snapshot. Verify backup freshness before migration.
- Apply expand-only Prisma migrations to the current database. Tenant fan-out is introduced only with the real control plane and bounded concurrency.
- Start the new runtime slot and pass readiness, database compatibility, authentication, and critical API smoke checks.
- Activate one internal or designated
single_tenantcanary. Observe error rate, latency, database locks, queue age, and resource pressure. - Expand to a small cohort, then larger cohorts, then global. Stop automatically when a release threshold is exceeded.
- Keep the previous slot and image digest available through the rollback window.
- Run the separate full UI and interaction regression once the release-candidate UI is stable and before global activation.
- Apply contract changes only in a later release after all tenants run
N, noN-1runtime remains, and the rollback window has closed.
Migration ownership and Liquibase cutover
Decision, 2026-09-01 (FC-MIG-001): Prisma Migrate is the sole schema writer for the
current release line. Liquibase is not adopted. The operational cost of a second
migration mechanism is not justified for one operator and one release line, and the
two mechanisms never run in parallel. Reopening this decision requires an ADR, a
checksum-verified baseline of the existing schema, a rehearsal against a restored
database and its own release, exactly as the bullets below describe. Liquibase
remains a Phase 1 option, not a parallel migration path. After a cutover Prisma
Client may remain the ORM, but Prisma Migrate must stop writing production schemas.
The guard for this decision is tests/release/migration-ownership.test.ts, which
fails if a second migration mechanism or a destructive migration appears.
- Before cutover, keep only the Prisma migration history. After cutover, keep one Liquibase root changelog for each schema contract.
- Give every changeset a unique immutable ID, English description, rollback where safe, and a precondition for destructive or data-dependent work.
- Use Liquibase's lock table independently in each database. The deploy controller must treat a lock timeout as a stopped rollout, not as permission to bypass the lock.
- Apply tenant migrations with bounded concurrency to protect CPU, memory, I/O, and PostgreSQL connection limits on the single server.
- Record migration result, duration, checksum, release digest, and tenant ID in the platform rollout ledger.
- Never edit an applied changeset. Add a corrective changeset.
- Run data backfills as resumable, idempotent jobs with checkpoints; do not hold a deployment transaction open for a large backfill.
Expand/contract example
- Expand: add a nullable column or new table; deploy code that can read old and new representations.
- Migrate: backfill in small resumable batches and verify counts.
- Switch: write the new representation while preserving rollback compatibility.
- Observe: confirm all selected tenants and jobs use the new path.
- Contract: remove the old representation in a later minor or major release.
Compatibility and rollback
| Component | Required compatibility during rollout |
|---|---|
Runtime N |
Config N and N-1; expanded database from release N; current and previous API response shape where promised |
Runtime N-1 |
Expanded database from release N during the rollback window |
| Database | Additive changes before activation; destructive changes only after rollback expiry |
| Worker jobs | Idempotent across retries and safe when processed by N or N-1 during handover |
Application rollback switches traffic to the previous digest and pauses further tenant activation. Database rollback is not assumed. Expand changes stay in place, which is why N-1 compatibility is mandatory. A failed tenant migration quarantines that tenant from the rollout and leaves previously activated tenants unchanged.
Version and patch rules
- Patch: backward-compatible fixes, copy/catalog updates, performance improvements, and additive optional configuration. No destructive schema change, mandatory config rewrite, entitlement semantic change, or API break.
- Minor: backward-compatible features, new entitlements, additive schema evolution, and staged configuration upgrades.
- Major: intentionally incompatible API, configuration, entitlement, or data-model changes with an explicit migration program.
- A tenant-specific emergency fix still receives a normal version and immutable digest. Scope is controlled by
single_tenant; source is not branched for that client. - Release metadata records version, digest, Git commit, config schema range, database changelog version, target snapshot, operator, timestamps, and outcome.
Essential test lanes
The normal development loop stays short:
- Fast gate: language policy, lint, typecheck, focused unit/security tests, current migration validation against a disposable database, build, and critical API smoke tests.
- Release gate: image and supply-chain checks, fresh backup evidence, expand migration, canary smoke, and rollback rehearsal.
- Regression gate: full desktop/mobile UI, accessibility, localization, browser interaction, and performance regression after UI work is complete.
Performance or security failures block promotion. Non-critical visual review does not run on every source-only change.
Operator controls and audit
The private admin console must show image digest, application version, config schema, database migration version, rollout target and progress, per-tenant failures, active slot, previous slot, backup freshness, and rollback eligibility. It must support pause, resume, promote, and rollback with role checks and an immutable audit event.
The public status page receives only aggregated availability and incident information. Tenant identifiers, database names, rollout membership, logs, secrets, and infrastructure topology remain private.