services:
  db:
    image: mysql:8
    container_name: eni-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: supersecret
      MYSQL_DATABASE: eni_db
      MYSQL_USER: eni
      MYSQL_PASSWORD: enisecret
      LANG: en_US.UTF-8
      LC_ALL: en_US.UTF-8
    ports:
      - "3307:3306"
    volumes:
      - db_data:/var/lib/mysql
      - ./backend/backup.sql:/docker-entrypoint-initdb.d/backup.sql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
    container_name: eni-backend
    ports:
      - "5000:5000"
    env_file:
      - ./backend/.env
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
    container_name: eni-frontend
    ports:
      - "3000:3000"
    env_file:
      - ./frontend/.env
    depends_on:
      - backend
    restart: unless-stopped

volumes:
  db_data:
