version: '3.8'

services:
  # Neo4j Database
  neo4j:
    image: neo4j:5.15
    container_name: kg-neo4j
    restart: unless-stopped
    ports:
      - "7474:7474"   # HTTP
      - "7687:7687"   # Bolt
    environment:
      - NEO4J_AUTH=neo4j/password
      - NEO4J_PLUGINS=["apoc"]
      - NEO4J_dbms_security_procedures_unrestricted=apoc.*
      - NEO4J_dbms_security_procedures_allowlist=apoc.*
    volumes:
      - neo4j_data:/data
      - neo4j_logs:/logs
      - neo4j_import:/var/lib/neo4j/import
      - neo4j_plugins:/plugins
    healthcheck:
      test: ["CMD", "cypher-shell", "-u", "neo4j", "-p", "password", "RETURN 1"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - kg-network

  # Ollama with lightweight model
#  ollama:
#    image: ollama/ollama:latest
#    container_name: kg-ollama
#    restart: unless-stopped
#    ports:
#      - "11434:11434"
#    environment:
#      - OLLAMA_HOST=0.0.0.0
#    volumes:
#      - ollama_data:/root/.ollama
#    healthcheck:
#      test: ["CMD", "curl", "-f", "http://localhost:11434/api/tags"]
#      interval: 30s
#      timeout: 10s
#      retries: 3
#    networks:
#      - kg-network
#
#  # Model initialization service
#  ollama-init:
#    image: ollama/ollama:latest
#    container_name: kg-ollama-init
#    depends_on:
#      ollama:
#        condition: service_healthy
#    environment:
#      - OLLAMA_HOST=ollama:11434
#    command: >
#      sh -c "
#        echo 'Waiting for Ollama to be ready...' &&
#        sleep 10 &&
#        echo 'Pulling phi3:mini model...' &&
#        ollama pull phi3:mini &&
#        echo 'Model phi3:mini ready for use!' &&
#        echo 'Alternative models you can pull:' &&
#        echo '  - llama3.2:1b (smallest, 1.3GB)' &&
#        echo '  - phi3:mini (recommended, 2.3GB)' &&
#        echo '  - qwen2.5:1.5b (good performance, 1.5GB)' &&
#        echo '  - gemma2:2b (Google model, 1.6GB)' &&
#        echo 'KG Engine configured for phi3:mini - change model in .env if needed'
#      "
#    networks:
#      - kg-network

  # Optional: KG Engine development container
  kg-engine-dev:
    build:
      context: .
      dockerfile: Dockerfile.dev
    container_name: kg-engine-dev
    depends_on:
      neo4j:
        condition: service_healthy
      ollama:
        condition: service_healthy
    environment:
      - NEO4J_URI=bolt://neo4j:7687
      - NEO4J_USERNAME=neo4j
      - NEO4J_PASSWORD=password
      - NEO4J_DATABASE=neo4j
      - OPENAI_MODEL=phi3:mini
#      - LLM_BASE_URL=http://ollama:11434/v1
      - LLM_PROVIDER=ollama
    volumes:
      - ./src:/app/src
      - ./examples:/app/examples
      - ./tests:/app/tests
      - ./notebooks:/app/notebooks
    working_dir: /app
    command: >
      sh -c "
        echo 'KG Engine Development Environment Ready!' &&
        echo 'Services available:' &&
        echo '  - Neo4j: http://localhost:7474 (neo4j/password)' &&
        echo '  - Ollama: http://localhost:11434' &&
        echo '  - Current model: phi3:mini' &&
        echo '' &&
        echo 'Quick test commands:' &&
        echo '  python examples/simple_test.py' &&
        echo '  python -c \"from kg_engine import __version__; print(f\"KG Engine v{__version__}\")\"' &&
        echo '' &&
        echo 'Starting interactive shell...' &&
        /bin/bash
      "
    networks:
      - kg-network
    profiles:
      - dev

volumes:
  neo4j_data:
    driver: local
  neo4j_logs:
    driver: local
  neo4j_import:
    driver: local
  neo4j_plugins:
    driver: local
  ollama_data:
    driver: local

networks:
  kg-network:
    driver: bridge