services:
  nextjs:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: schoolcompare-nextjs
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-http://backend:8000/api}
      - FASTAPI_URL=${FASTAPI_URL:-http://backend:8000/api}
    depends_on:
      - backend
    networks:
      - schoolcompare-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "node", "-e", "require('http').get('http://localhost:3000/', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  backend:
    image: schoolcompare-backend:latest
    container_name: schoolcompare-backend
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=${DATABASE_URL}
      - PYTHONUNBUFFERED=1
    networks:
      - schoolcompare-network
    restart: unless-stopped

networks:
  schoolcompare-network:
    driver: bridge
