Skip to main content

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
);
ColumnTypeConstraintsDescription
idINTEGERPRIMARY KEY AUTOINCREMENTAuto-generated role identifier
nombreTEXTUNIQUE NOT NULLHuman-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)
);
ColumnTypeConstraintsDescription
idINTEGERPRIMARY KEY AUTOINCREMENTAuto-generated user identifier
nombreTEXTNOT NULLDisplay name of the user
correoTEXTUNIQUE NOT NULLInstitutional email address (login credential)
passwordTEXTNOT NULLPlain-text password (stored as-is in the schema)
rol_idINTEGERFK references Roles.idDetermines 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
);
ColumnTypeConstraintsDescription
id_productoINTEGERPRIMARY KEY AUTOINCREMENTAuto-generated product identifier
nombreTEXTNOT NULLProduct name
precioREALNOT NULLUnit price in Mexican pesos
precioNivelTEXTNOT NULLPrice-range tier: $, $$, or $$$
descripcionTEXTOptional long-form product description
imagenTEXTURL of the product image
calificacionREALDEFAULT 0.0Stored default; overridden at query time by AVG (see below)
numResenasINTEGERDEFAULT 0Stored default; overridden at query time by COUNT (see below)
categoriaTEXTNOT NULLMenu 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
NombrePrecioNivelCategoria
Torta de Asada65.00$$comidas
Chilaquiles Rojos55.00$$comidas
Cafe Americano20.00$bebidas
Agua Fresca de Jamaica15.00$bebidas
Papas a la Francesa35.00$snacks
Galleta con Chispas15.00$snacks
Ensalada de Pollo75.00$$$sanas
Coctel de Frutas40.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)
);
ColumnTypeConstraintsDescription
idINTEGERPRIMARY KEY AUTOINCREMENTAuto-generated review identifier
usuario_idINTEGERNOT NULL, FK references UsuariosAuthor of the review
producto_idINTEGERNOT NULL, FK references ProductosProduct being reviewed
calificacionINTEGERNOT NULL, CHECK 1 to 5Star rating (1 = lowest, 5 = highest)
comentarioTEXTOptional free-text comment
fechaDATETIMEDEFAULT CURRENT_TIMESTAMPTimestamp set automatically at insertion
estadoTEXTDEFAULT ‘activa’Moderation status (see below)
estado values
ValueMeaning
'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.

Build docs developers (and LLMs) love