networks:
  lyra_net:
    driver: bridge

volumes:
  postgres_data:
    driver: local
  neo4j_data:
    driver: local

services:
  # ============================================================
  # NeoMem: Postgres
  # ============================================================
  neomem-postgres:
    image: ankane/pgvector:v0.5.1
    container_name: neomem-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: neomem
      POSTGRES_PASSWORD: neomempass
      POSTGRES_DB: neomem
    volumes:
      - ./volumes/postgres_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U neomem -d neomem || exit 1"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - lyra_net

  # ============================================================
  # NeoMem: Neo4j Graph
  # ============================================================
  neomem-neo4j:
    image: neo4j:5
    container_name: neomem-neo4j
    restart: unless-stopped
    environment:
      NEO4J_AUTH: "neo4j/neomemgraph"
      NEO4JLABS_PLUGINS: '["graph-data-science"]'
    volumes:
      - ./volumes/neo4j_data:/data
    ports:
      - "7474:7474"
      - "7687:7687"
    healthcheck:
      test: ["CMD-SHELL", "cypher-shell -u neo4j -p neomemgraph 'RETURN 1' || exit 1"]
      interval: 10s
      timeout: 10s
      retries: 10
    networks:
      - lyra_net

  # ============================================================
  # NeoMem API
  # ============================================================
  neomem-api:
    build:
      context: ./neomem
    image: lyra-neomem:latest
    container_name: neomem-api
    restart: unless-stopped
    env_file:
      - ./neomem/.env
    volumes:
      - ./neomem_history:/app/history
    ports:
      - "7077:7077"
    depends_on:
      neomem-postgres:
        condition: service_healthy
      neomem-neo4j:
        condition: service_healthy
    networks:
      - lyra_net

  # ============================================================
  # Relay
  # ============================================================
  relay:
    build:
      context: ./core/relay
    container_name: relay
    restart: unless-stopped
    ports:
      - "7078:7078"
    networks:
      - lyra_net

  # ============================================================
  # Cortex
  # ============================================================
  cortex:
    build:
      context: ./cortex
    container_name: cortex
    restart: unless-stopped
    env_file:
      - ./cortex/.env
    volumes:
      - ./cortex:/app
    ports:
      - "7081:7081"
    environment:
      LLM_PRIMARY_URL: http://10.0.0.43:7081/v1/completions
      NEOMEM_URL: http://neomem-api:7077
      RAG_URL: http://rag:7090
      RELAY_URL: http://relay:7078
    networks:
      - lyra_net

  # ============================================================
  # Intake
  # ============================================================
  intake:
    build:
      context: ./intake
    container_name: intake
    restart: unless-stopped
    env_file:
      - ./intake/.env
    ports:
      - "7080:7080"
    volumes:
      - ./intake:/app
      - ./intake-logs:/app/logs
    depends_on:
      - cortex
    networks:
      - lyra_net

  # ============================================================
  # RAG Service
  # ============================================================
  # rag:
  #   build:
  #     context: ./rag
  #   container_name: rag
  #   restart: unless-stopped
  #   environment:
  #     NEOMEM_URL: http://neomem-api:7077
  #   ports:
  #     - "7090:7090"
  #   networks:
  #     - lyra_net
