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 is intentionally minimal in its configuration — there are no environment variable files, build pipelines, or external services to wire up. All runtime settings live directly in server.js, and the SQLite database is a single file created by init_db.js. This page explains every configuration point and how the pieces connect.

Project Directory Structure

After cloning the repository and running node init_db.js, the project layout looks like this:
Unisierra-eats/
├── server.js               # Express server + REST API
├── init_db.js              # Database initialization script
├── index.html              # Entry point (role-based redirect)
├── package.json
├── unisierra_eats.db       # Created by init_db.js
├── public/                 # Student-facing pages
│   ├── index.html
│   ├── menu.html
│   ├── busqueda.html
│   ├── detalle_producto.html
│   ├── escribir_resena.html
│   ├── perfil.html
│   ├── configuracion.html
│   └── js/app.js
├── admin/                  # Admin panel pages
│   ├── panel_admin.html
│   ├── moderacion.html
│   ├── reportes.html
│   └── js/admin.js
└── assets/
    └── css/styles.css
unisierra_eats.db does not exist in the repository — it is generated the first time you run node init_db.js. If you delete it, re-running init_db.js will recreate it with fresh seed data.

Server Configuration

All server settings are defined at the top of server.js. There are three key configuration points:

Port

const PORT = 3000;
To run the server on a different port, change the value of the PORT constant at the top of server.js. For example, set const PORT = 8080 to serve on port 8080. No other changes are needed.

Database Path

The SQLite connection is opened with a path relative to the project root:
const db = new sqlite3.Database('./unisierra_eats.db', (err) => {
    if (err) {
        console.error('Error al conectar con la base de datos:', err.message);
    } else {
        console.log('Servidor conectado a la base de datos SQLite.');
    }
});
The path ./unisierra_eats.db is resolved relative to the directory from which you run node server.js. To use a different file location, update this string — for example, './data/unisierra_eats.db' — making sure the target directory exists before starting the server.

Static File Serving

app.use(express.static(__dirname)); // Servir archivos estáticos del frontend
The server uses __dirname as the static root, which means the entire project directory is served as public static files. All HTML pages in public/ and admin/ are accessible directly at their file paths — for example, http://localhost:3000/public/menu.html and http://localhost:3000/admin/panel_admin.html — with no separate web server or proxy required.

JSON Middleware

app.use(express.json()); // Entender formato JSON
This middleware parses incoming request bodies with a Content-Type: application/json header and makes the parsed object available at req.body. All POST and PUT API endpoints expect JSON-formatted request bodies.

Full Server Bootstrap Sequence

Putting it all together, here is how server.js initializes on startup:
const express = require('express');
const path = require('path');
const sqlite3 = require('sqlite3').verbose();

const app = express();
const PORT = 3000;

app.use(express.json());
app.use(express.static(__dirname));

const db = new sqlite3.Database('./unisierra_eats.db', (err) => {
    if (err) {
        console.error('Error al conectar con la base de datos:', err.message);
    } else {
        console.log('Servidor conectado a la base de datos SQLite.');
    }
});

// ... route definitions ...

app.listen(PORT, () => {
    console.log(`Servidor de UniSierra Eats corriendo en http://localhost:${PORT}`);
});

Database Initialization and Foreign Keys

The init_db.js script runs all CREATE TABLE statements inside a db.serialize() block to guarantee sequential execution. The first statement it runs is:
db.run("PRAGMA foreign_keys = ON;");
This enables SQLite’s foreign key enforcement, which is disabled by default in SQLite. With it active, the database will reject inserts or updates that violate referential integrity — for example, creating a Resenas row that references a non-existent usuario_id or producto_id. The four tables created by the script and their relationships are:
Roles (id, nombre)
  └─ Usuarios (id, nombre, correo, password, rol_id -> Roles.id)
       └─ Resenas (id, usuario_id -> Usuarios.id, producto_id -> Productos.id_producto, ...)
Productos (id_producto, nombre, precio, precioNivel, descripcion, imagen, categoria)
       └─ Resenas.producto_id -> Productos.id_producto
The Resenas table also enforces a check constraint on the calificacion column to ensure ratings are always between 1 and 5:
calificacion INTEGER NOT NULL CHECK(calificacion >= 1 AND calificacion <= 5)
Review rows carry a estado column (defaulting to 'activa') that powers the moderation workflow: students can report a review (setting it to 'reportada'), and administrators can approve it (resetting it to 'activa') or delete it permanently from the admin panel.

Default Seed Data

Running node init_db.js populates the database with the following initial records using INSERT OR IGNORE, so re-running the script never duplicates data. Roles seeded:
idnombre
1Administrador
2Estudiante
Default administrator account:
FieldValue
correoadmin@unisierra.edu.mx
passwordadmin123
rol_id1
Passwords are stored in plaintext — there is no hashing or encryption. The admin123 default credential is intentionally simple for local development. Never deploy this application with real credentials or in a public environment without adding proper password hashing.
The script also seeds 8 sample products across four categories (comidas, bebidas, snacks, sanas) so the menu is populated immediately after initialization.

Build docs developers (and LLMs) love