Accounts
What this is for
An account is the tenant boundary — nearly every scoped row in the database hangs off one account_id. Accounts form hierarchies (a parent account plus descendants), and a person may access several accounts and switch between them. Record scope: "account" in a type's design_schema means "rows belong to the active account"; scope: "platform" means the spine-system account.
Why it exists
You need isolation between customers while still allowing cross-account support and system administration.
Why it exists (5-whys):
- Multi-tenancy needs a unit of isolation — every record, role, and policy must answer "whose data is this?"
parent_idmakes tenancy hierarchical — orgs contain sub-orgs, agencies manage client accounts; support sees down the tree without seeing sideways.account_paths(closure table, ancestor/descendant/depth) exists because hierarchy lookups run inside RLS policies on every governed read — they must be a fast join, not a recursive CTE per row.get_accessible_accountsresolves the accessible set in one service-role RPC.- Accounts are typed (
type_id+ stampeddesign_schema) because accounts are domain-shaped too — a "client org" and a "sandbox" can carry different fields, same types-as-data pattern as items. - Root: tenancy is the foundation's non-negotiable —
accountsdefines the boundary,account_pathsmakes it traversable at policy speed, and every other primitive'saccount_idborrows this isolation. (confirmed 2026-11-13)
Fields and settings
| Column | Notes |
|---|---|
slug | UNIQUE — stable identifier (spine-system is the platform account). |
display_name | Human name shown in the account switcher. |
parent_id | FK → accounts — places this account in the hierarchy. |
type_id | Accounts are typed records; the type's design_schema governs data. |
data | jsonb — type-defined fields. |
logs_retention_days, observability_retention_days | Per-account retention knobs. |
Hierarchy mechanics
account_pathsis the closure table (ancestor_id,descendant_id,depth) — ancestors/descendants resolve viaget_account_ancestors/get_accessible_accountsRPCs, not recursive queries you write.GET /api/account-nodes?node_id=<id>returns a node with itstype:types(...)join, ancestors, and children — the admin tree view's data source.
The active account
- The client sends
X-Account-Idon everyapiFetch(set by AuthContext viasetAccountId). Server-sidectx.accountIdscopes reads/writes andcurrent_actor_id()-based RLS. user.accessible_accountslists the accounts a person may switch between; switching is a client-sidesetAccountIdchange, not a re-login.
App-driven placement
- A manifest
registrationblock decides where new accounts/people land:account_strategy: 'new' | 'existing',parent_account,target_account,default_workspace_name. The installer syncs it toapps.config.registration+spine.config.json(see App manifest reference).
Minimal configuration
slug, display_name, type_id, plus parent_id when it isn't a root account.
Full configuration
Adds data fields from the account type's design_schema, retention settings, and hierarchy position via parent_id/account_paths.
Example
A white-label app registers with account_strategy: 'new' + parent_account: 'spine-system': each new customer signup provisions a child account under the platform account; support staff in the parent see all children through the account switcher while customers stay scoped.
Core files
.framework/migrations/001_core_schema.sql—accounts+account_pathsclosure table.framework/functions/account-nodes.ts— node + ancestors + children API.framework/src/lib/api.ts—X-Account-Idon every request.framework/src/lib/registration.ts— signup → placement.framework/cli/commands/install-app.ts—registration→ config sync
Agent notes
- Scope confusion is the #1 tenancy bug: a record created under the wrong
account_idis invisible to the right users — always confirm which account is active before writing. spine-systemis the platform account;scope: "platform"types and system roles live there. Do not put tenant data in it.- Never hand-maintain
account_paths— it is derived fromparent_id.