Layered architecture#
HydroModPy is a layered dependency graph. Every top-level subpackage of
hydromodpy/ is one layer and may import only the layers that
tests/unit/architecture/layer_matrix.yaml grants it. The YAML file is the
normative contract. The matrix below is generated from it by
tools/doc_contracts.py at every build, so it cannot drift, and the gate reads
the same YAML. The layers drawn as a graph, with the transitive reduction of the
edges, are in Layer graph.
Ports and adapters at the storage edge#
The storage contract is DuckDB-first, not backend-agnostic in every runtime
path. The project catalog uses
DuckDBBackend (hydromodpy/results/catalog/adapters/duckdb.py), its one backend. The data cache uses a separate DuckDB cache adapter.
CLI diagnostics, migration runners and portable-package snapshots may open DuckDB
directly, in the cases listed in Direct DuckDB access.
Field readers go through Run.read, which dispatches to the Zarr or Parquet store
through the field registry. See Package: results
for the Python surface.
The rules#
Held by the gate. A pull request that breaks one of these fails
Architecture / layers, surface and two threads.
One layer per top-level subpackage, and one row per package in the matrix.
An import is an edge, and the edge must be in the matrix. The target has no tolerance and no exempt file. The scanner counts every import: at module level, inside a function, under
TYPE_CHECKING,import_moduleon a literal, and a dotted path written in a lazy-import table.coreis the kernel leaf. It imports no sibling layer.hydromodpy_annex/may importhydromodpy/. The reverse is forbidden.Inside
data,calibrationanddisplay, a part imports only what its row of the package*_layout.yamlallows.A solver sub-package reads only the private names it declares itself (
test_layers.py).A new edge that violates the matrix is a regression. Propose the change before you touch the code.
Held by convention. No test fails on these, so a reviewer holds them.
The two MODFLOW backends,
solver/modflow6/andsolver/modflow_nwt/, do not import each other. What they share lives insolver/modflow_common/andsolver/modflow_grid/. The matrix seessolveras one layer, so it cannot check this.A leading underscore means private to the owning package. The linter enforces it for
data/anddisplay/(ruleSLF001); elsewhere it is a review matter.
Layer matrix#
14 packages, the root facade and python -m hydromodpy, 101 granted edges.
A layer may always import itself. Anything absent from a row is forbidden and fails CI.
<root> is the facade hydromodpy/__init__.py with the other modules at the root.
<main> is hydromodpy/__main__.py alone.
Source layer |
Allowed import targets |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Documented tolerances#
No edge is tolerated.
Files exempt from the layer rule#
No file is exempt from the layer rule.
Special layers#
projectPublic object-oriented facade. It binds workflow and calibration launchers to
Project, so that lower layers do not depend on the facade.cliThe
hmpcommand. Onlyhydromodpy/__main__.pyimports it, whichtest_layers.pychecks.
How CI checks the matrix#
tests/unit/architecture/test_layers.py parses every Python file of
hydromodpy/ and asserts that each edge is allowed or tolerated. It also checks
that the matrix and the package list agree and that every declared layer has a page
in Packages. The other files of the folder hold the contracts listed in
Architecture gates. When one fails, follow
Fix a failing architecture gate.
When a refactor needs a new edge#
Look for an intermediary layer that already carries the dependency.
If none fits, propose the change in an issue before touching code.
Change the YAML and the prose together, and say why in the pull request.
Never add an edge silently.
See also#
Packages for the role of each layer.
Mental model and design choices for the runtime flow the matrix shapes.