services:
  mysql:
    image: mysql:8.0
    container_name: eacadm-mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: eacadm
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_USER: eacadm
      MYSQL_PASSWORD: secret
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: eacadm-backend
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: eacadm
      DB_USERNAME: eacadm
      DB_PASSWORD: secret
      FRONTEND_URL: http://localhost:5173
    volumes:
      - ./backend:/var/www
      - /var/www/vendor
    depends_on:
      mysql:
        condition: service_healthy

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: eacadm-frontend
    restart: unless-stopped
    ports:
      - "5173:5173"
    environment:
      VITE_PROXY_TARGET: http://backend:8000
    volumes:
      - ./frontend:/app
      - /app/node_modules
    depends_on:
      - backend

volumes:
  mysql_data:
