name: flowsint-dev

services:
  postgres:
    image: postgres:15
    container_name: flowsint-postgres-dev
    restart: always
    environment:
      POSTGRES_USER: flowsint
      POSTGRES_PASSWORD: flowsint
      POSTGRES_DB: flowsint
    ports:
      - "5433:5432"
    volumes:
      - pg_data_dev:/var/lib/postgresql/data
    networks:
      - flowsint_network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U flowsint"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:alpine
    container_name: flowsint-redis-dev
    ports:
      - "6379:6379"
    networks:
      - flowsint_network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  neo4j:
    image: neo4j:5
    container_name: flowsint-neo4j-dev
    ports:
      - "7474:7474" # Web UI
      - "7687:7687" # Bolt
    environment:
      - NEO4J_AUTH=${NEO4J_USERNAME}/${NEO4J_PASSWORD}
      - NEO4J_PLUGINS=["apoc"]
      - NEO4J_apoc_export_file_enabled=true
      - NEO4J_apoc_import_file_enabled=true
      - NEO4J_apoc_import_file_use__neo4j__config=true
    volumes:
      - neo4j_data_dev:/data
      - neo4j_logs_dev:/logs
      - neo4j_import_dev:/var/lib/neo4j/import
      - neo4j_plugins_dev:/plugins
    restart: unless-stopped
    networks:
      - flowsint_network
    healthcheck:
      test: cypher-shell -u ${NEO4J_USERNAME} -p ${NEO4J_PASSWORD} "RETURN 1"
      interval: 5s
      timeout: 5s
      retries: 10

  api:
    build:
      context: .
      dockerfile: flowsint-api/Dockerfile
      target: dev
    container_name: flowsint-api-dev
    restart: unless-stopped
    ports:
      - "5001:5001"
    volumes:
      - ./flowsint-api:/app/flowsint-api
      - /app/flowsint-api/.venv
      - ./flowsint-core:/app/flowsint-core
      - ./flowsint-types:/app/flowsint-types
      - ./flowsint-enrichers:/app/flowsint-enrichers
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - DATABASE_URL=postgresql://flowsint:flowsint@postgres:5432/flowsint
      - NEO4J_URI_BOLT=bolt://neo4j:7687
      - NEO4J_USERNAME=${NEO4J_USERNAME}
      - NEO4J_PASSWORD=${NEO4J_PASSWORD}
      - AUTH_SECRET=${AUTH_SECRET}
      - MASTER_VAULT_KEY_V1=${MASTER_VAULT_KEY_V1}
      - REDIS_URL=redis://redis:6379/0
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      neo4j:
        condition: service_healthy
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://localhost:5001/health || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - flowsint_network

  celery:
    build:
      context: .
      dockerfile: flowsint-api/Dockerfile
      target: dev
    container_name: flowsint-celery-dev
    restart: unless-stopped
    command: celery -A flowsint_core.core.celery worker --loglevel=info --pool=threads --concurrency=10
    volumes:
      - ./flowsint-api:/app/flowsint-api
      - /app/flowsint-api/.venv
      - ./flowsint-core:/app/flowsint-core
      - ./flowsint-types:/app/flowsint-types
      - ./flowsint-enrichers:/app/flowsint-enrichers
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - DATABASE_URL=postgresql://flowsint:flowsint@postgres:5432/flowsint
      - NEO4J_URI_BOLT=bolt://neo4j:7687
      - NEO4J_USERNAME=${NEO4J_USERNAME}
      - NEO4J_PASSWORD=${NEO4J_PASSWORD}
      - MASTER_VAULT_KEY_V1=${MASTER_VAULT_KEY_V1}
      - REDIS_URL=redis://redis:6379/0
      - SKIP_MIGRATIONS=true
      - AUTH_SECRET=${AUTH_SECRET}
    healthcheck:
      # Celery has no HTTP server — Dockerfile's curl-based healthcheck always fails.
      # Use celery's own ping primitive instead.
      test: ["CMD-SHELL", "celery -A flowsint_core.core.celery inspect ping -d celery@$$HOSTNAME || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      neo4j:
        condition: service_healthy
      api:
        condition: service_healthy
    networks:
      - flowsint_network

  app:
    build:
      context: ./flowsint-app
      dockerfile: Dockerfile.dev
    container_name: flowsint-app-dev
    ports:
      - "5173:5173"
    volumes:
      - ./flowsint-app:/app
      - /app/node_modules
    environment:
      - VITE_API_URL=${VITE_API_URL}
    depends_on:
      api:
        condition: service_healthy
    networks:
      - flowsint_network
    stdin_open: true
    tty: true

networks:
  flowsint_network:
    name: flowsint_network_dev
    driver: bridge

volumes:
  pg_data_dev:
  neo4j_data_dev:
  neo4j_logs_dev:
  neo4j_import_dev:
  neo4j_plugins_dev:
