Database
Database Configuration
.sequelizerc
file and src/config/sequelize.config.ts
.Entities and Relationships
Core Entities
User
User
model represents system users.id
: UUID primary keyname
: User's full nameemail
: User's email address (unique)password
: Hashed passwordrole
: User role (admin, user)active
: User account statusMember
(user can be a member of multiple companies)RefreshToken
(user can have multiple refresh tokens)PendingUser
(for invitations)Company
Company
model represents organizations in the system.id
: UUID primary keyname
: Company namedescription
: Company descriptionwebsite
: Company websiteemail
: Company emailphone
: Company phonelogo
: Logo URLactive
: Company statusMember
(company can have multiple members)Agenda
(company can have multiple agendas)Client
(company can have multiple clients)CompanyRole
(company can define multiple roles)Member
Member
model represents a user's membership in a company.id
: UUID primary keyuserId
: Reference to UsercompanyId
: Reference to CompanycompanyRoleId
: Reference to CompanyRoleactive
: Membership statusUser
(member belongs to a user)Company
(member belongs to a company)CompanyRole
(member has a role in the company)Appointment
(member can have multiple appointments)Client
Client
model represents clients of a company.id
: UUID primary keyname
: Client nameemail
: Client emailphone
: Client phone numbercompanyId
: Reference to Companynotes
: Client notesactive
: Client statusCompany
(client belongs to a company)ClientThread
(client can have multiple conversation threads)Appointment
(client can have multiple appointments)Appointment Management
Agenda
Agenda
model represents appointment calendars.id
: UUID primary keyname
: Agenda namedescription
: Agenda descriptioncompanyId
: Reference to CompanygoogleCalendarId
: Optional Google Calendar IDcolor
: Calendar color codeactive
: Agenda statusCompany
(agenda belongs to a company)Appointment
(agenda can have multiple appointments)Appointment
Appointment
model represents scheduled meetings.id
: UUID primary keytitle
: Appointment titledescription
: Appointment descriptionstartDate
: Start date and timeendDate
: End date and timestatus
: Appointment status (scheduled, completed, cancelled)agendaId
: Reference to AgendaclientId
: Reference to ClientgoogleEventId
: Optional Google Calendar event IDAgenda
(appointment belongs to an agenda)Client
(appointment is with a client)Member
through AppointmentMember
(appointment has multiple members)Messaging
MessagingInstance
MessagingInstance
model represents WhatsApp messaging instances.id
: UUID primary keyname
: Instance namecompanyId
: Reference to Companyphone
: Phone numberstatus
: Connection statusactive
: Instance statusCompany
(messaging instance belongs to a company)ClientThread
ClientThread
model represents messaging threads with clients.id
: UUID primary keyclientId
: Reference to ClientmessagingInstanceId
: Reference to MessagingInstancelastMessage
: Last message contentlastMessageDate
: Last message timestampunreadCount
: Number of unread messagesstatus
: Thread statusClient
(thread is with a client)MessagingInstance
(thread uses a messaging instance)Plans and Subscriptions
PlanType
PlanType
model represents subscription plan types.id
: UUID primary keyname
: Plan namedescription
: Plan descriptionfeatures
: Plan featuresprice
: Plan priceactive
: Plan statusPlanDuration
(plan type can have multiple durations)Company
(companies can subscribe to plans)PlanDuration
PlanDuration
model represents subscription duration options.id
: UUID primary keyplanTypeId
: Reference to PlanTypemonths
: Duration in monthsdiscount
: Discount percentageactive
: Duration statusPlanType
(duration belongs to a plan type)Integration Models
IntegrationToken
IntegrationToken
model stores tokens for external service integrations.id
: UUID primary keycompanyId
: Reference to Companyservice
: Service name (google, chatwoot, etc.)accessToken
: Access tokenrefreshToken
: Refresh tokenexpiry
: Token expiration dateactive
: Token statusCompany
(token belongs to a company)GoogleWebhook
GoogleWebhook
model tracks Google Calendar webhook subscriptions.id
: UUID primary keycompanyId
: Reference to CompanycalendarId
: Google Calendar IDresourceId
: Google resource IDchannelId
: Google channel IDexpiration
: Webhook expiration dateactive
: Webhook statusCompany
(webhook belongs to a company)OpenAICred
OpenAICred
model stores OpenAI API credentials.id
: UUID primary keycompanyId
: Reference to CompanyapiKey
: OpenAI API keyorganization
: OpenAI organization IDactive
: Credential statusCompany
(credentials belong to a company)OpenAIBots
(credentials can be used by multiple bots)OpenAIBots
OpenAIBots
model represents OpenAI-powered chatbot configurations.id
: UUID primary keycompanyId
: Reference to CompanyopenaiCredId
: Reference to OpenAICredname
: Bot namemodel
: OpenAI model nametemperature
: Model temperature settingsystemPrompt
: System prompt for the botactive
: Bot statusCompany
(bot belongs to a company)OpenAICred
(bot uses OpenAI credentials)Database Schema Diagram
1.
2.
3.
4.
5.
6.
Modificado em 2025-04-24 22:32:03