Refactor monolithic modules and harden booking, email, and auth infrastructure.
Split oversized frontend API client, email service, and admin/booking pages into focused modules while preserving import surfaces, and add Redis-backed queues, stale booking cleanup, stronger auth, and scale deployment configs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
# Example docker-compose for running the Spanglish API as multiple replicas
|
||||
# behind nginx, with Redis for shared state and Postgres as the database.
|
||||
#
|
||||
# This is a starting point, not a turnkey production setup. It expects a
|
||||
# Dockerfile at backend/Dockerfile that builds the API and runs it on PORT.
|
||||
#
|
||||
# Bring it up with N API replicas:
|
||||
# docker compose -f deploy/docker-compose.scale.yml up --build --scale api=3
|
||||
#
|
||||
# No em dashes are used in this file by design.
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_USER: spanglish
|
||||
POSTGRES_PASSWORD: spanglish
|
||||
POSTGRES_DB: spanglish
|
||||
# Raise max_connections if DB_POOL_MAX * replicas approaches the default 100.
|
||||
command: ["postgres", "-c", "max_connections=200"]
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U spanglish"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
command: ["redis-server", "--appendonly", "yes"]
|
||||
volumes:
|
||||
- redisdata:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
|
||||
api:
|
||||
build:
|
||||
context: ../backend
|
||||
environment:
|
||||
NODE_ENV: production
|
||||
PORT: "3001"
|
||||
DB_TYPE: postgres
|
||||
DATABASE_URL: postgresql://spanglish:spanglish@postgres:5432/spanglish
|
||||
DB_POOL_MAX: "15"
|
||||
REDIS_URL: redis://redis:6379
|
||||
JWT_SECRET: change-me-to-a-strong-secret
|
||||
FRONTEND_URL: http://localhost:8080
|
||||
# Optional S3-compatible storage so uploads are shared across replicas.
|
||||
# If you omit these, mount a shared volume at /app/uploads on every replica.
|
||||
# S3_ENDPOINT: http://garage:3900
|
||||
# S3_REGION: garage
|
||||
# S3_BUCKET: spanglish-media
|
||||
# S3_ACCESS_KEY_ID: ""
|
||||
# S3_SECRET_ACCESS_KEY: ""
|
||||
# S3_PUBLIC_URL: http://localhost:8080/media
|
||||
expose:
|
||||
- "3001"
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
redis:
|
||||
condition: service_healthy
|
||||
|
||||
# Load balancer across the scaled api replicas. nginx resolves the "api"
|
||||
# service name via Docker's embedded DNS, which round-robins across replicas.
|
||||
lb:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "8080:80"
|
||||
volumes:
|
||||
- ./nginx.scale.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
depends_on:
|
||||
- api
|
||||
|
||||
volumes:
|
||||
pgdata:
|
||||
redisdata:
|
||||
@@ -0,0 +1,29 @@
|
||||
# nginx load balancer for the scaled "api" service in docker-compose.scale.yml.
|
||||
# Uses Docker's embedded DNS resolver so newly scaled replicas are discovered
|
||||
# without editing a static upstream list.
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
# Docker embedded DNS. valid=10s re-resolves so scaling up/down is picked up.
|
||||
resolver 127.0.0.11 valid=10s;
|
||||
|
||||
location / {
|
||||
# Use a variable so nginx defers resolution to request time (round-robin
|
||||
# across all replicas of the "api" service).
|
||||
set $api_upstream http://api:3001;
|
||||
proxy_pass $api_upstream;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Server-Sent Events: do not buffer the payment status stream.
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
proxy_read_timeout 1h;
|
||||
proxy_set_header Connection "";
|
||||
proxy_http_version 1.1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user