Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/scoria02/marbes2021_backend/llms.txt

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

Marbes Backend ships with multiple Docker Compose configurations that cover different deployment scenarios. The standard docker-compose.yml attaches the backend to pre-existing external networks shared with a frontend and database layer. The docker-compose.prod.yml spins up a self-contained production stack that includes PostgreSQL, Redis, Nginx, and an optional automated backup service. This page covers both paths and documents every environment variable the application reads.

Prerequisites

  • Docker Engine 24+ and Docker Compose V2
  • pnpm is used as the package manager inside the image — no local install needed
  • A .env file populated from env.example (see Environment variables below)

Deployment options

Standard deployment (external networks)

Use this when the backend joins an existing Docker network topology — for example, when a frontend, database, and backend are each managed by separate Compose files. The backend container expects three external networks to already exist before it starts:
NetworkPurpose
marbes_frontend_netCommunication with the frontend service
marbes_backend_netInternal backend traffic
marbes_db_netAccess to the PostgreSQL database
Create the networks once before your first deploy:
docker network create marbes_frontend_net
docker network create marbes_backend_net
docker network create marbes_db_net

Production deployment (self-contained stack)

docker-compose.prod.yml brings up all services in one command. It includes:
  • PostgreSQL 16 (Alpine) with a health check
  • Redis 7 (Alpine) with a health check
  • Backend API — starts only after both database services are healthy
  • Nginx reverse proxy on ports 80 and 443
  • Backup service (opt-in via the backup profile)

Deploy the backend

1

Copy and configure environment variables

Copy the example file and fill in your values:
cp env.example .env
At minimum, set the database credentials and a strong JWT secret before continuing. See Environment variables for the full list.
Never commit .env to version control. The file contains secrets that must stay out of your repository.
2

Choose your Compose file and start

Run one of the following commands depending on your scenario:
# Foreground — useful for verifying the first boot
pnpm docker:dev

# Detached (background)
pnpm docker:dev:detached
3

Verify the deployment

Once the container is running, hit the health endpoint to confirm the API is accepting requests:
curl http://localhost:7780/api/health
Expected response:
{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00.000Z",
  "uptime": 12.5,
  "environment": "production",
  "version": "1.0.0"
}
The Docker health check in both the Dockerfile and docker-compose.prod.yml calls this same endpoint every 30 seconds. A container that fails three consecutive checks will be marked unhealthy.
4

Tail the logs

# Backend logs only
pnpm docker:logs

# All services (prod stack)
pnpm docker:logs:all

Available Docker commands

All commands below are defined in package.json and run with pnpm <command>:
CommandDescription
docker:buildBuild the Docker image and tag it marbes-backend
docker:runRun a standalone container on port 7780 using .env
docker:backendStart the backend-only Compose file in the foreground
docker:backend:detachedStart the backend-only Compose file in the background
docker:backend:downStop and remove the backend-only Compose services
docker:backend:logsTail logs from the backend-only container
docker:backend:restartRestart the backend service
docker:backend:shellOpen a shell inside the backend container
docker:devStart the default docker-compose.yml in the foreground
docker:dev:detachedStart the default docker-compose.yml in the background
docker:prodStart the production stack in the foreground
docker:prod:detachedStart the production stack in the background
docker:downStop and remove the default Compose services
docker:down:volumesStop services and delete all named volumes
docker:logsTail backend service logs
docker:logs:allTail logs for all services
docker:shellOpen a shell inside the backend container
docker:dbOpen a psql session inside the Postgres container
docker:cleanPrune unused images, containers, and volumes
docker:resetFull teardown: stop, remove volumes, and prune Docker

Environment variables

Copy env.example to .env and set the following variables. Variables marked required will cause the application to fail to start or behave incorrectly if left at their default values in production.

General

VariableDefaultRequiredDescription
NODE_ENVdevelopmentYesSet to production in production deployments
PORT7780NoPort the HTTP server listens on

PostgreSQL

VariableDefaultRequiredDescription
DB_HOSTlocalhostYesHostname or container name of the PostgreSQL server
DB_PORT5432NoPostgreSQL port
DB_NAMEmarbes_dbYesDatabase name
DB_USERmarbes_userYesDatabase user
DB_PASSWORDmarbes_passwordYesDatabase password — change this before deploying
DB_SSLfalseNoEnable SSL for the database connection

Redis

VariableDefaultRequiredDescription
REDIS_HOSTlocalhostNoRedis hostname or container name
REDIS_PORT6379NoRedis port
REDIS_PASSWORD(empty)NoRedis password if authentication is enabled

JWT

VariableDefaultRequiredDescription
JWT_SECRET(placeholder)YesSecret key used to sign and verify tokens
JWT_EXPIRES_IN24hNoExpiry duration for issued tokens (note: the auth service issues tokens with a 12 h hard-coded expiry)
JWT_REFRESH_EXPIRES_IN7dNoExpiry duration for refresh tokens
JWT_SECRET must be a long, random string in production. Any deployment using the placeholder value from env.example is critically insecure — tokens could be forged by anyone who knows the default value.

CORS and Socket.IO

VariableDefaultRequiredDescription
CORS_ORIGINhttp://localhost:3000YesAllowed origin for CORS requests
CORS_CREDENTIALStrueNoWhether credentials are included in CORS requests
SOCKET_CORS_ORIGINhttp://localhost:3000YesAllowed origin for Socket.IO connections

File uploads

VariableDefaultRequiredDescription
UPLOAD_PATH./uploadsNoDirectory where uploaded files are stored
MAX_FILE_SIZE10485760NoMaximum upload size in bytes (default: 10 MB)
VariableDefaultRequiredDescription
FRONTEND_URLhttp://localhost:3000YesBase URL of the frontend — used to construct links sent to clients
SOLICITUD_CREDITO_EXPIRA_HORAS72NoHow many hours a credit application link remains valid

Security

VariableDefaultRequiredDescription
BCRYPT_ROUNDS12NoCost factor for password hashing
RATE_LIMIT_WINDOW_MS900000NoRate-limiting window in milliseconds (default: 15 min)
RATE_LIMIT_MAX_REQUESTS100NoMaximum requests per window per IP

Logs

VariableDefaultRequiredDescription
LOG_LEVELinfoNoLog verbosity level
LOG_FILE_PATH./logs/app.logNoPath to the log file

Network architecture

The standard docker-compose.yml connects the backend container to three external networks. These networks must be created independently and are shared across services managed by other Compose files.
[ Frontend container ] ── marbes_frontend_net ──┐

                                          [ Backend container ]

[ PostgreSQL container ] ── marbes_db_net ────────┘

          └── marbes_backend_net (internal backend traffic)
The production Compose file (docker-compose.prod.yml) uses an isolated bridge network (marbes_network_prod, subnet 172.21.0.0/16) — all services communicate internally and only Nginx exposes ports 80 and 443 to the host.

Port mapping

Host portContainer portService
77807780Backend API (standard deployment)
8080Nginx (production stack)
443443Nginx TLS (production stack)

Health check endpoint

GET /api/health is unauthenticated and used by Docker, load balancers, and monitoring tools to verify the API is up.
curl http://localhost:7780/api/health
{
  "status": "healthy",
  "timestamp": "2024-01-15T10:30:00.000Z",
  "uptime": 3600.42,
  "environment": "production",
  "version": "1.0.0"
}
FieldTypeDescription
statusstringAlways "healthy" when the process is running
timestampstringISO 8601 timestamp of the response
uptimenumberProcess uptime in seconds
environmentstringValue of NODE_ENV
versionstringValue of npm_package_version from package.json

Build docs developers (and LLMs) love