services:
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-supersunday}
      POSTGRES_USER: ${POSTGRES_USER:-supersunday}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-supersunday}
    volumes:
      - db_data:/var/lib/postgresql/data
      - ./db/init:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-supersunday} -d ${POSTGRES_DB:-supersunday}"]
      interval: 5s
      timeout: 5s
      retries: 20

  api:
    build: ./backend
    env_file: .env
    depends_on:
      db:
        condition: service_healthy
    expose:
      - "8080"
    healthcheck:
      test: ["CMD", "wget", "-qO-", "http://localhost:8080/api/health"]
      interval: 10s
      timeout: 5s
      retries: 20

  web:
    build: ./frontend
    depends_on:
      api:
        condition: service_healthy
    ports:
      - "80:80"
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://localhost/health || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 20

volumes:
  db_data: