version: "3.9"

services:
  app:
    build:
      context: .
      dockerfile: docker/Dockerfile
    container_name: energy-monitor-app
    volumes:
      - .:/var/www/html
    env_file: .env
    depends_on:
      - mysql
      - redis
    networks: [energy-net]

  worker:
    build:
      context: .
      dockerfile: docker/Dockerfile
    container_name: energy-monitor-worker
    command: ["/usr/bin/supervisord", "-c", "/var/www/html/docker/supervisord.conf"]
    volumes:
      - .:/var/www/html
    env_file: .env
    depends_on:
      - mysql
      - redis
    ports:
      - "8080:8080" # Reverb websocket
    networks: [energy-net]

  nginx:
    image: nginx:1.27-alpine
    container_name: energy-monitor-nginx
    ports:
      - "80:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app
    networks: [energy-net]

  mysql:
    image: mysql:8.0
    container_name: energy-monitor-mysql
    environment:
      MYSQL_DATABASE: energy_monitor
      MYSQL_USER: energy_user
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: root_secret
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3306:3306"
    networks: [energy-net]

  redis:
    image: redis:7-alpine
    container_name: energy-monitor-redis
    ports:
      - "6379:6379"
    networks: [energy-net]

  mqtt-broker:
    image: eclipse-mosquitto:2
    container_name: energy-monitor-mqtt
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ./docker/mosquitto.conf:/mosquitto/config/mosquitto.conf
    networks: [energy-net]

  # Placeholder for the Python forecasting microservice (FastAPI + Prophet/
  # LSTM/XGBoost models). Build this as a separate repo/image and point
  # FORECAST_SERVICE_URL in .env at it; swap the `build` line for `image:`
  # once you have a published image.
  forecasting-service:
    build:
      context: ./forecasting-service
    container_name: energy-monitor-forecasting
    ports:
      - "8000:8000"
    networks: [energy-net]

networks:
  energy-net:
    driver: bridge

volumes:
  mysql_data:
