# Compose file for Coolify deployments.
# In Coolify: create a "Docker Compose" resource pointing at this repo and set
# "Docker Compose Location" to /docker-compose.coolify.yml.
#
# No host ports are published here on purpose: Coolify's proxy routes the
# auto-assigned domains to the container ports declared via the
# SERVICE_FQDN_<SERVICE>_<PORT> magic variables, so ports never clash with
# other apps on the server. postgres and fuzzy-service stay private on the
# internal network. SERVICE_PASSWORD_* / SERVICE_BASE64_* values are
# generated by Coolify and editable in its UI.
#
# docker-compose.yml (with fixed host ports) remains for local development.

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-sig}
      POSTGRES_USER: ${POSTGRES_USER:-sig}
      POSTGRES_PASSWORD: ${SERVICE_PASSWORD_POSTGRES}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-sig} -d ${POSTGRES_DB:-sig}"]
      interval: 5s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  fuzzy-service:
    build:
      context: ./fuzzy-service
      dockerfile: Dockerfile
    restart: unless-stopped

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    environment:
      - SERVICE_FQDN_BACKEND_4000=/
      - PORT=4000
      - JWT_SECRET=${SERVICE_BASE64_64_JWT}
      - FRONTEND_URL=${SERVICE_URL_FRONTEND}
      - DATABASE_URL=postgres://${POSTGRES_USER:-sig}:${SERVICE_PASSWORD_POSTGRES}@postgres:5432/${POSTGRES_DB:-sig}
      - FUZZY_SERVICE_URL=http://fuzzy-service:5001
    depends_on:
      postgres:
        condition: service_healthy
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile.frontend
      args:
        # Baked into the browser bundle at build time; must be the backend's
        # public URL, which Coolify provides via the magic variable below.
        NEXT_PUBLIC_BACKEND_URL: ${SERVICE_URL_BACKEND}
        # Server-side rewrites go over the internal network.
        BACKEND_URL: http://backend:4000
    environment:
      - SERVICE_FQDN_FRONTEND_3000=/
    depends_on:
      - backend
    restart: unless-stopped

volumes:
  postgres_data:
