Documentation Index
Fetch the complete documentation index at: https://mintlify.com/JuseAR27/Unisierra-eats/llms.txt
Use this file to discover all available pages before exploring further.
UniSierra Eats persists all data in a single SQLite file using four tables: Roles, Usuarios, Productos, and Resenas. Each table is created with CREATE TABLE IF NOT EXISTS, and foreign key constraints link users to roles, reviews to users, and reviews to products. The sections below document each table’s definition, its column semantics, and the relationships between them.
SQLite does not enforce foreign keys by default. UniSierra Eats explicitly runs PRAGMA foreign_keys = ON at the start of every database session — both in init_db.js and at server startup — so that referential integrity is applied at the engine level. Omitting this pragma would allow orphaned rows to be inserted without error.
Entity Relationships
The four tables form a straightforward star schema anchored by Resenas:
- Roles to Usuarios — One role can be assigned to many users (1:N). Every
Usuarios row carries a rol_id foreign key pointing to Roles.id.
- Usuarios to Resenas — One user can write many reviews (1:N). Every
Resenas row carries a usuario_id foreign key pointing to Usuarios.id.
- Productos to Resenas — One product can receive many reviews (1:N). Every
Resenas row carries a producto_id foreign key pointing to Productos.id_producto.
Tables
Roles
The Roles table defines the two permission levels available in the application: Administrador (id 1) and Estudiante (id 2). The nombre column carries a UNIQUE constraint so duplicate role names are rejected at the database level.
CREATE TABLE IF NOT EXISTS Roles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nombre TEXT UNIQUE NOT NULL
);
| Column | Type | Constraints | Description |
|---|
id | INTEGER | PRIMARY KEY AUTOINCREMENT | Auto-generated role identifier |
nombre | TEXT | UNIQUE NOT NULL | Human-readable role name |
Seed data
INSERT OR IGNORE INTO Roles (id, nombre) VALUES (1, 'Administrador'), (2, 'Estudiante');
Usuarios
The Usuarios table stores all registered accounts. The correo column has a UNIQUE constraint; the application layer additionally restricts registration to @unisierra.edu.mx addresses. The rol_id foreign key references Roles.id and determines what actions a user may perform inside the app.
CREATE TABLE IF NOT EXISTS Usuarios (
id INTEGER PRIMARY KEY AUTOINCREMENT,
nombre TEXT NOT NULL,
correo TEXT UNIQUE NOT NULL,
password TEXT NOT NULL,
rol_id INTEGER,
FOREIGN KEY (rol_id) REFERENCES Roles (id)
);
| Column | Type | Constraints | Description |
|---|
id | INTEGER | PRIMARY KEY AUTOINCREMENT | Auto-generated user identifier |
nombre | TEXT | NOT NULL | Display name of the user |
correo | TEXT | UNIQUE NOT NULL | Institutional email address (login credential) |
password | TEXT | NOT NULL | Plain-text password (stored as-is in the schema) |
rol_id | INTEGER | FK references Roles.id | Determines whether the user is an admin or student |
Seed data
INSERT OR IGNORE INTO Usuarios (id, nombre, correo, password, rol_id)
VALUES (1, 'Admin Principal', 'admin@unisierra.edu.mx', 'admin123', 1);
Productos
The Productos table holds every menu item offered in the cafeteria. Items are grouped into four categories (comidas, bebidas, snacks, sanas) and carry a precioNivel text indicator ($, $$, $$$) for quick price-range display in the UI.
CREATE TABLE IF NOT EXISTS Productos (
id_producto INTEGER PRIMARY KEY AUTOINCREMENT,
nombre TEXT NOT NULL,
precio REAL NOT NULL,
precioNivel TEXT NOT NULL,
descripcion TEXT,
imagen TEXT,
calificacion REAL DEFAULT 0.0,
numResenas INTEGER DEFAULT 0,
categoria TEXT NOT NULL
);
| Column | Type | Constraints | Description |
|---|
id_producto | INTEGER | PRIMARY KEY AUTOINCREMENT | Auto-generated product identifier |
nombre | TEXT | NOT NULL | Product name |
precio | REAL | NOT NULL | Unit price in Mexican pesos |
precioNivel | TEXT | NOT NULL | Price-range tier: $, $$, or $$$ |
descripcion | TEXT | — | Optional long-form product description |
imagen | TEXT | — | URL of the product image |
calificacion | REAL | DEFAULT 0.0 | Stored default; overridden at query time by AVG (see below) |
numResenas | INTEGER | DEFAULT 0 | Stored default; overridden at query time by COUNT (see below) |
categoria | TEXT | NOT NULL | Menu category: comidas, bebidas, snacks, or sanas |
Live rating computation
The calificacion and numResenas columns hold default values of 0.0 and 0 respectively. At query time, server.js overrides both with a LEFT JOIN against Resenas, computing the true average rating and review count on the fly:
SELECT p.*,
IFNULL(AVG(r.calificacion), 0) AS calificacion,
COUNT(r.id) AS numResenas
FROM Productos p
LEFT JOIN Resenas r ON p.id_producto = r.producto_id
GROUP BY p.id_producto;
This means the stored calificacion and numResenas values in the Productos table are never updated — they exist as schema defaults only. All meaningful rating data lives in Resenas.
Seed data — eight products across four categories
| Nombre | Precio | Nivel | Categoria |
|---|
| Torta de Asada | 65.00 | $$ | comidas |
| Chilaquiles Rojos | 55.00 | $$ | comidas |
| Cafe Americano | 20.00 | $ | bebidas |
| Agua Fresca de Jamaica | 15.00 | $ | bebidas |
| Papas a la Francesa | 35.00 | $ | snacks |
| Galleta con Chispas | 15.00 | $ | snacks |
| Ensalada de Pollo | 75.00 | $$$ | sanas |
| Coctel de Frutas | 40.00 | $ | sanas |
Resenas
The Resenas table stores every review submitted by a student. A CHECK constraint at the column level enforces that calificacion must be an integer between 1 and 5, inclusive. The estado column acts as a soft-moderation flag managed entirely through the API.
CREATE TABLE IF NOT EXISTS Resenas (
id INTEGER PRIMARY KEY AUTOINCREMENT,
usuario_id INTEGER NOT NULL,
producto_id INTEGER NOT NULL,
calificacion INTEGER NOT NULL CHECK(calificacion >= 1 AND calificacion <= 5),
comentario TEXT,
fecha DATETIME DEFAULT CURRENT_TIMESTAMP,
estado TEXT DEFAULT 'activa',
FOREIGN KEY (usuario_id) REFERENCES Usuarios (id),
FOREIGN KEY (producto_id) REFERENCES Productos (id_producto)
);
| Column | Type | Constraints | Description |
|---|
id | INTEGER | PRIMARY KEY AUTOINCREMENT | Auto-generated review identifier |
usuario_id | INTEGER | NOT NULL, FK references Usuarios | Author of the review |
producto_id | INTEGER | NOT NULL, FK references Productos | Product being reviewed |
calificacion | INTEGER | NOT NULL, CHECK 1 to 5 | Star rating (1 = lowest, 5 = highest) |
comentario | TEXT | — | Optional free-text comment |
fecha | DATETIME | DEFAULT CURRENT_TIMESTAMP | Timestamp set automatically at insertion |
estado | TEXT | DEFAULT ‘activa’ | Moderation status (see below) |
estado values
| Value | Meaning |
|---|
'activa' | The review is public and returned in all product and user review listings. |
'reportada' | The review has been flagged by another user. It is hidden from public listings and visible only to admins in the moderation panel. An admin can restore it to 'activa' or delete it permanently. |