Skip to content

Runtime & Collections

This page covers the non-entity runtime of @life-manager/db.

FileResponsibility
core.tsstable runtime export surface
schema.tsPowerSync schema definition
collection-registry.tscreates collections and cross-entity live query collections
init.tsinitializes and stores the singleton DB + collection registry
context.tsxinjects adapters and user context into the DB layer
BaseConnector.tsshared PowerSync backend connector using Supabase auth/session
PowerSyncProvider.tsxPowerSync status context
create PowerSync database
-> initCollections(db)
-> mount CollectionsProvider
-> query hooks read from getCollections()
-> action and mutation hooks read adapters from useCollectionsDeps()

createAllCollections() builds the collection registry from:

  • the PowerSync table schema
  • Zod schema/deserialization definitions from @life-manager/db/schemas
  • a set of live-query collections for cross-table joins and derived views

Relevant API pages:

The collections context provides app-level dependencies to the DB package:

  • userId
  • notification adapter
  • confirmation adapter
  • selection adapter

That context is consumed indirectly by action and mutation hooks through useMutationContext() from @life-manager/db/shared.

Relevant API pages:

BaseSupabaseConnector is the shared connector layer between local PowerSync state and Supabase.

It is responsible for:

  • session bootstrap
  • credential fetching for PowerSync
  • login/logout/register helpers
  • CRUD upload handling from local transactions to Supabase
  • fatal error classification for unrecoverable Postgres responses

Relevant API pages:

The package exposes a small PowerSync status context for apps that need to render connection state or reconnect flows.

Relevant API pages:

The core runtime does not bypass the entity system. Entity writes still go through:

query state
-> action hook
-> workflow resolution
-> mutation enforcement
-> raw mutation
-> local DB write
-> sync upload

That division is important:

  • the runtime bootstraps collections and sync
  • the entity layer decides what operations are allowed and how the UI should react

App initialization code should usually import from @life-manager/db/core and @life-manager/db/context, not from deep runtime files.

Typical consumers:

  • app boot code
  • PowerSync provider setup
  • platform-specific connector implementations