services:
  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: mcbdl
      MYSQL_USER: mcbdl
      MYSQL_PASSWORD: mcbdlpass
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -proot"]
      interval: 5s
      timeout: 3s
      retries: 20

  backend:
    build:
      context: ./backend
    ports:
      - "4010:4010"
    environment:
      CORS_ORIGIN: http://localhost:5174
      DB_HOST: mysql
      DB_PORT: 3306
      DB_USER: mcbdl
      DB_PASSWORD: mcbdlpass
      DB_NAME: mcbdl
    volumes:
      - ./backend/data:/app/data
    depends_on:
      mysql:
        condition: service_healthy

  frontend:
    build:
      context: ./frontend
    ports:
      - "5174:5173"
    environment:
      VITE_PROXY_TARGET: http://backend:4010
      CHOKIDAR_USEPOLLING: "true"
    depends_on:
      - backend

volumes:
  mysql_data:
