05 - Database Design
Overview
MultiWA uses PostgreSQL with Prisma ORM for type-safe database access.
Entity Relationship Diagram
┌────────────────┐ ┌────────────────┐
│ Organization │───────│ Workspace │
└────────────────┘ └───────┬────────┘
│
┌────────────┼────────────┐
│ │ │
┌──────▼───┐ ┌─────▼────┐ ┌─────▼────┐
│ Profile │ │ Account │ │ User │
└────┬─────┘ └──────────┘ └──────────┘
│
┌────────────┼────────────┬─────────────┐
│ │ │ │
┌────▼───┐ ┌─────▼────┐ ┌─────▼────┐ ┌──────▼─────┐
│Contact │ │ Message │ │Broadcast │ │ Automation │
└────────┘ └──────────┘ └──────────┘ └────────────┘
Core Models
Profile (WhatsApp Session)
model Profile {
id String @id @default(cuid())
name String
phone String?
status String @default("disconnected")
engine String @default("whatsapp-web-js") // whatsapp-web-js | baileys | mock
webhookUrl String?
createdAt DateTime @default(now())
contacts Contact[]
messages Message[]
broadcasts Broadcast[]
}
Contact
model Contact {
id String @id @default(cuid())
phone String
name String?
email String?
tags String[] @default([])
metadata Json?
profileId String
profile Profile @relation(...)
}
Message
model Message {
id String @id @default(cuid())
waMessageId String? @unique
fromMe Boolean
type MessageType
content String
status MessageStatus
timestamp DateTime @default(now())
profileId String
contactId String?
}
Enums
enum SessionStatus {
DISCONNECTED
CONNECTING
QR_READY
CONNECTED
}
// Engine is stored as a plain String on Profile (not a DB enum). Valid values are
// validated at the application layer: whatsapp-web-js (default) | baileys | mock.
enum MessageType {
TEXT
IMAGE
VIDEO
AUDIO
DOCUMENT
LOCATION
CONTACT
POLL
}
Indexes
@@index([profileId])
@@index([phone])
@@index([createdAt])
@@index([status])
← System Architecture · Documentation Index · Engine Abstraction →