Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuanSerna14/Final-lenguaje-Avanzado/llms.txt

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

The PitchPro backend is an Express + TypeScript REST API located in the arquimarket/ directory. It handles court management, reservations, and JWT-based authentication, with PostgreSQL as its data store and automatic schema initialization on every startup.

Prerequisites

RequirementVersion
Node.js18 or later
npmBundled with Node.js 18+
PostgreSQL14 or later (or Docker with a Postgres image)

Installation

2
cd arquimarket/
3
Install dependencies
4
npm
npm install
yarn
yarn install
5
This installs all runtime and dev dependencies, including express, pg, jsonwebtoken, bcryptjs, zod, swagger-ui-express, and TypeScript tooling.
6
Create the .env file
7
Create a .env file in the arquimarket/ root with the following variables:
8
# Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=arquimarket
DB_USER=arquiuser
DB_PASSWORD=arquipass

# API
PORT=8000
NODE_ENV=development
9
See the Configuration page for a full description of every variable.
10
Start the development server
11
npm run dev
12
This runs ts-node src/main.ts, which initializes the database schema and starts listening. You should see:
13
✅ Tablas "canchas", "reservas" y "users" verificadas/creadas.
🚀 Servidor corriendo en http://localhost:8000
📝 Documentación disponible en http://localhost:8000/docs

Available Scripts

ScriptCommandDescription
devts-node src/main.tsStart the development server with live TypeScript execution
seedts-node src/db/seed.tsPopulate the database with 20 sample courts and 20 reservations
buildtscCompile TypeScript to JavaScript in dist/
startnode dist/main.jsRun the compiled production build

Seed Data

Run the seed script to populate the database with realistic sample data for development and testing:
npm run seed
The script is idempotent — it checks the existing row count in each table before inserting. If records already exist, it skips that table and logs a message instead of duplicating data. What gets inserted:
  • 20 canchas — courts named Cancha 1 through Cancha 20, each with a synthetic grass description and a precio_hora that cycles through values between 30.00 and 55.00:
{
  "nombre": "Cancha 5",
  "descripcion": "Cancha de prueba número 5 — césped sintético, iluminación.",
  "precio_hora": "50.00",
  "activa": true
}
  • 20 reservas — reservations randomly distributed across the next 30 days, assigned to existing court IDs, with randomized estado (pendiente, confirmada, cancelada) and origen (whatsapp, interfaz).
Both sets of inserts run inside a PostgreSQL transaction — if any row fails, the entire batch is rolled back.
Run npm run seed only after starting the server at least once, so initDatabase() has had a chance to create the tables.

Swagger UI

Once the server is running, interactive API documentation is available at:
http://localhost:8000/docs
The Swagger UI is mounted via swagger-ui-express and covers all endpoints in the auth, canchas, and reservas modules.

Project Structure

arquimarket/
└── src/
    ├── main.ts                   # App entry point — wires Express, routes, Swagger
    ├── swagger.ts                # OpenAPI spec (inline)
    ├── db/
    │   ├── connection.ts         # pg Pool instance (shared across modules)
    │   ├── init.ts               # CREATE TABLE IF NOT EXISTS for all three tables
    │   └── seed.ts               # Seed script for development data
    ├── middlewares/
    │   └── verifyToken.ts        # JWT Bearer token guard
    └── modules/
        ├── auth/
        │   ├── auth.controller.ts   # /api/auth routes (register, login, refresh, logout, me)
        │   └── auth.validator.ts    # express-validator rules
        ├── canchas/
        │   ├── canchas.controller.ts  # /api/canchas routes
        │   ├── canchas.service.ts     # Business logic + CanchaNoEncontradaError
        │   ├── canchas.repository.ts  # SQL queries via pg pool
        │   └── canchas.types.ts       # Zod schema + TypeScript interfaces
        └── reservas/
            ├── reservas.controller.ts  # /api/reservas routes
            ├── reservas.repository.ts  # SQL queries + overlap detection
            └── reservas.types.ts       # Zod schema + TypeScript interfaces

Database Schema

Explore the three-table PostgreSQL schema and connection pool setup.

Authentication

Understand the JWT dual-token strategy and all auth endpoints.

Configuration

Full reference for every environment variable.

API Overview

Browse the full REST API endpoint reference.

Build docs developers (and LLMs) love