Skip to content

Database Schema

This document outlines the database schema for the Coastal Element AI SDR backend, which is defined using Prisma and uses MongoDB.

Overview

  • Database: MongoDB
  • ORM: Prisma

Entity Relationship Diagram


Enums

CampaignStatus

Defines the possible statuses for a campaign.

  • DRAFT
  • ACTIVE
  • PAUSED
  • COMPLETED
  • ARCHIVED

Authentication Tables

These tables are responsible for handling user authentication, sessions, and accounts.

User

Core user model.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
nameString
emailString@unique
emailVerifiedBoolean
imageString?
createdAtDateTime
updatedAtDateTime
roleString?
bannedBoolean?
banReasonString?
banExpiresDateTime?
twoFactorEnabledBoolean?
sessionsSession[]Relation to Session model
accountsAccount[]Relation to Account model
twofactorsTwoFactor[]Relation to TwoFactor model
profileUserProfile?Relation to UserProfile model

Session

User sessions.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
expiresAtDateTime
tokenString@unique
createdAtDateTime
updatedAtDateTime
ipAddressString?
userAgentString?
userIdStringForeign key to User
userUserRelation to User model
impersonatedByString?

Account

User accounts from different providers.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
accountIdString
providerIdString
userIdStringForeign key to User
userUserRelation to User model
accessTokenString?
refreshTokenString?
idTokenString?
accessTokenExpiresAtDateTime?
refreshTokenExpiresAtDateTime?
scopeString?
passwordString?
createdAtDateTime
updatedAtDateTime

Verification

Stores verification tokens for actions like email verification.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
identifierString
valueString
expiresAtDateTime
createdAtDateTime?
updatedAtDateTime?

TwoFactor

Stores two-factor authentication settings for users.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
secretString
backupCodesString
userIdStringForeign key to User
userUserRelation to User model

Application Tables

These tables handle the core application logic, including user profiles, brands, campaigns, and leads.

AppSettings

Global configurations for the application.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
maintenance_modeBoolean@default(false)
maintenance_messageString?
updatedAtDateTime@default(now()) @updatedAt

UserProfile

Extended user profile information.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
preferencesJson@default("{}")
brandBrand[]Relation to Brand model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt
userUser?Relation to User model
userIdString?@db.ObjectId @unique

Brand

Represents a user-owned brand.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
nameString
profileIdString@db.ObjectId
profileUserProfileRelation to UserProfile model
leadsLeads[]Relation to Leads model
campaignsCampaigns[]Relation to Campaigns model
infoBrandInformationRelation to BrandInformation model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt
brandInformationIdString@db.ObjectId

BrandInformation

AI configurations for a brand.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
personalityString
voiceString
audienceString
idealClientProfileString?
biggestChallengesString?
documentUrlString?
emailsJson@default("[]")
socialAccountsJson@default("{}")
phoneString?
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt
BrandBrand[]Relation to Brand model

Leads

Groups or containers for contacts.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
nameString
descriptionString?
totalContactsInt@default(0)
isDeletedBoolean@default(false)
tagsJson@default("[]")
brandIdString@db.ObjectId
brandBrandRelation to Brand model
campaignsCampaigns[]Relation to Campaigns model
contactsContacts[]Relation to Contacts model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt

Contacts

Detailed individual leads.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
firstNameString?
lastNameString?
companyString?
emailString
phoneString?
linkedinString?
facebookString?
xProfileString?
websiteString?
locationString?
tagsJson@default("[]")
metadataJson@default("{}")
statusString@default("new")
stageString@default("prospect")
bucketTypeString@default("free")
traitsJson@default("[]")
followUpDateDateTime?
convertedAtDateTime?
sourceFileString?
isEnrichedBoolean@default(false)
enrichedAtDateTime?
enrichmentSourceString@default("manual")
lastEngagementAtDateTime?
totalLinksClickedInt@default(0)
totalEmailsOpenedInt@default(0)
totalRepliesInt@default(0)
engagementScoreInt@default(0)
isDeletedBoolean@default(false)
importedAtDateTime@default(now())
leadsLeads?Relation to Leads model
leadsIdString?@db.ObjectId
campaignLeadsCampaignLeads[]Relation to CampaignLeads model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt
ConversationsConversations[]Relation to Conversations model

Campaigns

Manages marketing campaigns.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
nameString
descriptionString?
typeString
statusCampaignStatus@default(DRAFT)
targetLeadCountInt@default(0)
totalLeadsEnrolledInt@default(0)
totalResponsesInt@default(0)
appointmentsSetInt@default(0)
pipelineValueFloat@default(0.0)
avgResponseTimeFloat@default(0.0)
launchedAtDateTime?
pausedAtDateTime?
isActiveBoolean@default(false)
stepsCampaignSteps[]Relation to CampaignSteps model
campaignLeadsCampaignLeads[]Relation to CampaignLeads model
connectLeadsLeadsRelation to Leads model
connectLeadsIdString@db.ObjectId
brandIdString@db.ObjectId
brandBrandRelation to Brand model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt

CampaignSteps

Sequence of activities in a campaign.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
typeString
dataJson@default("{}")
is_activeBoolean@default(true)
executionStepExecutionsRelation to StepExecutions model
campaignIdString@db.ObjectId
campaignCampaignsRelation to Campaigns model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt
stepExecutionsIdString@db.ObjectId

StepExecutions

Tracks the execution of each campaign step.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
errorMessageString?
responseReceivedBoolean@default(false)
executedAtDateTime?
scheduledAtDateTime?
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt
CampaignStepsCampaignSteps[]Relation to CampaignSteps model

CampaignLeads

Metrics for each lead within a campaign.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
lastContactAtDateTime?
optedOutBoolean@default(false)
hasRepliedBoolean@default(false)
firstReplyAtDateTime?
totalRepliesInt@default(0)
totalOpensInt@default(0)
totalClicksInt@default(0)
lastEngagementDateTime?
campaignIdString@db.ObjectId
campaignCampaignsRelation to Campaigns model
contactContacts?Relation to Contacts model
contactIdString?@db.ObjectId
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt

Conversations

Inbox threads for each contact.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
campaignIdString?@db.ObjectId
statusString@default("active")
modeString@default("auto")
handoffAtDateTime?
tagString@default("medium")
messagesMessages[]Relation to Messages model
contactIdString@db.ObjectId
contactContactsRelation to Contacts model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt

Messages

Individual messages within a conversation.

FieldTypeNotes
idString@id @default(auto()) @map("_id") @db.ObjectId
contentString
message_typeString
scheduled_atDateTime?
sent_atDateTime?
delivered_atDateTime?
opened_atDateTime?
open_countInt@default(0)
metadataJson@default("{}")
conversationIdString@db.ObjectId
conversationConversationsRelation to Conversations model
createdAtDateTime@default(now())
updatedAtDateTime@default(now()) @updatedAt