services:
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
      args:
        UID: ${UID:-1000}
        GID: ${GID:-1000}
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      APP_URL: http://localhost:8080
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: life_analytics
      DB_USERNAME: laravel
      DB_PASSWORD: secret
      CACHE_STORE: database
      QUEUE_CONNECTION: database
      SESSION_DRIVER: database
    volumes:
      - ./:/var/www/html
      - composer_vendor:/var/www/html/vendor
      - composer_cache:/tmp/composer-cache
    depends_on:
      mysql:
        condition: service_healthy
    restart: unless-stopped

  web:
    image: nginx:1.29-alpine
    ports:
      - "8080:80"
    volumes:
      - ./:/var/www/html:ro
      - composer_vendor:/var/www/html/vendor:ro
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - app
    restart: unless-stopped

  node:
    image: node:24-alpine
    working_dir: /var/www/html
    command: sh -c "npm install && npm run dev -- --host 0.0.0.0"
    ports:
      - "5173:5173"
    volumes:
      - ./:/var/www/html
      - node_modules:/var/www/html/node_modules
    environment:
      CHOKIDAR_USEPOLLING: "true"
      VITE_APP_NAME: Life Analytics
    restart: unless-stopped

  mysql:
    image: mysql:8.4
    ports:
      - "3307:3306"
    environment:
      MYSQL_DATABASE: life_analytics
      MYSQL_USER: laravel
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-proot"]
      interval: 5s
      timeout: 3s
      retries: 20
    restart: unless-stopped

volumes:
  composer_vendor:
  composer_cache:
  node_modules:
  mysql_data:
