Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/123048152-JJDS/CafeteriaPM_S203/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through running the CafeteriaPM API on your local machine from a fresh clone. By the end you will have a fully seeded database, a running FastAPI server, and a valid JWT token you can use to call any endpoint.
1

Clone and configure

Clone the repository and copy the example environment file to create your local configuration:
git clone https://github.com/your-org/CafeteriaPM_S203.git
cd CafeteriaPM_S203
cp api/.env.example api/.env
The .env.example ships with safe placeholder values:
# ── Base de datos PostgreSQL ────────────────────────────────────
DB_HOST=localhost
DB_USER=cafeteria_user
DB_PASSWORD=cafeteria_pass
DB_NAME=cafeteria_db
DB_PORT=5432

# ── JWT ──────────────────────────────────────────────────────
SECRET_KEY=cambia_esto_por_una_clave_segura_minimo_32_chars
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=480

# ── App ──────────────────────────────────────────────────────
APP_NAME=CafeteriaPM API
APP_VERSION=1.0.0
ENVIRONMENT=development
DEBUG=True
Replace SECRET_KEY with a randomly generated string of at least 32 characters before deploying to any environment beyond your local machine. The placeholder value above must never be used in production.
Update DB_HOST, DB_USER, DB_PASSWORD, and DB_NAME to match your local PostgreSQL instance, then save the file as api/.env.
2

Install Python dependencies

Navigate to the api directory and install all required packages:
cd api
pip install -r requirements.txt
The key dependencies pinned in requirements.txt are:
PackageVersionPurpose
fastapi0.111.0Web framework and OpenAPI generation
sqlalchemy2.0.30ORM and database connection management
pydantic2.7.1Request/response schema validation
uvicorn0.29.0ASGI server
passlib1.7.4Password hashing (bcrypt backend)
python-jose3.3.0JWT creation and verification
reportlab4.2.0PDF report generation
openpyxl3.1.2Excel report generation
psycopg2-binary2.9.9PostgreSQL driver
python-decouple3.8.env file loading
3

Initialize the database

With your PostgreSQL server running and api/.env configured, run the two initialisation scripts from inside the api directory:
python scripts/init_db.py
python scripts/seed_all.py
init_db.py executes the bundled SQL schema file (sql/CafeteriaPM_S203.sql) which creates all tables, constraints, and indexes in your database.seed_all.py then orchestrates the full seeding sequence by running each seed script in order:
  1. init_db.py — schema creation (re-run as a safety step)
  2. seed_admin.py — creates the four roles (admin, cocina, caja, mesero) and the default administrator account
  3. seed_estados.py — populates order states and payment methods
  4. seed_productos.py — loads a sample product catalogue with categories and ingredients
  5. seed_demo_data.py — inserts demonstration orders, sales, and expense records
After seeding, a default admin account is ready to use:
FieldValue
Email[email protected]
PasswordAdmin123!
Change the default admin password immediately after your first login in any shared or production environment.
4

Start the API server

Launch the API with uvicorn from inside the api directory:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
The --reload flag watches for source file changes and restarts the server automatically, which is useful during development. Once the server is running you can access:The health check endpoint returns:
{
  "app": "CafeteriaPM API",
  "version": "1.0.0",
  "status": "ok",
  "docs": "/docs"
}
5

Authenticate and make your first call

Exchange the seeded admin credentials for a JWT access token:
# Login
curl -X POST http://localhost:8000/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "[email protected]", "password": "Admin123!"}'
A successful response returns the token alongside the user’s identity and role:
{
  "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user_id": 1,
  "nombre": "Admin",
  "rol": "admin"
}
Copy the access_token value and use it as a Bearer token to call any protected endpoint. For example, to list all products:
# List products
curl http://localhost:8000/productos/ \
  -H "Authorization: Bearer <access_token>"
Replace <access_token> with the full token string returned by the login call. Tokens are valid for 480 minutes (8 hours) by default, controlled by ACCESS_TOKEN_EXPIRE_MINUTES in your .env file.
For a full breakdown of the login endpoint, token refresh behaviour, and role-based access control, see the Authentication reference.

Build docs developers (and LLMs) love