""" FastAPI Application - Main Entry Point """ from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse from app.core.config import get_settings from app.core.logging import get_logger, setup_logging from app.presentation.api.v1.endpoints import router as api_router settings = get_settings() setup_logging(settings.log_level) logger = get_logger(__name__) @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan manager""" logger.info("application_startup", version=settings.app_version, env=settings.environment) # TODO: Initialize database connection pool # TODO: Initialize Qdrant collection # TODO: Warm up embedding model yield # Cleanup logger.info("application_shutdown") app = FastAPI( title=settings.app_name, version=settings.app_version, description="Production-ready RAG backend for corporate employee onboarding", lifespan=lifespan, ) # CORS app.add_middleware( CORSMiddleware, allow_origins=settings.cors_origins, allow_credentials=settings.cors_allow_credentials, allow_methods=["*"], allow_headers=["*"], ) # Include routers app.include_router(api_router) @app.get("/") async def root(): """Root endpoint""" return { "service": settings.app_name, "version": settings.app_version, "status": "running", "environment": settings.environment, } @app.exception_handler(Exception) async def global_exception_handler(request, exc): """Global exception handler""" logger.error("unhandled_exception", error=str(exc), exc_info=True) return JSONResponse( status_code=500, content={"error": "Internal server error", "detail": str(exc)}, ) if __name__ == "__main__": import uvicorn uvicorn.run( "app.main:app", host=settings.host, port=settings.port, reload=settings.debug, log_level=settings.log_level.lower(), )