# In-A-Lign Agent Provenance Infrastructure
# Production deployment with Neo4j + GraphRAG

version: "3.8"

services:
  # Neo4j Graph Database
  neo4j:
    image: neo4j:5.15-community
    container_name: inalign-neo4j
    restart: unless-stopped
    ports:
      - "7474:7474"  # HTTP
      - "7687:7687"  # Bolt
    environment:
      NEO4J_AUTH: neo4j/${NEO4J_PASSWORD:-inalign-secure-2024}
      NEO4J_PLUGINS: '["apoc", "graph-data-science"]'
      NEO4J_dbms_memory_heap_initial__size: 512m
      NEO4J_dbms_memory_heap_max__size: 2g
      NEO4J_dbms_memory_pagecache_size: 512m
      NEO4J_apoc_export_file_enabled: "true"
      NEO4J_apoc_import_file_enabled: "true"
      NEO4J_apoc_import_file_use__neo4j__config: "true"
    volumes:
      - neo4j_data:/data
      - neo4j_logs:/logs
      - neo4j_plugins:/plugins
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:7474"]
      interval: 30s
      timeout: 10s
      retries: 5
    networks:
      - inalign-net

  # In-A-Lign API Server
  api:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: inalign-api
    restart: unless-stopped
    command: ["api"]
    ports:
      - "8080:8080"
    environment:
      NEO4J_URI: bolt://neo4j:7687
      NEO4J_USERNAME: neo4j
      NEO4J_PASSWORD: ${NEO4J_PASSWORD:-inalign-secure-2024}
      NEO4J_DATABASE: neo4j
      API_PORT: 8080
      LOG_LEVEL: INFO
    depends_on:
      neo4j:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - inalign-net

  # Background Worker for Analysis
  worker:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: inalign-worker
    restart: unless-stopped
    command: ["worker"]
    environment:
      NEO4J_URI: bolt://neo4j:7687
      NEO4J_USERNAME: neo4j
      NEO4J_PASSWORD: ${NEO4J_PASSWORD:-inalign-secure-2024}
      NEO4J_DATABASE: neo4j
      LOG_LEVEL: INFO
    depends_on:
      neo4j:
        condition: service_healthy
    networks:
      - inalign-net

  # Redis for caching (optional)
  redis:
    image: redis:7-alpine
    container_name: inalign-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - inalign-net

volumes:
  neo4j_data:
  neo4j_logs:
  neo4j_plugins:
  redis_data:

networks:
  inalign-net:
    driver: bridge
