For: Full Stack · Backend API

Data model

The database tables and how they relate.

The schema is prisma/schema.prisma. After changing it, run npx prisma db push (applies it to the database) and npx prisma generate (updates the code).

Category 1 ── * MenuItem 1 ── * OptionGroup 1 ── * Option
Order 1 ── * OrderItem          (copies of names, prices and options at order time)
Order 1 ── * OrderEvent         (status history: who, when, note)
Reservation                     (table requests)
StaffUser                       (dashboard accounts)
Setting                         (one row, id = 1)
Table Main fields
Setting names, taglines, addresses (Arabic and English), phone, WhatsApp, map link, currency and decimals, tax %, delivery fee, minimum order, enabled order types and payment methods, acceptingOrders, hours (JSON)
Category slug, nameAr, nameEn, sort, active
MenuItem slug, category, names and descriptions, price, image, calories, prepMinutes, tags (JSON), available, featured, sort
OptionGroup dish, names, required, maxSelect, sort
Option group, names, priceDelta
Order code (public), status, type, customer name, phone, address, table, notes, subtotal, deliveryFee, tax, total, paymentMethod, paymentStatus, paymentRef (Thawani session), locale
OrderItem names in both languages, unitPrice, quantity, options (JSON copy), note, lineTotal
OrderEvent status, by (staff name, customer, thawani or system), note, at
Reservation code, name, phone, people, date (YYYY-MM-DD), time (HH:MM), notes, status
StaffUser name, email, passwordHash (scrypt), role (OWNER / STAFF), active

Rules worth knowing

  • Money is always an integer in the smallest unit; never store decimals.
  • Orders copy what they sold. Changing or deleting a dish never changes past orders or reports.
  • Order codes are random (SF-XXXX-XXXX, letters and digits without look-alikes such as 0/O and 1/I), so customers cannot guess other orders.
  • The order flow is enforced on the server by src/lib/rules.ts; the dashboard only shows allowed moves.
  • Opening hours are checked in RESTAURANT_TIMEZONE, and a closing time earlier than the opening time runs past midnight.

The pure rules (pricing, statuses, hours, codes) have unit tests in tests/ (npm test).