"""FastAPI application factory""" from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from luxx.config import config from luxx.database import init_db from luxx.routes import api_router @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan manager""" init_db() from luxx.tools.builtin import crawler, code, data yield def create_app() -> FastAPI: """Create FastAPI application""" app = FastAPI( title="luxx API", description="Intelligent chat backend API with multi-model support, streaming responses, and tool calling", version="1.0.0", lifespan=lifespan ) # Configure CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], # Should be restricted in production allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Register routes app.include_router(api_router, prefix="/api") # Health check @app.get("/health") async def health_check(): return {"status": "healthy", "service": "luxx"} @app.get("/") async def root(): return { "service": "luxx API", "version": "1.0.0", "docs": "/docs" } return app # Create application instance app = create_app()