Modules and Layers¶
Where code lives, how the four layers divide responsibility, and the placement and naming conventions new code should follow.
Source code structure¶
The directory tree below shows the main code layout. Paths are repository-relative.
gmlst/
├── __init__.py
├── __main__.py
├── cli.py
├── core_config.py
├── fasta_io.py
├── kmer_prefilter.py
├── metadata_io.py
├── utils.py
├── aligners/
│ ├── base.py
│ ├── blastn.py
│ ├── kma.py
│ ├── minimap2.py
│ └── nucmer.py
├── calling/
│ ├── allele.py
│ ├── chew_policy.py
│ ├── confidence.py
│ └── st_lookup.py
├── commands/
│ ├── common.py
│ ├── config.py
│ ├── typing.py
│ ├── typing_output.py
│ ├── typing_runner.py
│ ├── typing_runtime.py
│ ├── typing_scheme.py
│ ├── scheme.py
│ ├── scheme_common.py
│ ├── scheme_render.py
│ ├── scheme_custom.py
│ ├── utils.py
│ ├── utils_extract.py
│ └── utils_benchmark.py
├── core/
│ ├── config.py
│ ├── pipeline.py
│ ├── gene_predictor.py
│ ├── indexing.py
│ ├── prefilter.py
│ ├── ranking.py
│ ├── refinement.py
│ ├── sequences.py
│ ├── types.py
│ ├── cds.py
│ ├── exact_hash.py
│ ├── adapters_cds.py
│ ├── adapters_exact_hash.py
│ ├── adapters_index_prefilter.py
│ └── adapters_refinement.py
├── data/
│ ├── blocked_schemes.json
│ ├── organism_mapping.json
│ └── catalogs/
├── database/
│ ├── cache.py
│ ├── download.py
│ ├── schema.py
│ └── providers/
│ ├── __init__.py
│ ├── base.py
│ ├── bigsdb.py
│ ├── enterobase.py
│ ├── cgmlst.py
│ └── cgmlst_schemes.py
├── novel/
│ ├── reader.py
│ ├── service.py
│ └── writer.py
├── readers/
│ ├── fasta.py
│ ├── fastq.py
│ └── sample.py
├── schemefree/
│ ├── assembly_engine.py
│ ├── cluster_engine.py
│ ├── config.py
│ ├── gene_predictor.py # re-export shim (impl in core/)
│ ├── hasher.py
│ ├── io_handler.py
│ └── typing_engine.py
├── visual/
│ ├── cli.py
│ ├── _cli_helpers.py
│ ├── _cli_export.py
│ ├── app.py
│ └── mst.py
└── web/
├── frontend/
├── static/
└── templates/
Top-level modules¶
gmlst/__main__.pyis thepython -m gmlstentrypoint.gmlst/cli.pyregisters top-level Click groups,typing,scheme,utils, andvisual.gmlst/core_config.pycentralizes environment-driven cgMLST and backend toggles.gmlst/fasta_io.pyandgmlst/metadata_io.pyprovide focused I/O helpers.gmlst/utils.pycontains logging and shared utility helpers.
Domain and orchestration packages¶
gmlst/core/contains typing pipeline orchestration, indexing, prefiltering, ranking, refinement, sequence handling, and adapter layers.gmlst/calling/contains allele interpretation, confidence logic, chewBBACA-style policy, and ST lookup.gmlst/novel/contains novel allele/profile extraction and writing.gmlst/schemefree/contains the separate tgMLST workflow.
Infrastructure packages¶
gmlst/aligners/wraps BLAST+, KMA, minimap2, and MUMmer4 under one interface.gmlst/database/handles provider integration, downloads, catalogs, and cache layout.gmlst/readers/detects input type and groups FASTQ mate pairs.
Presentation packages¶
gmlst/commands/defines the CLI command behavior.gmlst/visual/exposes MST and result comparison APIs and the Flask app.gmlst/web/stores frontend source, built static assets, and templates.
Architecture layers¶
1. CLI layer¶
The CLI layer lives in gmlst/cli.py and gmlst/commands/. It is responsible for:
- parsing user input with Click
- validating command combinations
- applying command-level policy, such as FASTQ cgMLST backend switching
- dispatching to domain logic
- formatting output for terminal or files
Important files:
gmlst/cli.pygmlst/commands/typing.pygmlst/commands/typing_runner.pygmlst/commands/typing_output.pygmlst/commands/typing_scheme.pygmlst/commands/scheme.pygmlst/commands/utils.pygmlst/visual/cli.py
2. Domain layer¶
The domain layer lives mainly in gmlst/core/, gmlst/calling/, gmlst/novel/, and gmlst/schemefree/. It owns typing behavior and result interpretation.
Examples:
gmlst/core/pipeline.pyorchestrates sample typing end to end.gmlst/calling/allele.pyandgmlst/calling/st_lookup.pyturn alignments into calls and ST assignments.gmlst/novel/service.pycollects and persists novel alleles and profiles.gmlst/schemefree/typing_engine.pycoordinates de novo scheme-free typing.
3. Infrastructure layer¶
The infrastructure layer lives in gmlst/aligners/, gmlst/database/, and gmlst/readers/. It integrates external tools, remote sources, and local cache storage.
Examples:
gmlst/aligners/base.pydefines the aligner contract.gmlst/database/providers/base.pydefines the provider contract.gmlst/database/cache.pymanages scheme and index storage.gmlst/readers/sample.pydetects FASTA versus FASTQ input and auto-groups mates.
4. Presentation layer¶
The presentation layer lives in gmlst/visual/ and gmlst/web/.
gmlst/visual/app.pycreates the Flask application and JSON endpoints.gmlst/visual/mst.pycomputes profile distances, MSTs, heatmaps, and comparisons.gmlst/web/frontend/contains the Vue 3 + Vite source.gmlst/web/templates/andgmlst/web/static/serve built assets.
Repository path conventions¶
These conventions describe how code is organized today and where new code should live.
Code placement¶
- CLI registration belongs in
gmlst/cli.pyor feature-local CLI modules such asgmlst/visual/cli.py. - Command implementation belongs in
gmlst/commands/. - Pure typing orchestration belongs in
gmlst/core/. - Allele and ST interpretation belongs in
gmlst/calling/. - Remote provider and cache logic belongs in
gmlst/database/. - External aligner integrations belong in
gmlst/aligners/. - Input detection belongs in
gmlst/readers/. - Visualization code belongs in
gmlst/visual/andgmlst/web/.
Naming rules¶
- modules and files use
snake_case, for exampletyping_runner.py - classes use
PascalCase, for exampleDatabaseCache,SchemeInfo,SchemeFreeTyper - functions and variables use
snake_case - constants use
UPPER_SNAKE_CASE
Documentation paths¶
- architecture and contributor docs live in
docs/ - Chinese translations live in the same path with a
.zh.mdsuffix - provider-specific reference lives in
docs/usage/providers.md
Dependency direction¶
Imports flow in one direction:
commands/ + visual/cli.py -> core/ calling/ novel/ schemefree/ -> aligners/ database/ readers/
Practical consequences:
gmlst/core/must not importclick.gmlst/aligners/must not importgmlst/database/.gmlst/calling/accepts normalizedAlleleMatchobjects, never raw backend output.
If a change seems to require an import that points the other way, the logic is probably in the wrong layer.
Worked example: placing a new feature¶
| Change | Correct home | Why |
|---|---|---|
Add --min-depth validation |
gmlst/commands/typing.py |
User input policy |
| Add a new output column | gmlst/commands/typing_output.py |
Presentation concern |
| Add a prefilter heuristic | gmlst/core/prefilter.py |
Pure domain logic |
| Parse a new aligner output format | gmlst/aligners/<tool>.py |
Normalization at the boundary |
| Add a provider HTTP endpoint | gmlst/database/providers/<name>.py |
External integration |
| Change scheme name uniqueness | gmlst/database/cache.py |
Catalog ownership |
A quick rule: if the code needs click, rich, or sys.exit, it belongs in
commands/; if it needs subprocess to call a tool, it belongs in aligners/
or database/download.py; everything else is domain logic.