refactor: wave 3b — split api/routes.py (704 LOC) into a package#51
Merged
refactor: wave 3b — split api/routes.py (704 LOC) into a package#51
Conversation
api/routes.py was 704 LOC, the second-biggest backend file after
queries.py (split in wave 3a). Split by lifecycle concern:
routes/
__init__.py (22) barrel: single APIRouter(prefix="/api") that
includes the sub-routers
_helpers.py (126) classify_run_via_taxonomist — shared between
evolve handlers, not a route itself
evolve.py (214) POST /api/evolve + POST /api/evolve/from-parent
— endpoints that START runs
runs.py (402) POST /api/runs/{id}/cancel + every GET for
reading run state
Largest submodule is now 402 LOC, under the 500-LOC ceiling in
docs/clean-code.md §2. Also cleaned up one residual broad except in
classify_run_via_taxonomist (logger.warning -> logger.exception).
Test patches retargeted
-----------------------
Tests that used `patch("skillforge.api.routes.get_run", ...)` etc.
were patching the import side of the old monolith. They're updated to
target the new symbol location — `...routes.evolve.get_run` for tests
hitting POST endpoints and `...routes.runs.get_run` for tests hitting
GET endpoints.
QA
--
ruff check skillforge - clean
mypy skillforge - 64 files pass
pytest tests/ - 403 passed, 2 skipped, 0 failed
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wave 3b — splits
api/routes.py(704 LOC) into a package. Follows the same pattern as Wave 3a (queries split): decompose by concern, preserve every public URL, re-target test patches.__init__.pyAPIRouter(prefix="/api")that includes the sub-routers_helpers.pyclassify_run_via_taxonomist— shared between evolve handlers, not a route itselfevolve.py/api/evolve+ POST/api/evolve/from-parent— endpoints that start runsruns.py/api/runs/{id}/cancel+ every GET for reading run stateLargest submodule is 402 LOC — under the 500-LOC ceiling in
docs/clean-code.md§2.Also cleaned up
classify_run_via_taxonomistwas the last broadexcept Exceptionstill usinglogger.warning(..., exc)with redundant exc formatting. Fixed tologger.exception(...)with a clear noqa rationale._classify_run_via_taxonomist(module-private) renamed toclassify_run_via_taxonomistsince it's now cross-module.Test patches
Tests that used
patch("skillforge.api.routes.get_run", ...)etc. were patching the import side of the old monolith. Updated to target the new symbol location —...routes.evolve.get_runfor POST-endpoint tests,...routes.runs.get_runfor GET-endpoint tests. No test logic changed, just the patch target strings.Test plan
uv run ruff check skillforge— cleanuv run mypy skillforge— 64 files passuv run pytest tests/— 403 passed, 2 skipped, 0 failedWhat's next
Remaining hotspots (
agents/spawner.py805,agents/breeder.py619,engine/variant_evolution.py622,agents/managed_agents.py605) are agent / engine logic — trickier than routes+queries. Those are being deferred so we can move to Wave 4 (frontend API layer with TanStack Query) which is a cleaner Pareto win than splitting well-tested agent code.🤖 Generated with Claude Code