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.
- Boundary. Migration
000026addsworkspacesandworkspace_members, gives every user a backfilled personal workspace, and putsworkspace_idon all 14 owned content tables. Repository ownership filters compareworkspace_id;user_idstays 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. - 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. - Roles.
memberreads, creates and edits workspace resources;adminadditionally deletes any workspace resource and manages members below owner;owneradditionally renames/deletes the workspace. The cross-cutting row (DELETE needs admin+) is enforced centrally inmiddleware.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. - Teams retirement. Workspaces absorb teams. The user-facing
/teamsUI is archived to.archives/removal-safe/and redirects to/workspaces. The backend teams API, tables, and admin tab remain for legacy data access; theteams_limitplan setting now counts legacy teams plus owned shared workspaces, so the ceiling survives the rename. - Surface. The
/workspacesroute 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.accessmaps — 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