Skip to content

๐Ÿ“Š Database Schema โ€‹

The database schema is defined in prisma/schema.prisma using Prisma ORM. It targets PostgreSQL 16.

๐Ÿ“‹ Models by Domain โ€‹

๐Ÿ‘ค Users & Authentication โ€‹

ModelTableDescription
UserusersStaff/admin accounts with roles
CustomercustomersCustomer accounts (registered or guest)
CustomerGroupcustomer_groupsCustomer segmentation
AddressaddressesCustomer delivery addresses

๐Ÿ“ Locations โ€‹

ModelTableDescription
LocationlocationsRestaurant locations
OperatingHouroperating_hoursPer-day open/close times
DeliveryZonedelivery_zonesDelivery areas with fees

๐Ÿฝ๏ธ Menu โ€‹

ModelTableDescription
CategorycategoriesMenu categories (hierarchical)
MenuItemmenu_itemsMenu items with pricing
MenuOptionmenu_optionsOption groups (Size, Toppings)
MenuOptionValuemenu_option_valuesIndividual options (Small, Large)
MealtimemealtimesTime-based availability windows
MenuItemMealtimemenu_item_mealtimesItem โ†” mealtime junction
AllergenallergensAllergen types
MenuItemAllergenmenu_item_allergensItem โ†” allergen junction

๐Ÿ›’ Orders & Payments โ€‹

ModelTableDescription
OrderordersCustomer orders
OrderItemorder_itemsLine items in an order
OrderItemOptionorder_item_optionsSelected options per line item
PaymentpaymentsPayment records (Stripe, PayPal, cash)

๐Ÿช‘ Reservations โ€‹

ModelTableDescription
TabletablesRestaurant tables
ReservationreservationsTable reservations

๐Ÿ“ฃ Marketing & Engagement โ€‹

ModelTableDescription
CouponcouponsDiscount coupons
ReviewreviewsCustomer reviews
LoyaltyTransactionloyalty_transactionsLoyalty point history
AutomationRuleautomation_rulesEvent-driven automation

๐Ÿท๏ธ Enums โ€‹

EnumValues
RoleSUPER_ADMIN, MANAGER, STAFF
OrderTypeDELIVERY, PICKUP
OrderStatusPENDING, CONFIRMED, PREPARING, READY, OUT_FOR_DELIVERY, DELIVERED, PICKED_UP, CANCELLED
PaymentMethodCASH, STRIPE, PAYPAL
PaymentStatusPENDING, COMPLETED, FAILED, REFUNDED
ReservationStatusPENDING, CONFIRMED, SEATED, COMPLETED, CANCELLED
CouponTypePERCENTAGE, FIXED, FREE_DELIVERY
MenuOptionDisplayTypeSELECT, RADIO, CHECKBOX, QUANTITY
LoyaltyTransactionTypeEARN, REDEEM, ADJUST

๐Ÿ”— Key Relationships โ€‹

  • ๐Ÿ‘ค User belongs to a Location (optional staff assignment)
  • ๐Ÿ›๏ธ Customer has many Address, Order, Reservation, Review, LoyaltyTransaction
  • ๐Ÿ“ Location has many Category, MenuItem, Table, DeliveryZone, OperatingHour, Order, Reservation, Review
  • ๐Ÿ“‚ Category has self-referential parent/children for nesting
  • ๐Ÿ” MenuItem belongs to Category, has many MenuOption, MenuItemMealtime, MenuItemAllergen
  • ๐Ÿ“ฆ Order has many OrderItem, Payment, Review, LoyaltyTransaction
  • ๐Ÿ“‹ OrderItem has many OrderItemOption (snapshot of selected options)

๐Ÿ—‘๏ธ Cascade Behaviors โ€‹

The following relations use onDelete: Cascade:

  • Address โ†’ deleted when Customer is deleted
  • OrderItem โ†’ deleted when Order is deleted
  • OrderItemOption โ†’ deleted when OrderItem is deleted
  • Payment โ†’ deleted when Order is deleted
  • MenuOption โ†’ deleted when MenuItem is deleted
  • MenuOptionValue โ†’ deleted when MenuOption is deleted
  • Table โ†’ deleted when Location is deleted
  • DeliveryZone โ†’ deleted when Location is deleted
  • OperatingHour โ†’ deleted when Location is deleted
  • Junction tables (MenuItemMealtime, MenuItemAllergen) โ†’ deleted when either side is deleted