Spaces:
Running
Running
| """ | |
| GraphoLab Backend — FastAPI application entry point. | |
| Run locally: | |
| uvicorn backend.main:app --reload --port 8000 | |
| Interactive API docs: | |
| http://localhost:8000/docs (Swagger UI) | |
| http://localhost:8000/redoc (ReDoc) | |
| """ | |
| from __future__ import annotations | |
| import threading | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from backend.config import settings | |
| from backend.database import init_db | |
| from backend.routers import auth, users, projects, analysis, rag, audit, compliance, agent | |
| async def lifespan(app: FastAPI): | |
| """Startup / shutdown lifecycle.""" | |
| await init_db() | |
| # Load RAG index in background so startup is non-blocking | |
| from core.rag import rag_load_docs | |
| threading.Thread( | |
| target=lambda: rag_load_docs(settings.rag_cache_dir), | |
| daemon=True, | |
| name="rag-loader", | |
| ).start() | |
| yield | |
| app = FastAPI( | |
| title=settings.app_name, | |
| version=settings.app_version, | |
| docs_url="/docs", | |
| redoc_url="/redoc", | |
| lifespan=lifespan, | |
| ) | |
| # ── CORS (allow React dev server) ───────────────────────────────────────────── | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.cors_origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # ── Routers ─────────────────────────────────────────────────────────────────── | |
| app.include_router(auth.router) | |
| app.include_router(users.router) | |
| app.include_router(projects.router) | |
| app.include_router(analysis.router) | |
| app.include_router(rag.router) | |
| app.include_router(compliance.router) | |
| app.include_router(agent.router) | |
| app.include_router(audit.router) | |
| # ── Health check ────────────────────────────────────────────────────────────── | |
| async def health() -> dict: | |
| return {"status": "ok", "version": settings.app_version} | |