Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sheeplettuce/Monitor/llms.txt

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

This guide walks you from a fresh checkout to a running Monitor API server with a verified authenticated request. By the end you will have the server listening on port 3000, a JWT token in hand, and a successful response from GET /api/expedientes.
1

Prerequisites

Make sure the following are installed and running before you begin:
RequirementMinimum VersionNotes
Node.js18LTS recommended
pnpm11.5Enforced by devEngines in package.json
PostgreSQL14+Must be accessible from your machine
Verify your versions:
node --version   # v18.x.x or higher
pnpm --version   # 11.5.x or higher
psql --version   # psql (PostgreSQL) 14.x or higher
Create an empty PostgreSQL database for Monitor before continuing:
createdb monitor
2

Clone and Install

Clone the repository and install dependencies with pnpm:
git clone https://github.com/sheeplettuce/Monitor.git
cd Monitor
pnpm install
pnpm will install all runtime and dev dependencies declared in package.json, including Express 5, Prisma, bonjour-service, jsonwebtoken, and multer.
3

Configure Environment

Create a .env file at the project root with the following content. All variables are loaded at startup via dotenv/config.
# .env
DATABASE_URL="postgresql://user:password@localhost:5432/monitor"
JWT_SECRET="change-me-to-a-long-random-string"
EVIDENCIAS_DIR="../evidencias"
Replace user, password, and monitor with your actual PostgreSQL credentials and database name. See Configuration for a full description of every variable.Next, apply the Prisma schema to your database to create all tables:
pnpm prisma migrate deploy
During initial development you can also use pnpm prisma db push to sync the schema without creating a migration history. Use migrate deploy for production and CI environments.
4

Start the Server

Run the development server with hot-reload via tsx watch:
pnpm dev
Before binding to port 3000, the server runs seedAseguradoras() to upsert the three built-in insurers (AXA, HDI, Qualitas) into the database. Once that completes, you will see output similar to the following in your terminal:
<timestamp> [Backend] [SUCCESS] Servidor iniciado
  → {
  "puerto": 3000
}
<timestamp> [Red] [INFO] Servicio mDNS anunciado
  → {
  "tipo": "_monitor._tcp"
}
<timestamp> [Red] [INFO] IP local
  → {
  "ip": "192.168.1.42"
}
<timestamp> [Red] [INFO] Nombre del servidor
  → {
  "hostname": "mi-mac",
  "dns": "mi-mac.local"
}
<timestamp> [Sistema] [INFO] ══════════ Iniciando verificación de estado ══════════
<timestamp> [Sistema] [INFO] ══════════ Verificación completada ══════════
The server binds to 0.0.0.0:3000 and advertises itself on the local network via mDNS. Status checks run immediately at startup and repeat every five minutes.
5

Authenticate

Obtain a JWT token by posting credentials to /api/auth/login:
curl -s -X POST http://localhost:3000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "your-password"}'
A successful response returns the token and basic user information:
{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "usuario": {
    "id": 1,
    "nombre": "Administrador",
    "username": "admin",
    "rol": "Administrador"
  }
}
Copy the token value — you will pass it as a Bearer token in all subsequent requests. Tokens expire after 8 hours.
The rol field will be one of Administrador, Operador, or Técnico. Different roles have access to different routes. Refer to Authentication & Roles for the full permission matrix.
6

Make Your First API Call

Use the token from the previous step to fetch the list of expedientes:
curl -s http://localhost:3000/api/expedientes \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
The response returns an array of expediente objects, each identified by its no_siniestro claim number and including vehicle details, current estado, assigned personnel, and related document flags.A successful response looks like:
[
  {
    "no_siniestro": "SIN-2025-001",
    "vehiculo": "Toyota Corolla",
    "marca": "Toyota",
    "modelo": "2022",
    "placas": "ABC-123",
    "estado": "Ingreso",
    "nombre_cliente": "Juan Pérez",
    "fecha_ingreso": "2025-07-10"
  }
]
You’re all set. Explore the rest of the API with the same Bearer token.
Not sure what IP address the server is running on? Hit the /discovery endpoint from any machine on the same LAN:
curl http://monitor-server.local:3000/discovery
{
  "nombre": "Monitor API",
  "ips": ["192.168.1.42"]
}
This endpoint requires no authentication and returns all non-loopback IPv4 addresses the server is bound to. It’s useful for configuring frontend apps and mobile clients that need to locate the API dynamically. The same information is also published over mDNS as the _monitor._tcp service, discoverable by Bonjour-compatible clients without hitting any HTTP endpoint.

Build for Production

When you’re ready to deploy, compile the TypeScript source to JavaScript and run the compiled output directly with Node:
# Compile TypeScript → dist/
pnpm build

# Run the compiled server
pnpm start
pnpm build invokes tsc, which outputs ES2022 JavaScript modules to dist/ per the settings in tsconfig.json. pnpm start then runs node dist/server.js — no tsx or TypeScript tooling required at runtime. Make sure your production environment has DATABASE_URL and JWT_SECRET set before running pnpm start. See Configuration for all available options.

Build docs developers (and LLMs) love