# SwarmCare - Docker Compose for Development and Production
version: '3.8'

services:
  # SwarmCare UI - Next.js Frontend
  swarmcare-ui:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: swarmcare-ui
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - NEXT_PUBLIC_API_URL=http://swarmcare-api:8000
      - NEXT_PUBLIC_ENABLE_ANALYTICS=true
      - NEXT_PUBLIC_ENABLE_FHIR_INTEGRATION=false
    depends_on:
      - swarmcare-api
    networks:
      - swarmcare-network
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  # SwarmCare API - FastAPI Backend
  swarmcare-api:
    build:
      context: ../SwarmCare_Production
      dockerfile: Dockerfile
    container_name: swarmcare-api
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      - ENVIRONMENT=production
      - DATABASE_URL=postgresql://swarmcare:swarmcare@postgres:5432/swarmcare
      - REDIS_URL=redis://redis:6379/0
      - SECRET_KEY=${SECRET_KEY:-change-me-in-production}
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
    depends_on:
      - postgres
      - redis
    networks:
      - swarmcare-network
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

  # PostgreSQL Database
  postgres:
    image: postgres:16-alpine
    container_name: swarmcare-postgres
    restart: unless-stopped
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=swarmcare
      - POSTGRES_PASSWORD=swarmcare
      - POSTGRES_DB=swarmcare
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init-db:/docker-entrypoint-initdb.d
    networks:
      - swarmcare-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U swarmcare -d swarmcare"]
      interval: 10s
      timeout: 5s
      retries: 5

  # Redis for Caching and Session Management
  redis:
    image: redis:7-alpine
    container_name: swarmcare-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - swarmcare-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3

  # Nginx Reverse Proxy (Production)
  nginx:
    image: nginx:alpine
    container_name: swarmcare-nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/ssl:/etc/nginx/ssl:ro
    depends_on:
      - swarmcare-ui
      - swarmcare-api
    networks:
      - swarmcare-network
    profiles:
      - production

networks:
  swarmcare-network:
    driver: bridge

volumes:
  postgres_data:
  redis_data:
