# SwarmCare Local Development Environment
# Run entire stack on your laptop with one command!
# Usage: docker-compose up -d

version: '3.8'

services:
  # Neo4j Graph Database (Medical Ontologies)
  neo4j:
    image: neo4j:5.13
    container_name: swarmcare-neo4j
    ports:
      - "7474:7474"   # Browser interface
      - "7687:7687"   # Bolt protocol
    environment:
      - NEO4J_AUTH=neo4j/swarmcare123
      - NEO4J_PLUGINS=["apoc"]
      - NEO4J_dbms_memory_heap_max__size=2G
    volumes:
      - neo4j_data:/data
      - neo4j_logs:/logs
      - ./phases/phase00/deliverables/neo4j-medical-ontologies.cypher:/docker-entrypoint-initdb.d/init.cypher:ro
    healthcheck:
      test: ["CMD", "cypher-shell", "-u", "neo4j", "-p", "swarmcare123", "RETURN 1"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - swarmcare-network

  # SwarmCare API (Python Backend)
  swarmcare-api:
    build:
      context: .
      dockerfile: Dockerfile.simple
    container_name: swarmcare-api
    ports:
      - "8000:8000"
    environment:
      - NEO4J_URI=bolt://neo4j:7687
      - NEO4J_USER=neo4j
      - NEO4J_PASSWORD=swarmcare123
      - ENVIRONMENT=development
      - LOG_LEVEL=INFO
    depends_on:
      neo4j:
        condition: service_healthy
    volumes:
      - .:/app:ro
    command: python3 -m http.server 8000
    networks:
      - swarmcare-network

  # Redis (Caching layer - optional)
  redis:
    image: redis:7-alpine
    container_name: swarmcare-redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5
    networks:
      - swarmcare-network

  # Nginx (Reverse Proxy - optional)
  nginx:
    image: nginx:alpine
    container_name: swarmcare-nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    depends_on:
      - swarmcare-api
    networks:
      - swarmcare-network

networks:
  swarmcare-network:
    driver: bridge

volumes:
  neo4j_data:
  neo4j_logs:
  redis_data:

# ==============================================================================
# USAGE INSTRUCTIONS
# ==============================================================================
#
# START EVERYTHING:
#   docker-compose up -d
#
# VIEW LOGS:
#   docker-compose logs -f
#
# STOP EVERYTHING:
#   docker-compose down
#
# STOP AND REMOVE DATA:
#   docker-compose down -v
#
# CHECK STATUS:
#   docker-compose ps
#
# ACCESS SERVICES:
#   Neo4j Browser:  http://localhost:7474  (neo4j / swarmcare123)
#   API:            http://localhost:8000
#   Nginx:          http://localhost:80
#
# LOAD MEDICAL ONTOLOGIES:
#   docker-compose exec neo4j cypher-shell -u neo4j -p swarmcare123 < phases/phase00/deliverables/neo4j-medical-ontologies.cypher
#
# ==============================================================================
