Data and identity platform
The data and identity platform is the shared boundary for durable product data, user identity, protected values, billing links, and customer lifecycle updates. It gives product workflows one source of truth for who a user is, what that user can access, and how account changes reach external services.
Shared data foundation
Durable product state
The database package is the common data boundary for product services. It connects typed MySQL state with authentication, encryption, email, billing, and lifecycle work. Product services use this boundary so users, organizations, videos, sharing, storage, developer media, and billing state follow the same ownership rules.
The data model also stores workflow state that must survive a request. Uploads, processing, imports, support messages, directory sync, mobile push delivery, and customer lifecycle work can therefore continue after the original request ends. See Database schema and migrations for the detailed schema and migration view.
References: packages/…/index.ts• L6-25 packages/…/schema.ts• L89-174 packages/…/schema.ts• L480-596 packages/…/package.json• L61-89
User and organization relationships
The user is the stable identity shared by product services. An organization extends that identity into team access through membership, roles, invites, directory links, and organization settings. Videos, spaces, folders, sharing records, storage objects, and integrations then attach to that user and organization relationship.
This structure lets product workflows separate ownership from access. A viewer can receive access to one video without joining an organization, while an organization member can receive access through the organization’s shared resources and policies.
References: packages/…/schema.ts• L89-154 packages/…/schema.ts• L227-380 packages/…/schema.ts• L438-658 packages/…/schema.ts• L1558-1691
Developer and customer migration state
The same data boundary supports developer media and customer-led imports. Developer applications own their API media, transcripts, webhooks, delivery records, and credit state. Loom migration records track the customer organization, progress, active work, and source identity so retries do not create duplicate videos.
These records connect product ownership to long-running work. They also give billing, cleanup, support, and operator workflows a durable view of state.
References: packages/…/schema.ts• L1815-1897 packages/…/schema.ts• L1899-2395
Customer lifecycle synchronization
Customer lifecycle synchronization turns local account state into a customer profile in Loops. It combines identity, organization access, billing, license, consent, and product-use signals before it updates the remote contact.
Account changes create or revise durable per-user work. The worker claims that work with a lease, reads current state, waits for required billing identity, and updates Loops only when the remote identity and consent checks are safe. It holds an email identity change instead of risking an update to the wrong contact.
This flow connects local changes to a safe remote customer update.
flowchart LR
E[Account or organization change] --> Q[Per-user sync job]
Q --> S[Read identity, billing, consent, and usage]
S --> P[Build customer profile]
P --> R[Check remote identity and consent]
R --> U[Update Loops contact]
U --> N[Schedule next check or retry]
The child page Customer lifecycle automation covers profile rules, enrollment, consent, and queue behavior in more detail.
References: packages/…/worker.ts• L46-90 packages/…/worker.ts• L126-169 packages/…/worker.ts• L233-346 packages/…/schema.ts• L156-174
Identity and authentication
Sign-in identity
Authentication turns proof from an external provider or an email address into the shared user identity. Google, Apple, WorkOS, optional OpenID Connect, trusted private proxies, Google One Tap, passkeys, and email codes can all lead to a session for the same user.
The platform normalizes email identity before lookup and applies signup policy before account access is granted. Existing sessions also carry the user’s session version, so account-wide revocation can reject older sessions without changing the user record’s stable identity.
Google One Tap is a faster sign-in path for an already linked Google account. A short-lived nonce ties the browser request to Google’s signed credential, and the path does not create or link accounts by email.
The sign-in path connects external proof to database identity and then to product access.
sequenceDiagram
participant U as User
participant A as Auth service
participant P as Provider or email
participant D as MySQL data
participant S as Product service
U->>A: Start sign-in
A->>P: Authenticate or send code
P-->>A: Identity proof
A->>D: Find or create user and link account
A-->>U: Session token
S->>A: Read session
A->>D: Check user and session version
D-->>A: Current identity state
A-->>S: Current user or no session
References: packages/…/auth-options.ts• L53-78 packages/…/auth-options.ts• L133-388 packages/…/auth-options.ts• L422-580 packages/…/google-one-tap.ts• L46-79 packages/…/google-one-tap.ts• L171-257
Passkey identity
Passkeys provide a password-free sign-in and a strong identity check for sensitive account actions. A passkey registration or sign-in uses a short-lived challenge, verifies the browser origin and user presence, and records only the credential data needed for later proof.
The first passkey may be added after a fresh non-passkey sign-in. That passkey can sign in but cannot by itself approve later identity-sensitive changes. A passkey that confirms identity can provide a short step-up check instead of an emailed code. Users can keep several passkeys and remove them as account credentials.
Passkey setup and step-up checks share bounded attempts, expiry, one-time challenge use, and account locking. Security notices tell the account owner when a passkey is added or removed.
References: packages/…/passkeys.ts• L235-379 packages/…/passkeys.ts• L389-568 packages/…/passkeys.ts• L584-622 packages/…/auth-challenges.ts• L83-133 packages/…/auth-challenges.ts• L275-335 packages/…/fresh-sign-in.ts• L1-46 packages/…/schema.ts• L1042-1086 packages/…/passkey-added.tsx• L16-60 packages/…/passkey-removed.tsx• L16-60
Email changes and credential revocation
An email change is a controlled identity transition. The platform checks address policy and organization-managed identity, sends a short-lived code to the new address, and applies the change only after a single valid confirmation.
The change updates the product identity and billing contact together. It also signs out web sessions, clears pending authentication checks, removes stale invites for the old address, and queues a lifecycle update. The old address receives a security notice so the previous owner can report an unexpected change.
The account-wide revoke action uses the same session version boundary. It removes browser sessions and passkeys, revokes service keys and MCP tokens, and consumes pending authorization codes and security challenges.
References: packages/…/email-change.ts• L195-305 packages/…/email-change.ts• L367-568 packages/…/revoke-credentials.ts• L18-68 packages/…/security-emails.ts• L79-126 packages/…/email-change-code.tsx• L16-63 packages/…/email-changed.tsx• L16-56
Organization-managed identity
SAML SSO and directory sync let an organization control member access. The sign-in path checks the organization entitlement, provider connection, verified domain, short-lived sign-in intent, linked identity, and directory membership before it grants organization access.
An account with a managed identity cannot change its email through the local account flow. This keeps the account address aligned with the identity provider and prevents an offboarded member from keeping access by leaving the organization’s domain.
References: packages/…/auth-options.ts• L423-443 packages/…/email-change.ts• L100-193 packages/…/schema.ts• L227-355
Service and device identity
Non-browser clients use identities that are separate from browser sessions. Scoped agent keys, CLI authorization codes, MCP OAuth clients and tokens, and mobile push registrations all link back to a user while keeping their own expiry, scope, revocation, or session state.
The platform stores hashes for bearer secrets and one-time codes when it only needs lookup. Mobile push tokens also bind to the authentication key that registered them, so ending that key can remove its notification destination without deleting the user.
References: packages/…/schema.ts• L1023-1283 packages/…/schema.ts• L1139-1207 packages/…/revoke-credentials.ts• L34-67
Protected and billing data
Encrypted application values
Encryption helpers protect values that services must recover later. Integration credentials, storage access data, developer webhook secrets, video passwords, and space passwords stay behind the encrypted-data boundary instead of appearing as plain text in product records.
Password checks use one-way proofs. The service can verify a supplied password without recovering the original value, and a verified share password can remain in an encrypted HTTP-only cookie for later access.
References: packages/…/crypto.ts• L6-60 packages/…/crypto.ts• L63-194 packages/…/schema.ts• L382-409 packages/…/schema.ts• L480-558 packages/…/schema.ts• L886-1009 packages/…/schema.ts• L2334-2368
Billing identity
Stripe customer provisioning links a Cap user to the external billing customer used by product workflows. It reuses a safe customer match when possible, records the Cap user ID in billing metadata, and stores the customer and active subscription state on the user.
Provisioning is idempotent for a new user. The lifecycle worker can complete missing Stripe provisioning before it sends a non-SSO customer to Loops, so lifecycle state does not move ahead of the billing identity it needs.
References: packages/…/stripe-customer.ts• L8-97 packages/…/worker.ts• L126-133 packages/…/worker.ts• L270-287 packages/…/schema.ts• L89-154
Email and security notices
Transactional email
Transactional email is the shared user-message boundary for sign-in codes, security checks, email changes, passkey changes, invites, and product events. Authentication messages fail closed in production when delivery is not configured, while local development can print short-lived codes to the server log.
The email templates express the security contract to the user. They state why a code is needed, how long it remains valid, and what action to take when an account change was not expected.
References: packages/…/security-emails.ts• L4-126 packages/…/auth-options.ts• L331-386 packages/…/account-security-code.tsx• L16-63 packages/…/email-change-code.tsx• L16-63 packages/…/email-changed.tsx• L16-56 packages/…/passkey-added.tsx• L16-60 packages/…/passkey-removed.tsx• L16-60
Schema evolution
Schema contract and migration stream
The typed schema is the shared description of the MySQL data model. Drizzle Kit uses that contract to produce ordered SQL migrations, generated snapshots, and a migration journal. Runtime migration work applies the stream and runs any required data backfills before dependent product flows use the new state.
The latest identity changes add durable challenge state, passkey credentials, email-change requests, passkey identity-confirmation state, and indexes for revocable MCP records. The schema, SQL, snapshots, and journal must describe the same transition.
The child page Database schema and migrations covers schema structure, migration practice, and compatibility work in more detail.
References: packages/…/schema.ts• L1042-1103 packages/…/schema.ts• L1235-1283 packages/…/migrate.ts• L9-46 packages/…/drizzle.config.ts• L1-18 packages/…/0063_passkeys.sql• L1-33 packages/…/0064_email_change_requests.sql• L1-13 packages/…/0065_passkey_confirms_identity.sql• L1-3 packages/…/_journal.json• L439-466
Compatibility transitions
Schema changes must support data that already exists and services that deploy at different times. A new identity flow needs its tables and indexes before callers issue challenges, store credentials, or revoke tokens. A new required meaning must also be safe for old rows before the new rule becomes active.
The confirmsIdentity field gives older passkeys a safe default while marking newly added first-passkey credentials as unable to approve identity-sensitive changes. This lets the authentication policy change without invalidating every stored credential.
References: packages/…/passkeys.ts• L497-548 packages/…/schema.ts• L1042-1067 packages/…/0065_passkey_confirms_identity.sql• L1-3 packages/…/0063_snapshot.json• L1-6 packages/…/0064_snapshot.json• L1-6 packages/…/0065_snapshot.json• L1-6
Change checklist
When these files or sections are changed, remember to consider these:
- Keep email normalization aligned across sign-in, email changes, provider identity, organization invites, lifecycle contacts, and billing customer matching.
- Keep session-version changes aligned with every account action that must revoke browser sessions or pending credentials.
- Keep passkey challenge purpose, expiry, one-time consumption, identity-confirmation state, and first-passkey rules aligned across registration, sign-in, step-up, and revoke flows.
- Keep email-change ownership checks aligned with SSO accounts, active directory users, verified organization domains, invites, Stripe email, and lifecycle identity.
- Keep Google One Tap nonce creation, cookie scope, signed-token checks, and linked-account lookup aligned with the redirect sign-in path.
- Keep encrypted fields aligned with every caller that must decrypt integration, storage, webhook, video, or space secrets.
- Keep customer lifecycle profile signals, consent, remote identity checks, Stripe readiness, job revisions, leases, and retries aligned across local writes and the Loops worker.
- Keep migration
0063through0065aligned across the typed schema, SQL, snapshots, journal order, and the authentication flows that read the new state. - Apply data backfills or safe defaults before making a new identity or access rule required for existing rows.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A passkey challenge is reused or expires | Sign-in, registration, or step-up is rejected | Store a purpose-bound challenge and consume it once before accepting the assertion |
| A first passkey is treated as identity-confirming | A fresh session can approve a sensitive account change | Keep first-passkey credentials separate from passkeys that confirm identity |
| An email change ignores managed SSO or directory identity | A user can leave a managed address and keep access after offboarding | Check linked SSO, active directory, trusted-proxy, and verified organization-domain state |
| Email change updates the user but not Stripe or Loops | Billing or lifecycle messages use the old customer identity | Update the billing contact with rollback protection and enqueue lifecycle sync in the same account transition |
| Account revocation omits a credential class | A revoked account can still use a passkey, service key, MCP token, or pending code | Revoke all credential families while holding the user’s session-version boundary |
| Google One Tap accepts a valid token without a matching nonce or linked account | A browser can sign in as an unlinked Google identity | Require a fresh nonce and an existing Google provider account |
| The encryption key is missing or invalid | Protected values cannot be read or written | Use one stable server-side hexadecimal key with an accepted size |
| Loops runs before a non-SSO Stripe customer exists | Customer lifecycle sync is held and remote state is incomplete | Provision Stripe identity before the lifecycle worker updates the contact |
| A lifecycle job writes after a newer revision or changed email | Old customer data can replace current account data | Claim with a lease and update only with the current job token and revision |
Migration 0063, 0064, or 0065 is missing while the matching flow is deployed | Authentication state cannot be stored or revocation reads are incomplete | Apply each migration with its matching snapshot and journal entry before enabling the flow |
| Production email delivery is not configured | Security or sign-in messages fail and production authentication is blocked | Configure the email provider and sender domain for the deployment |
Key files
| File | Why to read it |
|---|---|
| packages/…/schema.ts | Defines the durable links among users, organizations, product data, authentication state, protected values, billing, and lifecycle jobs. |
| packages/…/auth-options.ts | Shows how provider proof becomes a session and how signup, blocked-account, session-version, and referral rules apply. |
| packages/…/passkeys.ts | Shows the passkey sign-in, registration, step-up, and identity-confirmation contract. |
| packages/…/auth-challenges.ts | Shows the shared one-time challenge and emailed step-up code boundary. |
| packages/…/email-change.ts | Shows how a verified email transition affects account, organization, billing, sessions, and lifecycle state. |
| packages/…/revoke-credentials.ts | Shows the account-wide credential revocation boundary. |
| packages/…/google-one-tap.ts | Shows how Google One Tap is tied to a browser nonce and an existing linked identity. |
| packages/…/crypto.ts | Defines reversible encryption and one-way password-proof helpers. |
| packages/…/stripe-customer.ts | Shows how users map to Stripe customers and subscription-derived product state. |
| packages/…/worker.ts | Shows how queued customer profiles are checked, synchronized, retried, and held. |
| packages/…/0063_passkeys.sql | Adds the durable passkey and challenge state. |
| packages/…/0064_email_change_requests.sql | Adds the durable email-change confirmation state. |
| packages/…/0065_passkey_confirms_identity.sql | Adds the distinction between sign-in passkeys and identity-confirming passkeys. |
| packages/…/migrate.ts | Shows how ordered migrations and required backfills are applied. |
| packages/…/security-emails.ts | Shows the security-code, email-change, and passkey notice delivery boundary. |
| packages/…/account-security-code.tsx | Shows the user-facing security-code message contract. |
| docs/database-schema-and-migrations.md | Provides the detailed schema and migration guide. |
| docs/customer-lifecycle-automation.md | Provides the detailed lifecycle enrollment and synchronization guide. |