Split views_api into a domain package; unshadow /accounts/hierarchy #61

Open
padreug wants to merge 3 commits from refactor/views-api-package into chore/hygiene

3 commits

Author SHA1 Message Date
a0166d4026 fix(accounts): register /accounts/hierarchy before /accounts/{account_id}
FastAPI matches in registration order, and hierarchy was registered
~3,300 lines after the {account_id} route — every request resolved as
account_id="hierarchy" and 404'd, so the endpoint has been unreachable
since it was added. Moved above the param routes in the accounts
module, with a functional reachability test and an updated route
snapshot (literal-before-param is now asserted for both overlap
families).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 16:12:37 +02:00
a7d7740a3a refactor(api): split views_api.py into a package of domain modules
Pure move — no logic changes. The 4,100-line single file becomes
views_api/ with one module per domain (accounts, entries, payments,
settings_reports, reconciliation, permissions, admin), each
registering full literal paths on its own APIRouter; __init__ builds
the combined libra_api_router so libra/__init__.py is untouched.
Shared imports/helpers live in views_api/_shared.py;
_extract_entry_id and _SYSTEM_LINK_PREFIXES move to
beancount_format.py (they are pure entry-dict parsing).

Route behavior is pinned by tests/test_route_table.py: the 73-route
set is unchanged, and the two order-sensitive families (the shadowed
/accounts/hierarchy wart — deliberately preserved here, fixed in the
next commit — and the admin sync literal/param pair) keep their
relative order inside a single module each.

Addresses CODE-REVIEW-2026-06 structure findings (views_api monolith).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 16:09:58 +02:00
9e06fa0b2a test(routes): snapshot the ordered route table before the package split
FastAPI matches in registration order; the views_api split must keep
the (methods, path, endpoint) table byte-identical. The snapshot also
records the known wart it must NOT silently change: /accounts/hierarchy
is registered after /accounts/{account_id} and therefore shadowed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-12 16:04:32 +02:00