version: '3.8'

services:
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "8000:8000"
    environment:
      - DATABASE_URL=sqlite:///./ai_tools.db
      - CORS_ORIGINS=${CORS_ORIGINS:-http://localhost:3000}
      - SECRET_KEY=${SECRET_KEY:-change-me-in-production}
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID:-}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET:-}
      - FRONTEND_URL=${FRONTEND_URL:-http://localhost:3000}
      - ALLOWED_EMAILS=${ALLOWED_EMAILS:-}
    volumes:
      - backend_data:/app/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/v1/health')"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        - PUBLIC_API_URL=${PUBLIC_API_URL:-http://localhost:8000}
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - ORIGIN=${ORIGIN:-http://localhost:3000}
    restart: unless-stopped
    depends_on:
      backend:
        condition: service_healthy

volumes:
  backend_data:

# Development override - use with: docker compose -f docker-compose.yml -f docker-compose.dev.yml up
