arch-design-agent-skill-das.../backend/app/main.py
openclaw 50db453ec9 feat(project): add REST API — CRUD endpoints with FastAPI
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-23 16:06:58 +00:00

48 lines
1.6 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
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)
# Register routers
app.include_router(project_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()