62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
import os
|
|
from pathlib import Path
|
|
|
|
from fastapi import FastAPI, Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from app.shared.kernel.exceptions import NotFoundError, ValidationError
|
|
from app.shared.infrastructure.config import Settings
|
|
from app.modules.project.infrastructure.json_repository import JsonProjectRepository
|
|
from app.modules.project.application.services import ProjectService
|
|
from app.modules.project.interfaces.http.router import router as project_router, init_router as init_project_router
|
|
from app.modules.scanner.application.services import ScanService
|
|
from app.modules.scanner.interfaces.http.router import router as scanner_router, init_router as init_scanner_router
|
|
from app.modules.graph.application.services import GraphService
|
|
from app.modules.graph.interfaces.http.router import router as graph_router, init_router as init_graph_router
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
app = FastAPI(title="Arch Design Dashboard API", version="0.1.0")
|
|
|
|
# Settings
|
|
registry_path = Path(os.environ.get("REGISTRY_PATH", str(Settings().registry_path)))
|
|
|
|
# Wire Project module
|
|
project_repo = JsonProjectRepository(registry_path)
|
|
project_service = ProjectService(project_repo)
|
|
init_project_router(project_service)
|
|
|
|
# Wire Scanner module
|
|
scan_service = ScanService()
|
|
init_scanner_router(project_service, scan_service)
|
|
|
|
# Wire Graph module
|
|
graph_service = GraphService()
|
|
init_graph_router(project_service, scan_service, graph_service)
|
|
|
|
# Register routers
|
|
app.include_router(project_router, prefix="/api")
|
|
app.include_router(scanner_router, prefix="/api")
|
|
app.include_router(graph_router, prefix="/api")
|
|
|
|
# Health check
|
|
@app.get("/api/health")
|
|
def health():
|
|
return {"status": "ok"}
|
|
|
|
# Exception handlers
|
|
@app.exception_handler(NotFoundError)
|
|
async def not_found_handler(request: Request, exc: NotFoundError):
|
|
return JSONResponse(status_code=404, content={"detail": str(exc)})
|
|
|
|
@app.exception_handler(ValidationError)
|
|
async def validation_handler(request: Request, exc: ValidationError):
|
|
return JSONResponse(status_code=400, content={"detail": exc.message})
|
|
|
|
return app
|
|
|
|
|
|
# For uvicorn: use `uvicorn app.main:create_app --factory`
|
|
# or for simple usage:
|
|
app = create_app()
|