Zum Hauptinhalt springen

Database Schema

JustCall uses Supabase PostgreSQL with a multi-tenant architecture.

Entity Relationship Diagram

Core Tables

accounts

Top-level tenant (Kunde/Mandant).

ColumnTypeDescription
iduuidPrimary key
nametextAccount name
slugtextURL-friendly identifier
stripe_customer_idtextStripe customer ID
billing_emailtextBilling contact
twilio_account_sidtextTwilio subaccount SID
created_attimestamptzCreation timestamp

restaurants

Restaurant/branch within an account.

ColumnTypeDescription
iduuidPrimary key
account_iduuidFK to accounts
nametextRestaurant name
phonetextRestaurant phone
addresstextPhysical address
voice_enabledbooleanVoice ordering active
whatsapp_enabledbooleanWhatsApp ordering active
minimum_order_valuedecimalMinimum for delivery
default_delivery_feedecimalStandard delivery charge
system_prompt_overridetextCustom AI prompt
vad_thresholddecimalVAD sensitivity
vad_silence_duration_msintegerSilence before response
logging_leveltextDebug logging level

orders

Customer orders.

ColumnTypeDescription
iduuidPrimary key
restaurant_iduuidFK to restaurants
order_numbertextHuman-readable number
statustextpending/confirmed/preparing/ready/delivered/cancelled
order_typetextpickup/delivery
customer_nametextCustomer name
customer_phonetextPhone number
delivery_addresstextAddress (if delivery)
delivery_feedecimalCharged fee
subtotaldecimalSum of items
totaldecimalFinal amount
itemsjsonbOrder items snapshot
call_session_iduuidFK to call_sessions
created_attimestamptzOrder time

Menu sections.

ColumnTypeDescription
iduuidPrimary key
restaurant_iduuidFK to restaurants
nametextCategory name
sort_orderintegerDisplay order
is_activebooleanVisible in menu

Individual dishes.

ColumnTypeDescription
iduuidPrimary key
category_iduuidFK to menu_categories
nametextItem name
descriptiontextDescription
pricedecimalPrice in CHF
is_availablebooleanCurrently orderable
allergenstext[]Allergen list
image_urltextOptional image

call_sessions

Voice call records.

ColumnTypeDescription
iduuidPrimary key
restaurant_iduuidFK to restaurants
twilio_call_sidtextTwilio call ID
statustextactive/completed/failed
caller_phonetextCustomer phone
started_attimestamptzCall start
ended_attimestamptzCall end
duration_secondsintegerCall length
order_iduuidFK to orders (if created)

delivery_zones

Delivery coverage areas.

ColumnTypeDescription
iduuidPrimary key
restaurant_iduuidFK to restaurants
nametextZone name
typetextpolygon/plz
geojsonjsonbPolygon coordinates
plz_codestext[]Postal codes
delivery_feedecimalZone-specific fee
minimum_orderdecimalZone-specific minimum
estimated_minutesintegerDelivery time

kb_documents

Knowledge base articles.

ColumnTypeDescription
iduuidPrimary key
restaurant_iduuidFK to restaurants
titletextDocument title
contenttextFull text content
source_typetextmanual/faq/menu
is_activebooleanInclude in RAG

kb_chunks

Vectorized document chunks for RAG.

ColumnTypeDescription
iduuidPrimary key
document_iduuidFK to kb_documents
contenttextChunk text
embeddingvector(1536)OpenAI embedding
metadatajsonbExtra data

Indexes

Key indexes for performance:

-- Order lookups
CREATE INDEX idx_orders_restaurant_status ON orders(restaurant_id, status);
CREATE INDEX idx_orders_created_at ON orders(created_at DESC);

-- Menu queries
CREATE INDEX idx_menu_items_category ON menu_items(category_id);
CREATE INDEX idx_menu_categories_restaurant ON menu_categories(restaurant_id);

-- RAG search
CREATE INDEX idx_kb_chunks_embedding ON kb_chunks USING ivfflat (embedding vector_cosine_ops);

-- Session lookups
CREATE INDEX idx_call_sessions_restaurant ON call_sessions(restaurant_id);
CREATE INDEX idx_call_sessions_status ON call_sessions(status);

JSONB Schemas

orders.items

[
{
"name": "Margherita",
"price": 16.50,
"quantity": 2,
"notes": "extra scharf"
}
]

delivery_zones.geojson

{
"type": "Polygon",
"coordinates": [[[8.5, 47.3], [8.6, 47.3], [8.6, 47.4], [8.5, 47.4], [8.5, 47.3]]]
}