version: '3.8'

services:
  # Hive Backend API
  hive-backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "8087:8000"
    environment:
      - DATABASE_URL=sqlite:///./hive.db
      - REDIS_URL=redis://redis:6379
      - ENVIRONMENT=development
      - LOG_LEVEL=info
      - CORS_ORIGINS=http://localhost:3000
    volumes:
      - ./config:/app/config
    depends_on:
      - redis
    networks:
      - hive-network
    restart: unless-stopped

  # Hive Frontend
  hive-frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    ports:
      - "3001:3000"
    environment:
      - REACT_APP_API_URL=http://localhost:8087
      - REACT_APP_WS_URL=ws://localhost:8087
    depends_on:
      - hive-backend
    networks:
      - hive-network
    restart: unless-stopped

  # PostgreSQL Database
  postgres:
    image: postgres:15
    environment:
      - POSTGRES_DB=hive
      - POSTGRES_USER=hive
      - POSTGRES_PASSWORD=hivepass
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./backend/migrations:/docker-entrypoint-initdb.d
    ports:
      - "5433:5432"
    networks:
      - hive-network
    restart: unless-stopped

  # Redis Cache
  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
    volumes:
      - redis_data:/data
    ports:
      - "6380:6379"
    networks:
      - hive-network
    restart: unless-stopped

  # Prometheus Metrics
  prometheus:
    image: prom/prometheus:latest
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--storage.tsdb.retention.time=30d'
      - '--web.enable-lifecycle'
    ports:
      - "9091:9090"
    volumes:
      - ./config/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus
    networks:
      - hive-network
    restart: unless-stopped

  # Grafana Dashboard
  grafana:
    image: grafana/grafana:latest
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=hiveadmin
      - GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
    ports:
      - "3002:3000"
    volumes:
      - grafana_data:/var/lib/grafana
      - ./config/monitoring/grafana:/etc/grafana/provisioning
    depends_on:
      - prometheus
    networks:
      - hive-network
    restart: unless-stopped

networks:
  hive-network:
    driver: bridge

volumes:
  postgres_data:
  redis_data:
  prometheus_data:
  grafana_data: