version: "3.9"

services:
  mongo:
    image: mongo:7
    container_name: cryptoeditorial-mongo
    restart: unless-stopped
    ports:
      - "27017:27017"
    volumes:
      - mongo_data:/data/db

  backend:
    image: python:3.11-slim
    container_name: cryptoeditorial-backend
    working_dir: /app
    restart: unless-stopped
    depends_on:
      - mongo
    environment:
      MONGO_URL: "mongodb://mongo:27017"
      DB_NAME: "cryptoeditorial"
      CORS_ORIGINS: "http://localhost:3000"
      FRONTEND_URL: "http://localhost:3000"
      JWT_SECRET: "${JWT_SECRET}"
      ADMIN_EMAIL: "${ADMIN_EMAIL:-admin@cryptoeditorial.local}"
      ADMIN_PASSWORD: "${ADMIN_PASSWORD:-Admin123!}"
      COOKIE_SECURE: "false"
      COOKIE_SAMESITE: "lax"
      EMERGENT_LLM_KEY: "${EMERGENT_LLM_KEY}"
      COINGECKO_API_KEY: "${COINGECKO_API_KEY:-}"
      RESEND_API_KEY: "${RESEND_API_KEY:-}"
      SENDER_EMAIL: "${SENDER_EMAIL:-onboarding@resend.dev}"
      SENDER_NAME: "${SENDER_NAME:-CryptoEditorial}"
      NEWSLETTER_HOUR_JAKARTA: "${NEWSLETTER_HOUR_JAKARTA:-8}"
    volumes:
      - ./backend:/app
    ports:
      - "8001:8001"
    command: >
      bash -c "pip install -r requirements.txt --extra-index-url https://d33sy5i8bnduwe.cloudfront.net/simple/
      && uvicorn server:app --host 0.0.0.0 --port 8001 --reload"

  frontend:
    image: node:20
    container_name: cryptoeditorial-frontend
    working_dir: /app
    restart: unless-stopped
    depends_on:
      - backend
    environment:
      REACT_APP_BACKEND_URL: "http://localhost:8001"
      WDS_SOCKET_PORT: "3000"
    volumes:
      - ./frontend:/app
    ports:
      - "3000:3000"
    command: >
      bash -c "corepack enable && yarn install && yarn start"

volumes:
  mongo_data:
