services:
  db:
    image: postgres:16
    container_name: supersunday_db
    environment:
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: supersunday
    volumes:
      - ./data/db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres -d supersunday -h localhost"]
      interval: 5s
      timeout: 3s
      retries: 20
      start_period: 10s

  api:
    build: ./backend
    container_name: supersunday_api
    env_file:
      - ./backend/.env
    depends_on:
      db:
        condition: service_healthy
    expose:
      - "4000"
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost:4000/api/health || exit 1"]
      interval: 10s
      timeout: 3s
      retries: 12
      start_period: 30s

  web:
    image: nginx:alpine
    container_name: supersunday_web
    depends_on:
      api:
        condition: service_healthy
    ports:
      - "80:80"         # Tout le trafic arrive sur Nginx
    volumes:
      - ./frontend/public:/usr/share/nginx/html:ro
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
