"""Configuration management for ClassLens backend.""" from __future__ import annotations import os from pathlib import Path from functools import lru_cache from dotenv import load_dotenv from pydantic import BaseModel # Load .env file — try project root first, then chatkit/ _root = Path(__file__).parent.parent.parent.parent # hf-classlens-deploy/ _chatkit = Path(__file__).parent.parent.parent # chatkit/ load_dotenv(_root / ".env") load_dotenv(_chatkit / ".env") # overrides root if both exist class Settings(BaseModel): """Application settings loaded from environment variables.""" # OpenAI (single key for both vision parsing and report generation) openai_api_key: str = "" # JWT Auth jwt_secret_key: str = "" jwt_algorithm: str = "HS256" jwt_expire_minutes: int = 1440 # 24 hours # Database database_path: str = "" # auto-resolved if empty # Encryption key for sensitive data encryption_key: str = "" # File upload upload_dir: str = "" # auto-resolved if empty max_file_size_mb: int = 20 # Frontend URL for redirects frontend_url: str = "http://localhost:3000" class Config: env_file = ".env" @lru_cache def get_settings() -> Settings: """Get cached settings instance.""" return Settings( openai_api_key=os.getenv("OPENAI_API_KEY", ""), jwt_secret_key=os.getenv("JWT_SECRET_KEY", "classlens-dev-secret-change-in-prod"), jwt_algorithm=os.getenv("JWT_ALGORITHM", "HS256"), jwt_expire_minutes=int(os.getenv("JWT_EXPIRE_MINUTES", "1440")), database_path=os.getenv("DATABASE_PATH", ""), encryption_key=os.getenv("ENCRYPTION_KEY", ""), upload_dir=os.getenv("UPLOAD_DIR", ""), max_file_size_mb=int(os.getenv("MAX_FILE_SIZE_MB", "20")), frontend_url=os.getenv("FRONTEND_URL", "http://localhost:3000"), )