The database schema and business logic live in API/database/torma.sql.
Source of Truth
Use torma.sql as the canonical source for:
- table structure
- foreign key relationships
- stored procedures
- default seed data
Note
Additional notes in
API/docs/db-model.mdare useful context, but implementation details may differ from the active SQL dump.
Database Diagram
The database model diagram is included in the project documentation assets:
Core Tables
user: account-level data and profile fieldsuser_secret: credential material associated with usernamesproduct: catalog items and stock quantitiesorders: order header and shipping/billing fieldsorder_items: product lines belonging to ordersreservations: booking requests and schedule detailsrate_limits: counters used by API rate limiter
Relationships
orders.user_id -> user.idorder_items.orders_id -> orders.idorder_items.product_id -> product.idreservations.user_id -> user.iduser_secret.username -> user.username
These constraints enforce ownership and consistency across checkout and booking flows.
Stored Procedure Usage
Most write-heavy workflows are procedure-driven:
- user signup/login/profile credential updates
- order creation and order item changes
- reservation creation/update/deletion
- product and admin management operations
Business Rules in SQL
Important behavior is enforced at the database level:
- stock-aware order item operations
- subtotal and quantity consistency
- required-field checks in order creation
- reservation domain constraints (location/service/date rules)
- username collision handling during account creation
For application-level implications of these rules, see backend-api and security.