Skip to main content

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 SessionStatus @default(DISCONNECTED)
engine EngineType @default(BAILEYS)
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
}

enum EngineType {
BAILEYS
WHATSAPP_WEB_JS
}

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 →