Data Model
The detailed typed schema lives in the Supabase migrations andpackages/database/types.ts. This page summarizes the parts of the model that matter for product and operational reasoning.
Design rules
- Supabase Postgres is the system of record.
- Webhooks are stored as first-class operational records.
- Conversations are derived from durable message history.
- Outbox jobs are explicit rows, not hidden queue internals.
- Workspace scoping and RLS are mandatory on every table.
Core entity groups
Workspace and access
workspacesworkspace_membersapi_keys
api_keys are workspace-scoped and used for public REST API v1 authentication. All key operations filter by the caller’s resolved workspace_id — keys from other workspaces are never visible or operable.
Channel and contact plane
channelscontactstagscontact_tag_links
Inbox and message ledger
conversationsmessagesmessage_events
Templates, campaigns, and journeys
templatescampaignscampaign_recipientsjourneys
AI and Margaret layer
llm_provider_configs— per-workspace LLM provider configuration (OpenAI, Anthropic, OpenRouter, Ollama, vLLM). References secrets stored in Supabase Vault.workspace_secret_bindings— maps a workspace to a named Vault secret (e.g., an LLM API key or Meta access token). Secrets never appear in plain-text columns.ai_agents— defines an AI agent persona, model selection, tool permissions, and PII pseudonymization settings per workspace.ai_threads— a thread of AI conversation context associated with a contact/conversation pair.ai_thread_messages— individual messages within an AI thread (user, assistant, tool roles).ai_agent_executions— audit log of tool-use runs during agent execution (BORD-140–143). Each execution records the agent, tools invoked, input/output, and outcome.
Webhook and operational plane
webhook_eventsoutbox_jobsaudit_logs
webhook_eventsstores inbound provider and partner deliveriesoutbox_jobsstores asynchronous follow-up work including message sendsaudit_logsstores operator and system actions (member changes, GDPR erasures, secret rotations, write operations that need review)
Webhook-first design
Webhook records carry:- source and topic
- verification result
- dedupe keys
- processing status
- attempt counts
- payload summaries
Realtime posture
The schema enables Supabase Realtime on operational tables such as:conversationsmessageswebhook_eventsoutbox_jobscampaigns
Current implementation note
The repo preserves route and UI contracts with a typed in-memory implementation in@repo/database when WHATSAPP_PLATFORM_DATA_MODE=mock. That is a delivery choice, not a different schema. The canonical schema lives in the Supabase migrations and generated types.