services:

  backend:
    build:
      context: ../backend
      dockerfile: Dockerfile
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY:-}
    volumes:
      - db_data:/app/data
    restart: unless-stopped
    networks:
      - internal
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health')"]
      interval: 30s
      timeout: 10s
      retries: 3

  frontend:
    build:
      context: ../frontend
      dockerfile: Dockerfile
    restart: unless-stopped
    networks:
      - internal

  nginx:
    image: nginx:1.27-alpine
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      - ./nginx/certs:/etc/letsencrypt:ro
      - ./nginx/certbot-webroot:/var/www/certbot:ro
    depends_on:
      - backend
      - frontend
    restart: unless-stopped
    networks:
      - internal

volumes:
  db_data:

networks:
  internal:
    driver: bridge
