"""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 = "" # legacy SQLite path; auto-resolved if empty database_provider: str = "sqlite" # "supabase" | "sqlite" db_schema: str = "classlens" # Postgres schema to isolate ClassLens tables # Supabase supabase_url: str = "" supabase_service_role_key: str = "" supabase_db_url: str = "" # postgresql://... (session pooler) supabase_storage_bucket: str = "classlens-raw-files" # Admin bootstrap: comma-separated emails promoted to admin on startup admin_emails: str = "" # 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", ""), database_provider=os.getenv("DATABASE_PROVIDER", "sqlite"), db_schema=os.getenv("DB_SCHEMA", "classlens"), supabase_url=os.getenv("SUPABASE_URL", ""), supabase_service_role_key=os.getenv("SUPABASE_SERVICE_ROLE_KEY", ""), supabase_db_url=os.getenv("SUPABASE_DB_URL", ""), supabase_storage_bucket=os.getenv("SUPABASE_STORAGE_BUCKET", "classlens-raw-files"), admin_emails=os.getenv("ADMIN_EMAILS", ""), 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"), )