Skip to content
Toolkit

ADR-0006: Workspace tenancy — boundary, roles, token pinning, teams retirement

  • Status: Accepted
  • Date: 2026-08-11
  • Deciders: Cardsite platform team (workstream 003, streams B1–B3)

Context

Every resource was owned and access-controlled by user_id alone, so collaboration was impossible without credential sharing. A teams feature existed (tables, API, UI) but its per-member access permission maps were never enforced anywhere — teams were chrome without a boundary. The sidebar carried a static "workspace switcher" with no backend. Workstream 003 resolved to build real multi-tenancy and decide what happens to teams.

Decision

Workspaces are the access boundary; users remain the billing anchor.

  1. Boundary. Migration 000026 adds workspaces and workspace_members, gives every user a backfilled personal workspace, and puts workspace_id on all 14 owned content tables. Repository ownership filters compare workspace_id; user_id stays on every row as owner-of-record. Plan limits, billing, AI quotas, inboxes, and audit logs deliberately stay per-user. Public paths (redirects, sitemaps) are not workspace-filtered.
  2. Resolution. Session requests select a workspace with X-Workspace-ID (membership-validated; non-member and unknown ids are indistinguishable; no header → personal workspace). Scoped API tokens are pinned to the workspace they were minted in — the header is ignored, and a token whose owner lost membership stops working.
  3. Roles. member reads, creates and edits workspace resources; admin additionally deletes any workspace resource and manages members below owner; owner additionally renames/deletes the workspace. The cross-cutting row (DELETE needs admin+) is enforced centrally in middleware.EnforceWorkspaceRoles; workspace/member management gates live in the workspace handler. The owner membership row is immutable and unremovable; ownership transfer is out of scope. Personal workspaces cannot be renamed, deleted, or given members.
  4. Teams retirement. Workspaces absorb teams. The user-facing /teams UI is archived to .archives/removal-safe/ and redirects to /workspaces. The backend teams API, tables, and admin tab remain for legacy data access; the teams_limit plan setting now counts legacy teams plus owned shared workspaces, so the ceiling survives the rename.
  5. Surface. The /workspaces route group is session-only (absent from the token scope table, deny-by-default). The web client persists the selection, sends the header from one interceptor, and clears the query cache on switch because resource query keys are not workspace-scoped.

Consequences

  • Collaboration works day one with zero behavior change for existing users: every pre-workspace request resolves to the personal workspace.
  • Billing never fragments: limits and payments stay on the user who owns the workspace, even for resources created by other members.
  • A leaked scoped token cannot cross workspaces (pinning), and a member's token cannot do more than the member (role checks read the membership, not the token).
  • Cache keys not being workspace-scoped forces a full query-cache clear on switch — cheap today; revisit key scoping if switching becomes frequent.
  • The delete gate lists resource prefixes explicitly (deleteGatedPrefixes); adding a new workspace-scoped surface means adding its prefix there — same lockstep discipline as the scope table.

Alternatives considered

  • Enforce teams_members.access maps — rejected: builds a second, weaker permission model that workspaces immediately supersede.
  • Workspace-id in the URL path (/w/{id}/links) — rejected: breaks every existing client and bookmark; the header keeps the API stable.
  • Per-workspace billing — rejected for now: plan settings and payment flows are deeply user-anchored; workspaces absorb collaboration, not monetization.
  • Free-form per-member permissions — rejected: three fixed roles cover the product need and stay testable as a matrix.

Source: docs/decisions/0006-workspace-tenancy.md

Library