version: '3.8'

services:
  # Self-Correcting Agent Kernel service
  scak:
    build:
      context: .
      target: production
    container_name: scak-kernel
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
    volumes:
      - ./data:/app/data
      - ./logs:/app/logs
    networks:
      - scak-network
    restart: unless-stopped

  # Streamlit Dashboard (development/monitoring)
  dashboard:
    build:
      context: .
      target: development
    container_name: scak-dashboard
    ports:
      - "8501:8501"
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
    volumes:
      - .:/app
      - ./data:/app/data
    networks:
      - scak-network
    command: streamlit run dashboard.py --server.address=0.0.0.0
    restart: unless-stopped

  # Redis for Tier 2 Skill Cache
  redis:
    image: redis:7-alpine
    container_name: scak-redis
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - scak-network
    command: redis-server --appendonly yes
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Vector DB (Qdrant) for Tier 3 Archive
  vectordb:
    image: qdrant/qdrant:latest
    container_name: scak-vectordb
    ports:
      - "6333:6333"
    volumes:
      - vectordb-data:/qdrant/storage
    networks:
      - scak-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:6333/"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Jupyter Notebook for experiments
  jupyter:
    build:
      context: .
      target: development
    container_name: scak-jupyter
    ports:
      - "8888:8888"
    environment:
      - JUPYTER_ENABLE_LAB=yes
    volumes:
      - .:/app
      - ./notebooks:/app/notebooks
    networks:
      - scak-network
    command: jupyter lab --ip=0.0.0.0 --allow-root --no-browser --NotebookApp.token=''
    restart: unless-stopped

volumes:
  redis-data:
  vectordb-data:

networks:
  scak-network:
    driver: bridge
