services:
  # --------------------------------------------------
  # PHP / Laravel App (PHP-FPM)
  # --------------------------------------------------
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile.dev
    container_name: opensource
    working_dir: /var/www
    volumes:
      - .:/var/www
    depends_on:
      - mysql
      - redis
    networks:
      - opensource

  # --------------------------------------------------
  # Nginx Web Server
  # --------------------------------------------------
  nginx:
    image: nginx:alpine
    container_name: opensource_nginx
    ports:
      - "8080:80"
    volumes:
      - .:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app
    networks:
      - opensource

  # --------------------------------------------------
  # Redis Cache & Pub/Sub
  # --------------------------------------------------
  redis:
    image: redis:alpine
    container_name: opensource_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - opensource
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5

  # --------------------------------------------------
  # Laravel Scheduler
  # --------------------------------------------------
  scheduler:
    build:
      context: .
      dockerfile: docker/php/Dockerfile.dev
    container_name: opensource_scheduler
    working_dir: /var/www
    command: php artisan schedule:work --interval=60
    volumes:
      - .:/var/www
    depends_on:
      - app
      - mysql
      - redis
    networks:
      - opensource

  worker:
    build:
      context: .
      dockerfile: docker/php/Dockerfile.dev
    container_name: opensource_worker
    working_dir: /var/www
    command: php artisan queue:work --tries=3 --timeout=90 --sleep=3
    volumes:
      - .:/var/www
    depends_on:
      - app
      - mysql
      - redis
    networks:
      - opensource

  # --------------------------------------------------
  # MySQL Database
  # --------------------------------------------------
  mysql:
    image: mysql:8.0
    container_name: opensource_mysql
    environment:
      MYSQL_DATABASE: opensource
      MYSQL_ROOT_PASSWORD: root
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - opensource

  # --------------------------------------------------
  # phpMyAdmin
  # --------------------------------------------------
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: opensource_pma
    links:
      - mysql:db
    ports:
      - "8081:80"
    environment:
      PMA_HOST: mysql
      PMA_ARBITRARY: 1
    depends_on:
      - mysql
    networks:
      - opensource

  # --------------------------------------------------
  # Kafka
  # --------------------------------------------------
  # kafka:
  #   image: bitnami/kafka:latest
  #   container_name: kafka
  #   ports:
  #     - "9092:9092"
  #   environment:
  #     # --- Enable KRaft ---
  #     KAFKA_ENABLE_KRAFT: "yes"
  #     KAFKA_PROCESS_ROLES: broker,controller
  #     KAFKA_NODE_ID: 1

  #     # --- Listeners ---
  #     KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
  #     KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
  #     KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT

  #     # --- Controller quorum ---
  #     KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
  #     KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@kafka:9093

  #     ALLOW_PLAINTEXT_LISTENER: "yes"
  #   networks:
  #     - opensource

# --------------------------------------------------
# Networks
# --------------------------------------------------
networks:
  opensource:
    driver: bridge

# --------------------------------------------------
# Volumes
# --------------------------------------------------
volumes:
  mysql_data:
  redis_data:
