refactor: wave 3 — split db/queries.py (1363 LOC) into a package#50
Merged
refactor: wave 3 — split db/queries.py (1363 LOC) into a package#50
Conversation
db/queries.py was the largest non-seed file in the backend at 1363 LOC
and 46 functions. Every change forced a reviewer to re-scan the whole
module. Splits it into a package with one submodule per entity:
queries/
__init__.py barrel re-exporting every public name for
backward compatibility with the 38 import sites
_helpers.py (53) _connect, _int_or_none, _row_get
challenges.py (63) Challenge CRUD
genomes.py (302) SkillGenome + CompetitionResult + Generation —
the three row kinds a Generation owns
runs.py (318) EvolutionRun + lineage + leaked skills + zombies
seeds.py (109) candidate-seed registry
taxonomy.py (416) TaxonomyNode + SkillFamily + Variant +
VariantEvolution (related v2.0 entities)
transcripts.py (125) dispatch transcripts (v2.1.3 audit trail)
Largest submodule is now 416 LOC, under the 500-LOC ceiling in
docs/clean-code.md §2. No behavior changes — every public name is
still importable from the same path.
QA
--
ruff check skillforge - clean
mypy skillforge - 61 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 3 of the clean-code overhaul — decomposes the single biggest non-seed file in the backend.
db/queries.pywas 1363 LOC / 46 functions. Every change forced a reviewer to re-scan the whole file. Now a package with one submodule per entity cluster:__init__.py_helpers.py_connect,_int_or_none,_row_getchallenges.pygenomes.pySkillGenome+CompetitionResult+Generation(the three row kinds a Generation owns)runs.pyEvolutionRun+ lineage + leaked skills + zombiesseeds.pytaxonomy.pyTaxonomyNode+SkillFamily+Variant+VariantEvolutiontranscripts.pyLargest submodule is now 416 LOC — under the 500-LOC ceiling in
docs/clean-code.md§2. No behavior changes — every public name is still importable fromskillforge.db.queries.Why grouping, not one-file-per-entity
Generation,SkillGenome, andCompetitionResultare tightly coupled (a Generation owns a list of each). Splitting further would scatter related serialization code without clarifying anything. Same rationale forTaxonomyNode/SkillFamily/Variant/VariantEvolution— they're one v2.0 classification system. Runs + lineage + leaked + zombies are all top-level run-state operations.Test plan
uv run ruff check skillforge— cleanuv run mypy skillforge— 61 files passuv run pytest tests/— 403 passed, 2 skipped, 0 failedcd frontend && npm run build / lint / format:check / test— untouched, still greenFollow-ups (future waves)
api/routes.py(707 LOC) andagents/spawner.py(805 LOC) are the remaining backend hotspots. Both are being held for their own PRs because:🤖 Generated with Claude Code