- Extract database models from monolithic main.py (2,373 lines) into organized modules - Implement service layer pattern with dedicated business logic classes - Split API endpoints into modular FastAPI routers by functionality - Add centralized configuration management with environment variable handling - Create proper separation of concerns across data, service, and presentation layers **Architecture Changes:** - models/: SQLAlchemy database models (CVE, SigmaRule, RuleTemplate, BulkProcessingJob) - config/: Centralized settings and database configuration - services/: Business logic (CVEService, SigmaRuleService, GitHubExploitAnalyzer) - routers/: Modular API endpoints (cves, sigma_rules, bulk_operations, llm_operations) - schemas/: Pydantic request/response models **Key Improvements:** - 95% reduction in main.py size (2,373 → 120 lines) - Updated 15+ backend files with proper import structure - Eliminated circular dependencies and tight coupling - Enhanced testability with isolated service components - Better code organization for team collaboration **Backward Compatibility:** - All API endpoints maintain same URLs and behavior - Zero breaking changes to existing functionality - Database schema unchanged - Environment variables preserved 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
No EOL
1.8 KiB
Python
55 lines
No EOL
1.8 KiB
Python
import os
|
|
from typing import Optional
|
|
|
|
|
|
class Settings:
|
|
"""Centralized application settings"""
|
|
|
|
# Database
|
|
DATABASE_URL: str = os.getenv("DATABASE_URL", "postgresql://cve_user:cve_password@localhost:5432/cve_sigma_db")
|
|
|
|
# External API Keys
|
|
NVD_API_KEY: Optional[str] = os.getenv("NVD_API_KEY")
|
|
GITHUB_TOKEN: Optional[str] = os.getenv("GITHUB_TOKEN")
|
|
OPENAI_API_KEY: Optional[str] = os.getenv("OPENAI_API_KEY")
|
|
ANTHROPIC_API_KEY: Optional[str] = os.getenv("ANTHROPIC_API_KEY")
|
|
|
|
# LLM Configuration
|
|
LLM_PROVIDER: str = os.getenv("LLM_PROVIDER", "ollama")
|
|
LLM_MODEL: str = os.getenv("LLM_MODEL", "llama3.2")
|
|
OLLAMA_BASE_URL: str = os.getenv("OLLAMA_BASE_URL", "http://ollama:11434")
|
|
|
|
# API Configuration
|
|
NVD_API_BASE_URL: str = "https://services.nvd.nist.gov/rest/json/cves/2.0"
|
|
GITHUB_API_BASE_URL: str = "https://api.github.com"
|
|
|
|
# Rate Limiting
|
|
NVD_RATE_LIMIT: int = 50 if NVD_API_KEY else 5 # requests per 30 seconds
|
|
GITHUB_RATE_LIMIT: int = 5000 if GITHUB_TOKEN else 60 # requests per hour
|
|
|
|
# Application Settings
|
|
DEBUG: bool = os.getenv("DEBUG", "false").lower() == "true"
|
|
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
|
|
|
|
# CORS Settings
|
|
CORS_ORIGINS: list = [
|
|
"http://localhost:3000",
|
|
"http://127.0.0.1:3000",
|
|
"http://frontend:3000"
|
|
]
|
|
|
|
# Processing Settings
|
|
DEFAULT_BATCH_SIZE: int = 50
|
|
MAX_GITHUB_RESULTS: int = 10
|
|
DEFAULT_START_YEAR: int = 2002
|
|
|
|
@classmethod
|
|
def get_instance(cls) -> "Settings":
|
|
"""Get singleton instance of settings"""
|
|
if not hasattr(cls, "_instance"):
|
|
cls._instance = cls()
|
|
return cls._instance
|
|
|
|
|
|
# Global settings instance
|
|
settings = Settings.get_instance() |