version: '3.8'

services:
  # Main App Service running Laravel Octane (Swoole)
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: aipos3-laravel-app
    container_name: aipos3_app
    ports:
      - "8000:8000"
    environment:
      - APP_ENV=production
      - APP_DEBUG=false
      - DB_CONNECTION=mysql
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=aierppos
      - DB_USERNAME=root
      - DB_PASSWORD=root
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - OCTANE_SERVER=swoole
    depends_on:
      - mysql
      - redis
    networks:
      - erp-network
    restart: unless-stopped

  # MySQL Database Service
  mysql:
    image: mysql:8.0
    container_name: aipos3_mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: aierppos
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    networks:
      - erp-network
    restart: unless-stopped

  # Single Redis instance for the Triple-Redis Pattern (DB 0: Queue, DB 1: Streams, DB 2: Pub/Sub, DB 3: Cache)
  redis:
    image: redis:7-alpine
    container_name: aipos3_redis
    command: redis-server --appendonly yes
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - erp-network
    restart: unless-stopped

  # Laravel Horizon Queue Monitor (Horizon db 0)
  horizon:
    image: aipos3-laravel-app
    container_name: aipos3_horizon
    command: php artisan horizon
    environment:
      - APP_ENV=production
      - DB_HOST=mysql
      - REDIS_HOST=redis
    depends_on:
      - app
      - redis
      - mysql
    networks:
      - erp-network
    restart: unless-stopped

  # Laravel Reverb Realtime WebSockets Server
  reverb:
    image: aipos3-laravel-app
    container_name: aipos3_reverb
    command: php artisan reverb:start --host=0.0.0.0 --port=8080
    ports:
      - "8080:8080"
    environment:
      - APP_ENV=production
      - REDIS_HOST=redis
    depends_on:
      - app
      - redis
    networks:
      - erp-network
    restart: unless-stopped

networks:
  erp-network:
    driver: bridge

volumes:
  mysql_data:
  redis_data:
