The four card handlers lived in app/api/decks.py, scattering the Card
concept across model / schema / repository / a misnamed handler file. To
read the Card HTTP surface you had to open decks.py.
Move all four card handlers into app/api/cards.py with its own ROUTER.
The deck-nested /decks/{deck_id}/cards/ routes move too -- they operate
on Card rows (CardsRepository, return schemas.Cards); the /decks prefix
is just scoping, not ownership. Handlers keep their full paths, so the
URL tree is unchanged.
include_routers now registers both decks.ROUTER and cards.ROUTER; each
mounts at /api and resolves to distinct paths -- no collision. Ports
modern-python/litestar-sqlalchemy-template#31 to FastAPI.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Problem
The four card handlers lived in app/api/decks.py, scattering the Card concept across model / schema / repository / a misnamed handler file. To read the Card HTTP surface you had to open decks.py.
Change
Move all four card handlers into app/api/cards.py with its own ROUTER:
The deck-nested /decks/{deck_id}/cards/ routes move too — they operate on Card rows (CardsRepository, return schemas.Cards); the /decks/{deck_id}/ prefix is just scoping, not ownership. Handlers keep their full paths, so the URL tree is unchanged.
include_routers now registers both decks.ROUTER and cards.ROUTER; each mounts at /api and resolves to distinct paths — no collision. decks.py drops its now-unused models and CardsRepository imports.
CLAUDE.md updated to describe one ROUTER per resource.
This ports modern-python/litestar-sqlalchemy-template#31 to FastAPI.
Tests
Pure file move; tests address routes via the HTTP client, not handler imports. 19 passed, 100% coverage — cards.py and decks.py both fully covered.
🤖 Generated with Claude Code