| """Main application entry point.""" | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from src.middlewares.logging import configure_logging, get_logger | |
| from src.middlewares.cors import add_cors_middleware | |
| from src.middlewares.rate_limit import limiter, _rate_limit_exceeded_handler | |
| from slowapi.errors import RateLimitExceeded | |
| # --- pr/5 Phase 1: unwire non-AI routers (Go owns these now). --- | |
| # Routers below are commented out, NOT deleted. The router files stay alive; | |
| # they're just not mounted, so they also disappear from Swagger. | |
| # from src.api.v1.document import router as document_router # unwired: Go handles documents | |
| # from src.api.v1.room import router as room_router # unwired: replaced by analysis_id | |
| # from src.api.v1.users import router as users_router # unwired: login moved off Python | |
| # from src.api.v1.db_client import router as db_client_router # unwired: Go registers DB client | |
| # from src.api.v1.data_catalog import router as data_catalog_router # unwired: Go handles the catalog | |
| # from src.api.v1.analysis import router as analysis_router # unwired: Go owns create/update analysis | |
| # from src.api.v1.chat import router as chat_router # unwired: replaced by /api/v2/chat/stream | |
| # NOTE: src.api.v1.chat module still imported by v2 chat + /tools/help — keep the file. | |
| from src.api.v1.report import router as report_router | |
| from src.api.v1.tools import router as tools_router | |
| from src.api.v1.help import router as help_router # pr/5 Phase 2: dedicated /tools/help | |
| from src.api.v2.chat import router as chat_v2_router # pr/5 Phase 2: v2 chat pilot (analysis_id) | |
| from src.db.postgres.init_db import init_db | |
| import os | |
| import uvicorn | |
| # Configure logging | |
| configure_logging() | |
| logger = get_logger("main") | |
| async def lifespan(app: FastAPI): | |
| logger.info("Starting application...") | |
| if os.getenv("SKIP_INIT_DB", "false").lower() != "true": | |
| await init_db() | |
| logger.info("Database initialized") | |
| else: | |
| logger.info("Skipping database initialization (SKIP_INIT_DB=true)") | |
| yield | |
| # Create FastAPI app | |
| app = FastAPI( | |
| title="DataEyond Agentic Service", | |
| description="Multi-agent AI backend with RAG capabilities", | |
| version="0.1.0", | |
| lifespan=lifespan, | |
| ) | |
| # Add middleware | |
| add_cors_middleware(app) | |
| app.state.limiter = limiter | |
| app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) | |
| # Include routers | |
| # --- pr/5 Phase 1: AI-only surface. Non-AI routers unwired (Go owns them). --- | |
| # app.include_router(users_router) # unwired: login moved off Python | |
| # app.include_router(document_router) # unwired: Go handles documents | |
| # app.include_router(room_router) # unwired: replaced by analysis_id | |
| # app.include_router(db_client_router) # unwired: Go registers DB client | |
| # app.include_router(data_catalog_router) # unwired: Go handles the catalog | |
| # app.include_router(analysis_router) # unwired: Go owns create/update analysis | |
| # app.include_router(chat_router) # unwired: v2 chat replaces it (drops v1 cache ops routes) | |
| app.include_router(report_router) | |
| app.include_router(tools_router) | |
| app.include_router(help_router) | |
| app.include_router(chat_v2_router) # pr/5 Phase 2: POST /api/v2/chat/stream (analysis_id) | |
| async def root(): | |
| """Root endpoint.""" | |
| return { | |
| "status": "ok", | |
| "service": "DataEyond Agentic Service", | |
| "version": "0.1.0" | |
| } | |
| async def health_check(): | |
| """Health check endpoint.""" | |
| return {"status": "healthy"} | |
| if __name__ == "__main__": | |
| uvicorn.run( | |
| "main:app", | |
| host="0.0.0.0", | |
| port=7860, | |
| reload=True | |
| ) | |