services:
  postgres:
    image: pgvector/pgvector:pg16  
    container_name: postgres-db
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5

  minio:
    image: minio/minio:latest
    container_name: minio-storage
    restart: always
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD}
    volumes:
      - miniodata:/data
    ports:
      - "9000:9000"
      - "9001:9001"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
      interval: 30s
      timeout: 20s
      retries: 3

  n8n:
    image: n8nio/n8n:latest
    container_name: n8n-workflow
    restart: always
    environment:
      N8N_BASIC_AUTH_ACTIVE: "true"
      N8N_BASIC_AUTH_USER: ${N8N_BASIC_AUTH_USER}
      N8N_BASIC_AUTH_PASSWORD: ${N8N_BASIC_AUTH_PASSWORD}
      N8N_HOST: ${N8N_HOST}
      N8N_PORT: ${N8N_PORT}
      N8N_PROTOCOL: ${N8N_PROTOCOL}
      WEBHOOK_URL: ${WEBHOOK_URL}
      GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
    volumes:
      - n8ndata:/home/node/.n8n
    ports:
      - "5678:5678"
    depends_on:
      - postgres
      - minio
    links:
      - postgres
      - minio

  voice-agent:
    build: ./voice_agent    # path to your Dockerfile folder
    container_name: voice-agent
    ports:
      - "8000:8000"  # Expose the FastAPI server
    restart: always
    environment:
      MINIO_ENDPOINT: "http://minio:9000"
      MINIO_ACCESS_KEY: "${MINIO_ROOT_USER}"
      MINIO_SECRET_KEY: "${MINIO_ROOT_PASSWORD}"
      N8N_WEBHOOK_URL: "${N8N_WEBHOOK_URL}"
      OPENAI_API_KEY: "${OPENAI_API_KEY}"
      MINIO_BUCKET: "${MINIO_BUCKET}"
      POSTGRES_HOST: "postgres"
      POSTGRES_USER: "${POSTGRES_USER}"
      POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
      POSTGRES_DB: "${POSTGRES_DB}"

    volumes:
      - ./uploads:/app/uploads
    depends_on:
      - minio
      - n8n



volumes:
  pgdata:
  miniodata:
  n8ndata:
