Skip to Content
MySagra 1.4.0 is released 🎉

Database

MySagra uses MySQL as its primary database, managed via Prisma ORM . Migrations are applied automatically on API startup when MIGRATE_ON_START=true is set in the environment (default for the Docker Compose setup).

ER Diagram

erDiagram Category { String id PK String name Boolean available Int position String image String printerId FK } Ingredient { String id PK String name } Food { String id PK String name String description Decimal price Boolean available String categoryId FK String printerId FK } FoodIngredient { String foodId FK String ingredientId FK } Order { Int id PK String displayCode String table String customer DateTime createdAt DateTime confirmedAt Int ticketNumber OrderStatus status PaymentMethod paymentMethod Decimal subTotal Decimal discount Decimal surcharge Decimal total String userId FK String cashRegisterId FK } OrderItem { String id PK Int quantity Int orderId FK String foodId FK Decimal unitPrice Decimal unitSurcharge Decimal total String notes } Role { String id PK String name } User { String id PK String username String password String roleId FK } RefreshToken { String id PK String token String userId FK DateTime createdAt DateTime expiresAt DateTime revokedAt String ip String userAgent } Printer { String id PK String name String ip String mac Int port String description PrinterStatus status } CashRegister { String id PK String name Boolean enabled String defaultPrinterId FK } ApiKey { String id PK String hash_key String prefix String last_digits ApiKeyType type String name DateTime createdAt DateTime lastUsedAt DateTime revokedAt } Banner { String id PK String name BannerType type String title String description String website String instagram String facebook String image String color DateTime dateTime } OrderInstruction { String id PK String text Int position } Report { String id PK DateTime timestamp Int intervalInMinutes Decimal totalRevenue Decimal totalCashRevenue Decimal totalCardRevenue Int totalOrders Int averageCompletitionTime } CategoryStats { String id PK String categoryId FK String reportId FK Int itemsSold Decimal revenue } FoodStats { String id PK String foodId FK String reportId FK Int itemsSold Decimal revenue } UserStats { String id PK String userId FK String reportId FK Int ordersProcessed Decimal totalHandled } Category }o--o| Printer : "printerId" Food }o--|| Category : "categoryId" Food }o--o| Printer : "printerId" FoodIngredient }|--|| Food : "foodId" FoodIngredient }|--|| Ingredient : "ingredientId" Order }o--o| User : "userId" Order }o--o| CashRegister : "cashRegisterId" OrderItem }|--|| Order : "orderId" OrderItem }|--|| Food : "foodId" User }|--|| Role : "roleId" RefreshToken }|--|| User : "userId" CashRegister }o--o| Printer : "defaultPrinterId" CategoryStats }|--|| Category : "categoryId" CategoryStats }|--|| Report : "reportId" FoodStats }|--|| Food : "foodId" FoodStats }|--|| Report : "reportId" UserStats }|--|| User : "userId" UserStats }|--|| Report : "reportId"

Model reference

ModelTableDescription
CategorycategoriesGroups of foods. Each category can be linked to a specific printer for ticket routing.
FoodfoodsIndividual menu items. Belong to a category; can override the category printer.
IngredientingredientsA shared pool of ingredients.
FoodIngredientfood_ingredientsMany-to-many join between Food and Ingredient.

Orders

ModelTableDescription
OrderordersA customer order. Tracks table, customer name, payment method, totals, and status lifecycle.
OrderItemorder_itemsA line item inside an order. Stores the food, quantity, unit price, and optional notes.

Order status lifecycle

PENDING → CONFIRMED → COMPLETED → PICKED_UP
StatusMeaning
PENDINGOrder created, not yet confirmed by the cashier
CONFIRMEDPayment taken, ticket printed
COMPLETEDFood is ready for pickup
PICKED_UPCustomer collected the order

Users & authentication

ModelTableDescription
RolerolesNamed roles (e.g. admin, cashier). Controls API permissions.
UserusersOperator accounts. Each user has one role.
RefreshTokenrefresh_tokensJWT refresh tokens with expiry, revocation timestamp, and client metadata.

Hardware

ModelTableDescription
PrinterprintersESC/POS network printers (IP + port). Status tracked as ONLINE, OFFLINE, or ERROR. MAC address optional for identification.
CashRegistercash_registersNamed cash register stations. Each can have a default printer; orders are associated to a register.

Configuration & Reporting

ModelTableDescription
ApiKeyapi_keysMachine-to-machine authentication keys. Two types: PRINTER (prefix ms_pt_) and WEBAPP (prefix ms_wb_).
BannerbannersPromotional images for POS and customer screens. Type: EVENT (branding) or SPONSOR (logos).
OrderInstructionorder_instructionsInstructional text shown to cashiers during order creation, sorted by position.
ReportreportsAggregated sales statistics snapshots, grouped by time window (hourly, daily, or full-period). Linked to granular stats per category, food, and user.
CategoryStatscategory_statsPer-category sales metrics for a given report period. Tracks items sold and revenue by category.
FoodStatsfood_statsPer-food sales metrics for a given report period. Tracks items sold and revenue by menu item.
UserStatsuser_statsPer-operator performance metrics for a given report period. Tracks orders processed and total cash/card handled.
Last updated on