services:
  postgres:
    image: postgres:16-alpine
    container_name: mitai-db-prod
    restart: unless-stopped
    environment:
      POSTGRES_DB: mitai_prod
      POSTGRES_USER: mitai_prod
      POSTGRES_PASSWORD: ${DB_PASSWORD:-change_me_in_production}
    volumes:
      - mitai_postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U mitai_prod"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build: ./backend
    container_name: mitai-api
    restart: unless-stopped
    ports:
      - "8002:8000"
    depends_on:
      postgres:
        condition: service_healthy
    volumes:
      - bodytrack_bodytrack-data:/app/data
      - bodytrack_bodytrack-photos:/app/photos
    environment:
      # Database
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_NAME=mitai_prod
      - DB_USER=mitai_prod
      - DB_PASSWORD=${DB_PASSWORD:-change_me_in_production}

      # AI
      - OPENROUTER_API_KEY=${OPENROUTER_API_KEY}
      - OPENROUTER_MODEL=${OPENROUTER_MODEL:-anthropic/claude-sonnet-4}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}

      # Email
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT:-587}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASS=${SMTP_PASS}
      - SMTP_FROM=${SMTP_FROM}

      # App
      - APP_URL=${APP_URL}
      - DATA_DIR=/app/data
      - PHOTOS_DIR=/app/photos
      - ALLOWED_ORIGINS=${ALLOWED_ORIGINS:-*}
      - ENVIRONMENT=production

  frontend:
    build: ./frontend
    container_name: mitai-ui
    restart: unless-stopped
    ports:
      - "3002:80"
    depends_on:
      - backend

volumes:
  mitai_postgres_data:
  bodytrack_bodytrack-data:
    external: true
  bodytrack_bodytrack-photos:
    external: true
