Skip to main content
Back to Elite Events

Elite Events Documentation

Technical documentation, guides, and API references for the Elite Events platform.

Architecture/Database Schema

Database Schema Documentation

Overview

Elite Events uses MySQL as the primary database with Prisma ORM for type-safe database access. The schema supports a comprehensive e-commerce platform with promotions, loyalty programs, support ticketing, and affiliate systems.

Entity Relationship Diagram

Core E-commerce

+----------------+     +----------------+     +----------------+
|     User       |----<|     Order      |>----|   OrderItem    |
+----------------+     +----------------+     +----------------+
| id             |     | id             |     | id             |
| email          |     | userId         |     | orderId        |
| name           |     | status         |     | productId      |
| role           |     | total          |     | quantity       |
| password       |     | shippingAddress|     | price          |
| createdAt      |     | createdAt      |     +----------------+
+----------------+     +----------------+            |
       |                                             |
       |                                             v
       v                                     +----------------+
+----------------+                           |    Product     |
|    Address     |                           +----------------+
+----------------+     +----------------+    | id             |
| id             |     |   Category     |--->| title          |
| userId         |     +----------------+    | categoryId     |
| type           |     | id             |    | price          |
| street         |     | title          |    | discountedPrice|
| city           |     | slug           |    | stock          |
| state          |     | parentId       |    | sku            |
| zipCode        |     +----------------+    | description    |
+----------------+            |              +----------------+
                              |                     |
                              v                     v
                     +----------------+     +----------------+
                     |   (children)   |     | ProductImage   |
                     | Self-reference |     +----------------+
                     +----------------+     | id             |
                                            | productId      |
                                            | url            |
                                            | thumbnailUrl   |
                                            | order          |
                                            +----------------+

Promotions System

+----------------+     +----------------+     +----------------+
|   Promotion    |----<|   PromoCode    |>----|PromotionUsage  |
+----------------+     +----------------+     +----------------+
| id             |     | id             |     | id             |
| name           |     | promotionId    |     | promotionId    |
| type           |     | code           |     | promoCodeId    |
| discountType   |     | usageLimit     |     | userId         |
| discountValue  |     | usageCount     |     | orderId        |
| startDate      |     | isActive       |     | discountAmount |
| endDate        |     +----------------+     | usedAt         |
| isActive       |                            +----------------+
| stackable      |
| priority       |
+----------------+
       |
       +----> BogoPromotion (BOGO deals)
       +----> BundlePromotion (Bundle pricing)
       +----> FreeGiftPromotion (Free items)
       +----> TieredPromotion (Volume discounts)
       +----> FlashSale (Time-limited sales)

Loyalty & Affiliates

+----------------+     +----------------+     +----------------+
| LoyaltyProgram |---->|  LoyaltyTier   |     |CustomerLoyalty |
+----------------+     +----------------+     +----------------+
| id             |     | id             |     | id             |
| name           |     | programId      |     | userId         |
| pointsPerDollar|     | name           |     | totalPoints    |
| redemptionRate |     | minPoints      |     | lifetimePoints |
| isActive       |     | pointsMultiplier|    | currentTierId  |
+----------------+     | perks          |     +----------------+
                       +----------------+            |
                                                     v
                                            +-------------------+
                                            |LoyaltyTransaction |
                                            +-------------------+
                                            | id                |
                                            | customerLoyaltyId |
                                            | type              |
                                            | points            |
                                            | description       |
                                            | orderId           |
                                            | expiresAt         |
                                            +-------------------+

+----------------+     +----------------+
|ReferralProgram |---->|   Referral     |
+----------------+     +----------------+
| id             |     | id             |
| name           |     | programId      |
| referrerReward |     | referrerId     |
| refereeReward  |     | refereeId      |
| minPurchase    |     | referralCode   |
| isActive       |     | status         |
+----------------+     | referrerRewarded|
                       | refereeRewarded |
                       +----------------+

Support System

+----------------+     +----------------+     +----------------+
|  SupportTicket |---->| SupportMessage |---->|MessageAttachment|
+----------------+     +----------------+     +----------------+
| id             |     | id             |     | id             |
| ticketNumber   |     | ticketId       |     | messageId      |
| userId         |     | senderType     |     | fileName       |
| customerEmail  |     | senderId       |     | fileUrl        |
| subject        |     | senderName     |     | fileType       |
| description    |     | content        |     | fileSize       |
| category       |     | isInternal     |     +----------------+
| priority       |     | createdAt      |
| status         |     +----------------+
| assignedToId   |
| orderId        |     +----------------+
| productId      |     | TicketHistory  |
| createdAt      |     +----------------+
| resolvedAt     |     | id             |
+----------------+     | ticketId       |
       |               | action         |
       v               | oldValue       |
+----------------+     | newValue       |
|TicketAttachment|     | performedBy    |
+----------------+     +----------------+

Core Tables

User

Primary user account table supporting customers and admins.

ColumnTypeDescription
idINTPrimary key (auto-increment)
emailVARCHAR(255)Unique email address
passwordVARCHAR(255)Bcrypt hashed password
nameVARCHAR(100)Display name
phoneVARCHAR(20)Phone number
roleENUMCUSTOMER, ADMIN, MODERATOR, SUPPORT
emailVerifiedDATETIMEEmail verification timestamp
imageVARCHAR(500)Avatar URL
twoFactorEnabledBOOLEAN2FA status
twoFactorSecretVARCHAR(500)TOTP secret
failedLoginAttemptsINTFailed login counter
lockedUntilDATETIMEAccount lockout timestamp
createdAtDATETIMECreation timestamp
updatedAtDATETIMELast update timestamp

Indexes:

  • email (UNIQUE)

Product

Product catalog with pricing and inventory.

ColumnTypeDescription
idINTPrimary key
titleVARCHAR(255)Product name
descriptionTEXTFull description
detailsTEXTAdditional details
priceFLOATRegular price
discountedPriceFLOATSale price
skuVARCHAR(50)Stock keeping unit (unique)
stockINTAvailable quantity
categoryIdINTForeign key to Category
specificationsJSONProduct specifications
createdAtDATETIMECreation timestamp
updatedAtDATETIMELast update timestamp

Indexes:

  • sku (UNIQUE)
  • categoryId
  • title
  • price
  • discountedPrice
  • stock
  • createdAt
  • categoryId, stock
  • categoryId, createdAt
  • categoryId, discountedPrice

Category

Hierarchical product categories with self-referencing for subcategories.

ColumnTypeDescription
idINTPrimary key
titleVARCHAR(255)Category name
slugVARCHAR(255)URL-friendly identifier
descriptionTEXTCategory description
imageUrlVARCHAR(500)Category image
parentIdINTParent category (nullable)
createdAtDATETIMECreation timestamp

Indexes:

  • slug (UNIQUE)
  • parentId

Order

Customer orders with status tracking.

ColumnTypeDescription
idINTPrimary key
userIdINTForeign key to User
statusENUMPROCESSING, SHIPPED, DELIVERED, CANCELLED
totalFLOATOrder total
discountAmountFLOATApplied discount
appliedPromoCodeVARCHAR(50)Used promo code
shippingAddressTEXTJSON shipping address
billingAddressTEXTJSON billing address
isDemoBOOLEANDemo order flag
createdAtDATETIMEOrder timestamp
updatedAtDATETIMELast status update

Indexes:

  • userId
  • userId, status
  • createdAt DESC
  • isDemo

OrderItem

Individual items within an order.

ColumnTypeDescription
idINTPrimary key
orderIdINTForeign key to Order
productIdINTForeign key to Product
quantityINTItem quantity
priceFLOATPrice at time of purchase

Indexes:

  • orderId
  • productId

Review

Product reviews and ratings.

ColumnTypeDescription
idINTPrimary key
productIdINTForeign key to Product
userIdINTForeign key to User
ratingINT1-5 star rating
commentTEXTReview text
createdAtDATETIMECreation timestamp
updatedAtDATETIMELast update timestamp

Indexes:

  • productId
  • userId
  • productId, rating
  • productId, createdAt
  • createdAt

Promotion Tables

Promotion

Base promotion configuration.

ColumnTypeDescription
idINTPrimary key
nameVARCHAR(255)Internal name
displayNameVARCHAR(255)Customer-facing name
descriptionTEXTPromotion description
typeENUMPERCENTAGE, FIXED, BOGO, BUNDLE, FREE_GIFT, TIERED, FLASH_SALE
discountTypeENUMPERCENTAGE, FIXED_AMOUNT
discountValueFLOATDiscount amount/percentage
startDateDATETIMEPromotion start
endDateDATETIMEPromotion end
isActiveBOOLEANActive status
usageLimitINTTotal usage limit
usageCountINTCurrent usage count
perCustomerLimitINTPer-customer limit
minimumPurchaseFLOATMinimum cart value
maximumDiscountFLOATDiscount cap
stackableBOOLEANCan combine with others
priorityINTApplication priority
targetTypeENUMALL, SPECIFIC_PRODUCTS, SPECIFIC_CATEGORIES
createdAtDATETIMECreation timestamp
updatedAtDATETIMELast update timestamp

Indexes:

  • startDate, endDate
  • isActive
  • type

PromoCode

Promo codes linked to promotions.

ColumnTypeDescription
idINTPrimary key
promotionIdINTForeign key to Promotion
codeVARCHAR(50)Unique promo code
usageLimitINTCode-specific limit
usageCountINTCurrent usage
isActiveBOOLEANActive status
expiresAtDATETIMECode expiration
createdAtDATETIMECreation timestamp

Indexes:

  • code (UNIQUE)
  • promotionId

Loyalty Tables

CustomerLoyalty

Customer loyalty status and points.

ColumnTypeDescription
idINTPrimary key
userIdINTForeign key to User (unique)
totalPointsINTCurrent available points
lifetimePointsINTTotal points ever earned
currentTierIdINTCurrent membership tier

Indexes:

  • userId (UNIQUE)

LoyaltyTransaction

Points earning and redemption history.

ColumnTypeDescription
idINTPrimary key
customerLoyaltyIdINTForeign key to CustomerLoyalty
typeVARCHAR(50)EARN, REDEEM, EXPIRE, ADJUSTMENT
pointsINTPoints (positive or negative)
descriptionVARCHAR(255)Transaction description
orderIdINTRelated order (nullable)
expiresAtDATETIMEPoints expiration date
createdAtDATETIMETransaction timestamp

Indexes:

  • customerLoyaltyId
  • createdAt

Support Tables

SupportTicket

Customer support tickets.

ColumnTypeDescription
idCUIDPrimary key
ticketNumberVARCHAR(20)Human-readable ticket ID
userIdINTRegistered user (nullable)
customerEmailVARCHAR(255)Customer email
customerNameVARCHAR(100)Customer name
subjectVARCHAR(255)Ticket subject
descriptionTEXTInitial description
categoryENUMORDER, PRODUCT, SHIPPING, REFUND, TECHNICAL, OTHER
priorityENUMLOW, MEDIUM, HIGH, URGENT
statusENUMOPEN, IN_PROGRESS, WAITING_CUSTOMER, RESOLVED, CLOSED
assignedToIdINTAssigned agent
orderIdINTRelated order
productIdINTRelated product
tagsVARCHAR(255)Comma-separated tags
internalNotesTEXTAgent-only notes
firstResponseAtDATETIMEFirst agent response
resolvedAtDATETIMEResolution timestamp
closedAtDATETIMEClosure timestamp
createdAtDATETIMECreation timestamp
updatedAtDATETIMELast update

Indexes:

  • ticketNumber (UNIQUE)
  • userId
  • status
  • priority
  • category
  • assignedToId
  • createdAt
  • orderId
  • productId

Authentication Tables

Account

OAuth provider accounts (NextAuth).

ColumnTypeDescription
idCUIDPrimary key
userIdINTForeign key to User
typeVARCHAR(50)Account type
providerVARCHAR(50)OAuth provider
providerAccountIdVARCHAR(255)Provider's user ID
access_tokenTEXTOAuth access token
refresh_tokenTEXTOAuth refresh token
expires_atINTToken expiration
token_typeVARCHAR(50)Token type
scopeVARCHAR(255)OAuth scope

Indexes:

  • provider, providerAccountId (UNIQUE)
  • userId

Session

Active user sessions (NextAuth).

ColumnTypeDescription
idCUIDPrimary key
sessionTokenVARCHAR(255)Unique session token
userIdINTForeign key to User
expiresDATETIMESession expiration
ipAddressVARCHAR(45)Client IP
userAgentVARCHAR(500)Client user agent
lastActiveDATETIMELast activity

Indexes:

  • sessionToken (UNIQUE)
  • userId

Audit & Analytics Tables

AuditLog

System audit trail.

ColumnTypeDescription
idINTPrimary key
userIdINTActing user
actionVARCHAR(100)Action performed
resourceVARCHAR(100)Resource type
resourceIdINTResource ID
ipAddressVARCHAR(45)Client IP
userAgentTEXTClient user agent
metadataJSONAdditional context
createdAtDATETIMEAction timestamp

Indexes:

  • userId
  • action
  • createdAt

Enums

UserRole

CUSTOMER, ADMIN, MODERATOR, SUPPORT

OrderStatus

PROCESSING, SHIPPED, DELIVERED, CANCELLED

AddressType

SHIPPING, BILLING

PromotionType

PERCENTAGE, FIXED, BOGO, BUNDLE, FREE_GIFT, TIERED, FLASH_SALE

DiscountType

PERCENTAGE, FIXED_AMOUNT

TicketCategory

ORDER, PRODUCT, SHIPPING, REFUND, TECHNICAL, OTHER

TicketPriority

LOW, MEDIUM, HIGH, URGENT

TicketStatus

OPEN, IN_PROGRESS, WAITING_CUSTOMER, RESOLVED, CLOSED

MessageSenderType

CUSTOMER, AGENT, SYSTEM

Relationships Summary

ParentChildTypeDescription
UserOrder1:NUser's orders
UserAddress1:NUser's addresses
UserReview1:NUser's reviews
UserCart1:NCart items
UserWishlist1:NWishlist items
UserCustomerLoyalty1:1Loyalty membership
OrderOrderItem1:NOrder line items
ProductOrderItem1:NProduct in orders
ProductProductImage1:NProduct images
ProductReview1:NProduct reviews
CategoryProduct1:NCategory products
CategoryCategory1:NSubcategories
PromotionPromoCode1:NPromo codes
PromotionPromotionUsage1:NUsage tracking
SupportTicketSupportMessage1:NTicket messages
SupportTicketTicketHistory1:NStatus changes

Database Migrations

Prisma manages schema migrations. To apply changes:

# Generate migration
npx prisma migrate dev --name description

# Apply to production
npx prisma migrate deploy

# Reset database (development only)
npm run db:reset

Seed Scripts

Available seed commands:

npm run db:seed-all        # Seed all data
npm run db:seed-products   # Products and categories
npm run db:seed-users      # User accounts
npm run db:seed-orders     # Order history
npm run db:seed-reviews    # Product reviews
npm run db:seed-promotions # Promotions and codes
npm run db:seed-loyalty    # Loyalty program
npm run db:seed-support    # Support tickets
npm run db:seed-affiliate  # Affiliate program
Documentation | Elite Events | Philip Rehberger