version: '3.8'

services:
  # MongoDB with Replica Set
  mongodb:
    image: mongo:7.0
    container_name: accessible-video-mongo
    restart: unless-stopped
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: password123
      MONGO_INITDB_DATABASE: accessible_video
    ports:
      - "27017:27017"
    volumes:
      - mongodb_data:/data/db
      - ./mongo-init.js:/docker-entrypoint-initdb.d/init.js:ro
      - ./mongo-keyfile:/data/keyfile:ro
    command: ["mongod", "--replSet", "rs0", "--bind_ip_all", "--keyFile", "/data/keyfile"]
    networks:
      - app-network

  # Redis
  redis:
    image: redis:7.2-alpine
    container_name: accessible-video-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - app-network

  # Backend API
  api:
    build:
      context: ./backend
      dockerfile: Dockerfile
      target: development
    container_name: accessible-video-api
    restart: unless-stopped
    environment:
      - APP_ENV=dev
      - MONGODB_URL=mongodb://admin:password123@mongodb:27017/accessible_video?authSource=admin&replicaSet=rs0
      - REDIS_URL=redis://redis:6379/0
      - JWT_SECRET_KEY=dev-secret-key-change-in-production
      - JWT_REFRESH_SECRET_KEY=dev-refresh-secret-key-change-in-production
      - GEMINI_API_KEY=${GEMINI_API_KEY}
      - SENDGRID_API_KEY=${SENDGRID_API_KEY}
      - ELEVENLABS_API_KEY=${ELEVENLABS_API_KEY}
      - GCS_BUCKET_NAME=accessible-video-dev
      - GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}
      - OTEL_SERVICE_NAME=accessible-video-api-dev
      - OTEL_TRACES_EXPORTER=console
      - OTEL_METRICS_EXPORTER=prometheus
      - SENTRY_DSN=${SENTRY_DSN}
      - SENTRY_ENVIRONMENT=development
    ports:
      - "8000:8000"
    volumes:
      - ./backend:/app
      - /app/.venv  # Keep venv in container
    depends_on:
      - mongodb
      - redis
    networks:
      - app-network

  # Celery Worker
  worker:
    build:
      context: ./backend
      dockerfile: Dockerfile
      target: development
    container_name: accessible-video-worker
    restart: unless-stopped
    environment:
      - APP_ENV=dev
      - MONGODB_URL=mongodb://admin:password123@mongodb:27017/accessible_video?authSource=admin&replicaSet=rs0
      - REDIS_URL=redis://redis:6379/0
      - CELERY_BROKER_URL=redis://redis:6379/0
      - CELERY_RESULT_BACKEND=redis://redis:6379/0
      - GEMINI_API_KEY=${GEMINI_API_KEY}
      - ELEVENLABS_API_KEY=${ELEVENLABS_API_KEY}
      - GCS_BUCKET_NAME=accessible-video-dev
      - GOOGLE_CLOUD_PROJECT=${GOOGLE_CLOUD_PROJECT}
      - OTEL_SERVICE_NAME=accessible-video-worker-dev
      - OTEL_TRACES_EXPORTER=console
      - OTEL_METRICS_EXPORTER=prometheus
      - SENTRY_DSN=${SENTRY_DSN}
      - SENTRY_ENVIRONMENT=development
      - C_FORCE_ROOT=1
    volumes:
      - ./backend:/app
      - /app/.venv  # Keep venv in container
    depends_on:
      - mongodb
      - redis
    command: ["celery", "-A", "app.tasks", "worker", "--loglevel=info", "--concurrency=1"]
    networks:
      - app-network


  # Frontend (for local development)
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: accessible-video-frontend
    restart: unless-stopped
    environment:
      - VITE_API_URL=http://localhost:8000
      - VITE_SENTRY_DSN=${VITE_SENTRY_DSN}
      - VITE_ENVIRONMENT=development
    ports:
      - "5173:5173"
    volumes:
      - ./frontend:/app
      - /app/node_modules  # Keep node_modules in container
    depends_on:
      - api
    networks:
      - app-network

volumes:
  mongodb_data:
  redis_data:

networks:
  app-network:
    driver: bridge