Skip to content

Database Schema

Loquent uses PostgreSQL with SeaORM 2.0. The schema is defined across 51 migrations and produces 24 entity tables.

TablePurpose
userUser accounts
email_password_accountEmail/password credentials linked to users
sessionActive sessions with expiry, references member
organizationMulti-tenant orgs (Twilio creds, client lookup config, report toggles)
memberUser ↔ Organization membership
TablePurpose
phone_numberTwilio phone numbers, each assigned to an org and optionally an agent
phone_number_analyzerJoin: which analyzers are active on which phone numbers
TablePurpose
agentAI voice agents — name, prompt, realtime_config (JSONB)
agent_knowledgeJoin: which knowledge bases are linked to which agents
TablePurpose
callCall records — SID, phone number, contact, recording URL, transcription
call_analysisAnalysis runs against call transcriptions
TablePurpose
analyzerOrg-level analyzer config — name, prompt, default flag
system_analyzerPlatform-wide system analyzers
system_call_analysisSystem analyzer results
TablePurpose
contactContacts auto-resolved from callers
contact_phonePhone numbers associated with a contact
contact_emailEmail addresses associated with a contact
TablePurpose
knowledgeKnowledge base definitions
knowledge_documentDocuments within a knowledge base (title, description, content)
TablePurpose
todo_typeTo-do type definitions with extraction prompts
todo_type_toolTools available for AI to-do execution
todoExtracted to-do items from calls
TablePurpose
core_confSingle-row runtime config — API keys, provider settings, email config
report_email_addressEmail addresses receiving reports
organization ─┬─ member ── user
├─ phone_number ── agent ── agent_knowledge ── knowledge
├─ analyzer
├─ contact ─┬─ contact_phone
│ └─ contact_email
└─ todo_type ── todo_type_tool
phone_number ── phone_number_analyzer ── analyzer
call ─┬─ phone_number
├─ contact
└─ call_analysis ── analyzer
knowledge ── knowledge_document
todo ── todo_type

A single-row table holding all runtime configuration. Seeded during first migration from seed.env, then managed at runtime.

Column GroupFields
Twiliotwilio_main_sid, twilio_main_token
OpenAIopenai_api_key
Emailresend_api_key, email_domain, email_user_admin
Google/Geminigoogle_project_id, google_client_email, google_private_key, google_location, google_token_uri

SeaORM entity files are gitignored and generated from the live database schema:

Terminal window
just generate
# runs: sea-orm-cli generate entity -o src/bases/db/schemas --with-serde both

This produces one Rust file per table in src/bases/db/schemas/ with Serialize + Deserialize derives on all models. Must be re-run after any migration.