149 lines
4.2 KiB
Python
149 lines
4.2 KiB
Python
from pydantic_settings import BaseSettings
|
|
from typing import Optional
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
import os
|
|
|
|
# Load environment variables from .env files
|
|
app_env = os.getenv("APP_ENV", "local")
|
|
env_filename = f".env.{app_env}"
|
|
|
|
# Define paths
|
|
base_path = Path(__file__).resolve().parent.parent.parent
|
|
backend_path = Path(__file__).resolve().parent.parent
|
|
|
|
# Load specific environment file (e.g., .env.development)
|
|
# Priority: Backend folder specific env -> Root specific env -> Backend .env -> Root .env
|
|
load_dotenv(dotenv_path=base_path / '.env') # Load base .env first as fallback
|
|
load_dotenv(dotenv_path=backend_path / '.env')
|
|
|
|
# Override with specific environment config
|
|
if (base_path / env_filename).exists():
|
|
load_dotenv(dotenv_path=base_path / env_filename, override=True)
|
|
if (backend_path / env_filename).exists():
|
|
load_dotenv(dotenv_path=backend_path / env_filename, override=True)
|
|
|
|
class Settings(BaseSettings):
|
|
# Project
|
|
PROJECT_NAME: str = "SaaS Architecture"
|
|
VERSION: str = "1.0.0"
|
|
|
|
# FastAPI
|
|
PORT: int
|
|
HOST: str
|
|
APP_ENV: str
|
|
SECRET_KEY: str
|
|
ALLOWED_HOSTS: str = "*"
|
|
|
|
# Frontend
|
|
FRONTEND_URL: str
|
|
# CORS (comma-separated origins). Example: "http://localhost:5173,https://app.example.com"
|
|
CORS_ALLOWED_ORIGINS: Optional[str] = None
|
|
# Optional CORS regex for advanced matching. Example: r"https://.*\\.example\\.com"
|
|
CORS_ALLOW_ORIGIN_REGEX: Optional[str] = None
|
|
|
|
# Security
|
|
ENCRYPTION_KEY: Optional[str] = None
|
|
BCRYPT_ROUNDS: int = 12
|
|
|
|
# Database settings
|
|
DATABASE_URL: str
|
|
DB_SSL: bool = False
|
|
|
|
# Redis Configuration
|
|
REDIS_URL: str = "redis://localhost:6379/0"
|
|
REDIS_ENABLED: bool = False # Disable Redis to avoid timeout warnings in development
|
|
REDIS_TIMEOUT: int = 2 # Connection timeout in seconds
|
|
REDIS_MAX_CONNECTIONS: int = 10 # Max connections in the pool
|
|
|
|
# Email
|
|
SMTP_HOST: str
|
|
SMTP_PORT: int = 587
|
|
SMTP_SECURE: bool = True
|
|
SMTP_USER: str
|
|
SMTP_PASSWORD: str
|
|
EMAIL_FROM: str
|
|
|
|
# JWT settings
|
|
ACCESS_TOKEN_SECRET: str
|
|
ACCESS_TOKEN_EXPIRES: int = 86400
|
|
REFRESH_TOKEN_SECRET: str
|
|
REFRESH_TOKEN_EXPIRES: int = 864000
|
|
JWT_ALGORITHM: str = "HS256"
|
|
|
|
# Super Admin Setup
|
|
SUPER_ADMIN_EMAIL: str
|
|
SUPER_ADMIN_PASSWORD: str
|
|
SUPER_ADMIN_FIRST_NAME: str = "Super"
|
|
SUPER_ADMIN_LAST_NAME: str = "Admin"
|
|
|
|
# External SaaS Integration
|
|
EXTERNAL_SAAS_WEBHOOK_SECRET: str = "change-this-secret-key"
|
|
|
|
# PayPal Integration
|
|
PAYPAL_CLIENT_ID: str
|
|
PAYPAL_CLIENT_SECRET: str
|
|
PAYPAL_MODE: str = "sandbox"
|
|
PAYPAL_API_URL: str = "https://api-m.sandbox.paypal.com"
|
|
|
|
# AWS S3 settings
|
|
AWS_SECRET_ACCESS_KEY: Optional[str] = None
|
|
AWS_ACCESS_KEY_ID: Optional[str] = None
|
|
S3_BUCKET_NAME: Optional[str] = None
|
|
AWS_REGION: Optional[str] = "us-east-1"
|
|
|
|
# Property to use existing S3_BUCKET_NAME for AWS_S3_BUCKET
|
|
@property
|
|
def AWS_S3_BUCKET(self) -> Optional[str]:
|
|
return self.S3_BUCKET_NAME
|
|
|
|
# S3 Dataset Processing Settings
|
|
S3_PROCESSING_WORKERS: int = 4
|
|
DOCUMENT_CHUNK_SIZE: int = 1000
|
|
DOCUMENT_CHUNK_OVERLAP: int = 200
|
|
PINECONE_BATCH_SIZE: int = 100
|
|
|
|
# Redis Chat Settings
|
|
REDIS_CHAT_TTL: int = 86400 # 24 hours
|
|
|
|
# Logging
|
|
LOG_LEVEL: str = "info"
|
|
|
|
# Rate Limiting
|
|
RATE_LIMIT_REQUESTS: int = 100
|
|
RATE_LIMIT_WINDOW: int = 60
|
|
|
|
# Integration Settings (Optional for development)
|
|
# Test_BASE_URL: Optional[str] = "http://localhost:8001"
|
|
# Test2_BASE_URL: Optional[str] = "http://localhost:8002"
|
|
# Test3_BASE_URL: Optional[str] = "http://localhost:8003"
|
|
# INTEGRATION_TIMEOUT: int = 30
|
|
|
|
# Properties for FastAPI Mail compatibility
|
|
@property
|
|
def MAIL_USERNAME(self) -> str:
|
|
return self.SMTP_USER
|
|
|
|
@property
|
|
def MAIL_PASSWORD(self) -> str:
|
|
return self.SMTP_PASSWORD
|
|
|
|
@property
|
|
def MAIL_PORT(self) -> int:
|
|
return self.SMTP_PORT
|
|
|
|
@property
|
|
def MAIL_SERVER(self) -> str:
|
|
return self.SMTP_HOST
|
|
|
|
@property
|
|
def MAIL_FROM(self) -> str:
|
|
return self.EMAIL_FROM
|
|
|
|
model_config = {
|
|
"case_sensitive": True,
|
|
"extra": "ignore",
|
|
}
|
|
|
|
settings = Settings() |