version: "3.8"

services:
  postgres:
    image: postgres:16
    environment:
      POSTGRES_DB: datanexus
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 3s
      timeout: 3s
      retries: 10

  backend:
    build: ./backend
    ports:
      - "8000:8000"
    environment:
      DATANEXUS_DATABASE_URL: postgresql+asyncpg://postgres:postgres@postgres:5432/datanexus
      DATANEXUS_SECRET_KEY: change-me-in-production
      DATANEXUS_AES_KEY: change-me-16bytes-key
      DATANEXUS_DEBUG: true
      DATANEXUS_MAX_QUERY_ROWS: 1000
    depends_on:
      postgres:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 5s
      timeout: 3s
      retries: 12

  frontend:
    build:
      context: ./frontend
      args:
        VITE_API_BASE_URL: ${VITE_API_BASE_URL:-/api/v1}
    ports:
      - "8088:80"
    depends_on:
      backend:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost/health"]
      interval: 5s
      timeout: 3s
      retries: 12

volumes:
  pgdata: