version: '3.8'

services:
  # Neo4j Database
  neo4j:
    image: neo4j:5-community
    container_name: kg_neo4j
    ports:
      - "7474:7474"  # HTTP
      - "7687:7687"  # Bolt
    environment:
      - NEO4J_AUTH=neo4j/${NEO4J_PASSWORD:-password}
      - NEO4J_PLUGINS=["apoc"]
      - NEO4J_dbms_security_procedures_unrestricted=apoc.*
      - NEO4J_dbms_memory_heap_initial__size=512m
      - NEO4J_dbms_memory_heap_max__size=2G
      - NEO4J_dbms_memory_pagecache_size=1G
    volumes:
      - neo4j_data:/data
      - neo4j_logs:/logs
      - neo4j_plugins:/plugins
    networks:
      - kg_network
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "wget --no-verbose --tries=1 --spider http://localhost:7474 || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 40s

  # MCP Server
  mcp-server:
    build:
      context: ..
      dockerfile: kg_mcp_server/Dockerfile
    container_name: kg_mcp_server
    ports:
      - "3000:3000"  # MCP Server SSE endpoint
    environment:
      - NEO4J_URI=${NEO4J_URI:-bolt://neo4j:7687}
      - NEO4J_USERNAME=${NEO4J_USERNAME:-neo4j}
      - NEO4J_PASSWORD=${NEO4J_PASSWORD:-password}
      - NEO4J_DATABASE=${NEO4J_DATABASE:-neo4j}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - LLM_BEARER_KEY=${LLM_BEARER_KEY}
      - LLM_BASE_URL=${LLM_BASE_URL}
      - OPENAI_MODEL=${OPENAI_MODEL}
      - LOG_LEVEL=${LOG_LEVEL:-INFO}
    networks:
      - kg_network
    depends_on:
      neo4j:
        condition: service_healthy
    restart: unless-stopped

networks:
  kg_network:
    driver: bridge
    name: kg_network

volumes:
  neo4j_data:
    driver: local
  neo4j_logs:
    driver: local
  neo4j_plugins:
    driver: local