Documentation Index
Fetch the complete documentation index at: https://docs.yourhq.ai/llms.txt
Use this file to discover all available pages before exploring further.
Database Schema
HQ stores shared state in one Supabase project per workspace. The SQL source of truth lives indb/migrations/ and should be applied in filename order.
Migrations
| File | Contents |
|---|---|
001_extensions.sql | Required Postgres extensions (vector, pg_cron, pgcrypto) |
002_enums.sql | Shared enum types used across tables |
003_shared_functions.sql | set_updated_at() trigger function |
004_workspace.sql | Workspace settings, pipeline stages, field definitions, seed row |
005_crm.sql | Tags, campaigns, contacts, organizations, templates |
006_gateways.sql | Gateway hosts, registration tokens, consume_gateway_token() RPC |
007_agents.sql | Agent registry, org-chart hierarchy, agent_reports_chain() RPC |
008_interactions.sql | Contact interaction timeline and sync triggers |
009_tasks_streams.sql | Streams, tasks, recurring task series, and scheduling |
010_comments_attachments.sql | Polymorphic comments and task attachments |
011_assets_documents.sql | Assets, documents, semantic search, and draft sets |
012_audit_notifications.sql | Audit log and notification tables |
013_agent_inbox.sql | Agent inbox queue, inbox triggers, and automation rules |
014_agent_commands.sql | Command queue for agent lifecycle and system operations |
015_usage_budgets.sql | LLM usage logging, per-agent budgets, and enforcement |
016_rls_realtime_storage.sql | Row-level security, Realtime subscriptions, Storage buckets |
017_setup_wizard.sql | complete_setup() RPC for the first-run wizard |
IF NOT EXISTS, CREATE OR REPLACE) and safe to re-run.
Trust Model
HQ is designed as single-user admin software.- The
authenticatedrole has broad workspace access. - The
service_rolekey is trusted by the UI and gateway services. - Workspace isolation is by Supabase project, not by tenant rows inside one shared database.
- The hosted product, when built, should add an account layer outside this self-hosted schema.
Core Tables
Workspace
workspace— singleton workspace profile, owner preferences, setup state, and budget defaults.audit_log— append-style audit events for important UI and system actions.notifications— operator-visible notifications such as budget warnings and command outcomes.
Agents and Gateways
agents— agent metadata, slug, status, gateway assignment, manager assignment, and template metadata.gateways— registered gateway hosts, heartbeat state, labels, and reachable URLs.gateway_registration_tokens— short-lived hashed tokens used by Settings → Gateways → Add Gateway.agent_commands— command queue consumed by the runner daemon.agent_inbox_items— background-work queue consumed by agents through the dispatcher/runtime path.
lease_command(...)atomically leases pending commands for one gateway.start_command(...),complete_command(...), andfail_command(...)update command lifecycle state.lease_inbox_item(...),complete_inbox_item(...), andfail_inbox_item(...)update inbox lifecycle state.agent_reports_chain(...)returns an agent’s manager chain for cycle detection.
Usage and Budgets
agent_usage— append-only LLM call records with provider, model, tokens, cache tokens, estimated cost, and metadata.agent_budgets— per-agent budget config and current monthly rollup.
agent_usage_rollup trigger updates agent_budgets after each usage row. Budget status changes can create budget.warned and budget.exceeded notifications.
CRM
contacts— people records, core fields, pipeline status, priority, relationship strength, andextendedcustom data.organizations— company/group records andextendedcustom data.contact_organizations— links between contacts and organizations.interactions— timeline entries for calls, messages, notes, meetings, and other relationship events.templates,campaigns,draft_sets— outreach and campaign workflow data.
Tasks
tasks— operator and agent work items.streams— task grouping and workflow lanes.task_series— recurring task definitions.task_comments/ comments-related tables — discussion and mention surface.task_attachments— links from tasks to documents/assets/files.
agent_inbox_items for affected agents.
Documents and Assets
documents— rich-text knowledge base documents, folders, tags, pinned state, and metadata.document_folders— folder hierarchy.assets— operational files and references such as SOPs, research, images, videos, audio, templates, scripts, spreadsheets, and links.asset_folders— asset folder hierarchy.
boot:allincludes a document for every agent.boot:<agent-slug>includes a document for one agent.
Automations
automation_rules— event-driven rules that turn CRM/task/comment changes into agent inbox items.agent_inbox_items— stores the resulting work items, lease state, retry counters, dedup keys, and failure state.
Configuration Tables
field_definitions— custom fields by entity type.pipeline_stages— runtime-configurable pipeline stages.streams— task stream definitions.
Realtime
The runner and dispatcher use Supabase Realtime subscriptions for low-latency wakeups:- Runner listens for inserts into
agent_commands. - Dispatcher listens for inserts into
agent_inbox_items.
Applying Migrations
Fresh project:- Create a Supabase project.
- Open SQL Editor.
- Run every
.sqlfile indb/migrations/in filename order (001through017). Or use the onboarding wizard, which concatenates them all into a single copy-paste blob. - Create an auth user and disable public signup unless needed.
- Back up the database.
- Run all migration files — they are idempotent (
IF NOT EXISTS,CREATE OR REPLACE) and safe to re-run. - Confirm the UI onboarding validator passes.