2026-05-23 — api/app/ subpackage (main.py split)¶
Motivation¶
Phase B of the SRP cleanup. api/main.py had grown to 615 LOC and was
juggling four responsibilities: inspector rules + JWT helpers + the giant
RequestIdMiddleware body + the lifespan context + app composition. Pull the
helpers into a dedicated api/app/ package so main.py shrinks back to a
thin wiring file (~220 LOC).
Diff¶
- New package:
api/app/ inspector.py— capture path lists +_inspector_should_capturepredicatejwt_utils.py—_decode_jwt_upn,_extract_client_ipmiddleware.py—RequestIdMiddleware(~225 LOC of body buffering / metrics emission)lifespan.py—_lifespancontext (credential warm-up + subscriber start- clean shutdown of broadcaster, frontend proxy client, httpx pool)
api/main.pynow: docstring + logging setup +create_app()+app, with a re-export of_inspector_should_capturefor the two tests that import it fromapi.main.- LOC:
main.py615 → 219; newapp/*.pytotal ≈ 459 (with docstrings, comments, and headers — same code, more readable).
Validation¶
uv run pytest -q api/tests→ 1260 passed in 60.63suv run ruff check api→ All checks passed