🗄️ PostgreSQL Data Models
Kloyst strongly leverages PostgreSQL managed entirely behind Prisma ORM. By sticking aggressively to a Relational Schema, we guarantee strict isolation and transactional safety.
1. Core Tenant Architecture
Vendor Model
The root environment node housing the billing configurations.
id: UUID@idname: StringplanType: Enum(SHARED, DEDICATED)settings: JSON (Stores dynamic configs rather than creating multiple sparse columns).- Relationships: One-to-Many with
Users,Wallets,Campaigns.
User Model
The authentication node granting access to a dashboard scope.
id: UUID@idvendorId: UUID (Strict mapping to Vendor)email: String (Unique)passwordHash: Stringrole: Enum(ADMIN, STAFF)- Indexing:
@@index([vendorId])
2. Infrastructure Models
WabaAccount Model
Configuration keys specifically tracking WhatsApp states.
id: UUIDvendorId: UUIDwabaId: String (Extracted Meta WABA ID)systemUserToken: String (Encrypted token if Dedicated model)phoneNumberId: String
Contact Model (Phonebook)
Client CRM mappings representing destination targets.
id: UUIDvendorId: UUIDmobile: String (Cleaned standardized E.164 without '+' symbols)attributes: JSON (Dynamic mail-merge tags: e.g., name, age, city).
3. Financial Mechanics
Wallet Model (Prepaid Mechanism)
Tracks exact integer floating balance metrics for Shared instances.
id: UUIDvendorId: UUID (Unique, ensuring exactly 1 wallet per vendor)balance: Decimal(Precision 10, Scale 4)updatedAt: DateTime
Transaction Model (Ledger)
Append-only log containing every credit and debit payload for strict accounting trails.
id: UUIDwalletId: UUIDtype: Enum(CREDIT_RECHARGE, DEBIT_MESSAGE, REFUND)amount: Decimalreference: String (Razorpay ID / Target Campaign ID)
4. Communication States
Campaign Model
Group orchestrator for bulk deployments.
id: UUIDvendorId: UUIDname: Stringstatus: Enum(DRAFT, QUEUED, PROCESSING, COMPLETED, FAILED)
MessageLog Model (High-Throughput Table)
Tracks the absolute granular state of individual WA transmissions.
id: UUIDvendorId: UUIDcampaignId: UUID (Nullable if transaction sent via API)waMessageId: String (Unique Meta return hash e.g.,wamid.XXX)status: Enum(SENT, DELIVERED, READ, FAILED)direction: Enum(INBOUND, OUTBOUND)