Skip to content

Database & Prisma Schema

The prisma/schema.prisma file is the single source of truth for the application's data structure. This page provides a detailed breakdown of each model, its fields, and its relationships.

Authentication Models

These models are primarily managed by the better-auth library to handle user identity and sessions.

User

Represents an administrator account. The application is designed for a single administrator.

FieldTypeDescription
idStringUnique identifier (CUID). Primary key.
emailStringThe user's unique email address, used for login.
passwordStringThe hashed password for the user.
campaignsCampaign[]A one-to-many relationship linking the user to all campaigns they have created.

Other Auth Models (Account, Session, etc.)

These models are standard better-auth requirements for session management, OAuth connections, and verification tokens. Their structure is not critical to the application's core business logic.


Core Business Models

This is the functional heart of the Mood application.

Campaign

The top-level container for a polling event.

FieldTypeDescription
idIntAuto-incrementing integer. Primary key.
nameStringThe descriptive name of the campaign (e.g., "Q4 Feedback").
createdByStringForeign key linking to a User.id.
creatorUserThe relation to the User model. onDelete: Cascade ensures that if a user is deleted, all their campaigns are also deleted.
archivedBooleanA flag for soft-deleting campaigns. Defaults to false.
expiresAtDateTime?An optional date for the campaign to auto-archive.
pollLinksPollLink[]A one-to-many relationship to all poll links generated for this campaign.
votesVote[]A direct one-to-many relationship with all votes, used for fast global aggregations.

The unique, distributable link for a specific team or manager within a campaign.

FieldTypeDescription
idStringUnique identifier (UUID). Primary key. UUIDs are excellent for non-guessable public identifiers.
campaignIdIntForeign key linking to a Campaign.id.
campaignCampaignThe relation to the parent Campaign. onDelete: Cascade ensures that if a campaign is deleted, all its links are also deleted.
tokenStringA unique, short, random string (nanoid(10)) used as the public part of the poll URL.
managerNameStringThe name of the manager or team associated with this link, used for segmenting results.
votesVote[]A one-to-many relationship to all votes submitted through this specific link.

Vote

The atomic unit of feedback, representing a single anonymous submission.

FieldTypeDescription
idIntAuto-incrementing integer. Primary key.
pollLinkIdStringForeign key linking to a PollLink.id. This is crucial for tracking results per manager.
pollLinkPollLinkThe relation to the PollLink used. onDelete: Cascade ensures data integrity.
campaignIdIntDenormalized foreign key to Campaign.id. This is a deliberate performance optimization for global aggregation queries, avoiding an extra join through PollLink.
campaignCampaignThe direct relation to the Campaign.
moodStringThe core sentiment value (e.g., "green", "red").
commentString?Optional qualitative feedback provided by the user.

Logical Relationship Schema

text
[User] 1--* [Campaign] 1--* [PollLink] 1--* [Vote]
                         ^                      |
                         |______________________|
             (A Vote is also directly linked to the Campaign for performance)

Released under the MIT License.