Files
CA/backend/CLAUDE.md
Akiba So fc468464b2 feat: Initial CBPOA commit — 武汉儿童呼吸疾病风险评估系统
Context: Build a spatial risk assessment system correlating air quality
data with children's respiratory disease incidence across Wuhan.

Approach: FastAPI backend serving PostGIS spatial queries, React
frontend with Deck.gl maps, and a PyTorch SpatialTemporalGCN pipeline
for multi-day (1d/3d/7d) risk prediction.

Changes:
- backend/ — FastAPI API with auth (JWT), alerts, risk analysis,
  geocoded case data, grid statistics, and report endpoints
- frontend/ — React dashboard with interactive risk maps, alert
  monitoring, district comparison charts, and timeline player
- models/ — SpatialTemporalGCN model with trained weights and ONNX
  export for inference
- scripts/ — ETL pipeline for weather + medical data, grid generation,
  feature engineering, training, and daily inference
- deploy/ — Docker Compose configs for backend, frontend, and MLflow
- docs/ — API docs, deployment guide, user guide, and code review

Impact: Enables spatial risk visualization, alert monitoring, and
ML-driven health risk forecasting for environmental health teams.
2026-06-05 02:13:49 +08:00

1.3 KiB

Backend — FastAPI + PostGIS

Stack

  • FastAPI (async), asyncpg connection pool, Pydantic v2 settings
  • PostGIS via GeoAlchemy2, spatial queries with Shapely
  • Auth: python-jose + passlib (JWT/bcrypt)

Structure

backend/
  main.py          # App entry, CORS, router registration
  database.py      # asyncpg pool, Settings from .env
  models.py         # Pydantic response/request models
  routers/          # One file per domain (risk, alerts, cases, grid, etc.)
  app/              # Legacy code (routers/cases.py, routers/grid.py, performance.py)

Patterns

  • Routers: APIRouter() with prefix, registered in main.py via app.include_router()
  • DB access: async with db.get_connection() context manager (global db singleton)
  • Settings: pydantic_settings.BaseSettings loaded from .env at module level
  • Endpoints return Pydantic models, not raw dicts

Running

cd backend
source venv/bin/activate
uvicorn main:app --reload --port 8000

Anti-Patterns

  • Don't use sync database drivers — always asyncpg
  • Don't put business logic in routers — delegate to service functions
  • Don't hardcode DB credentials — use Settings from environment
  • Don't skip Pydantic validation on request/response bodies
  • Don't import from app/ — it's legacy, prefer top-level modules