Backstage — Architecture Map & Code Health
pgdorm is a Rust core with a thin Python surface. This page maps how the pieces depend on each other and where the code carries debt. Every diagram and table is generated from the live code by tools/archmap, which is assembled from standard tools rather than custom graph code:
grimp builds the Python import graph. It is the engine behind import-linter, and it also knows which imports are lazy (PEP 810 ).
import-linter enforces the layering contracts in pyproject.toml.
cargo-modules resolves Rust use items with rust-analyzer.
Graphviz lays the graphs out: tred removes implied edges and dot draws the layers.
complexipy scores the cognitive complexity of Python functions with SonarSource's rules.
Core: 43,885 SLOC (25.4%)
25%
Rust core (crates): 18,311 SLOC (10.6%)
Python ORM (model · query · runtime): 13,708 SLOC (7.9%)
Python migrations (migrate): 11,866 SLOC (6.9%)
Tests: 35,482 SLOC (20.6%)
21%
ORM tests: 14,718 SLOC (8.5%)
migration tests: 10,229 SLOC (5.9%)
real-app cases: 2,901 SLOC (1.7%)
architecture & support: 3,808 SLOC (2.2%)
Rust tests: 3,826 SLOC (2.2%)
Docs & Examples: 69,852 SLOC (40.5%)
41%
docs (.md/.css/.js): 45,808 SLOC (26.6%)
examples (.py/.sql): 24,044 SLOC (13.9%)
Tools & Bench: 23,232 SLOC (13.5%)
13%
tools (.py): 13,164 SLOC (7.6%)
bench (.py): 10,068 SLOC (5.8%)
172.5k
SLOC total
75% tests, docs & tools
Core — 43.9k (25.4%)
Rust core (crates)
18,311 (10.6%)
Python ORM (model · query · runtime)
13,708 (7.9%)
Python migrations (migrate)
11,866 (6.9%)
Tests — 35.5k (20.6%)
ORM tests
14,718 (8.5%)
migration tests
10,229 (5.9%)
real-app cases
2,901 (1.7%)
architecture & support
3,808 (2.2%)
Rust tests
3,826 (2.2%)
Docs & Examples — 69.9k (40.5%)
docs (.md/.css/.js)
45,808 (26.6%)
examples (.py/.sql)
24,044 (13.9%)
Tools & Bench — 23.2k (13.5%)
tools (.py)
13,164 (7.6%)
bench (.py)
10,068 (5.8%)
Non-blank, non-comment SLOC across the repository (excluding vendored upstream/ fixtures). Rust crates are split into production code (crates/*/src/) vs. tests (crates/*/tests/ and inline #[cfg(test)] blocks).
How to read the maps
An arrow A → B means A imports B . Imports only ever point down, toward the Rust core.
Each map is drawn as a transitive reduction : an import that a longer chain of arrows already implies is left out. The full import counts are in the coupling table .
Box borders encode file size against the budget : plain up to 350 lines, orange for 351–600 lines, red above 600.
Bold blue boxes are package facades (__init__.py or lib.rs). Dashed arrows are lazy imports. Dashed grey boxes are other packages that the modules import.
Python package layers
packages
cluster_surface
public surface
cluster_migrate
pgdorm.migrate (migration toolkit)
cluster_core
ORM core
pgdorm.enums
enums
1 module
pgdorm.typing
typing
1 module
pgdorm.migrate
migrate
2 modules
pgdorm.typing->pgdorm.migrate
pgdorm
pgdorm
1 module
pgdorm.runtime
runtime
11 modules
pgdorm->pgdorm.runtime
pgdorm.testing
testing
1 module
pgdorm.testing->pgdorm
pgdorm.migrate.enums
migrate.enums
1 module
pgdorm.migrate._catalog
migrate._catalog
10 modules
pgdorm.migrate._catalog->pgdorm.runtime
pgdorm.migrate._plan
migrate._plan
18 modules
pgdorm.migrate._plan->pgdorm.migrate.enums
pgdorm.migrate._plan->pgdorm.migrate._catalog
pgdorm.migrate._exec
migrate._exec
4 modules
pgdorm.migrate._exec->pgdorm.migrate._plan
pgdorm.migrate._assimilate
migrate._assimilate
20 modules
pgdorm.migrate._assimilate->pgdorm.migrate._exec
pgdorm.migrate._cli
migrate._cli
6 modules
pgdorm.migrate._cli->pgdorm.migrate._assimilate
pgdorm.migrate->pgdorm.migrate._cli
pgdorm.model
model
28 modules
pgdorm.model->pgdorm.enums
pgdorm._pgdorm
_pgdorm
Rust extension
pgdorm.model->pgdorm._pgdorm
pgdorm.query
query
20 modules
pgdorm.query->pgdorm.model
pgdorm.runtime->pgdorm.query
lint-imports and tests/architecture/ enforce these contracts on every commit:
A few rules have no import-linter contract type and stay as AST checks in tests/architecture/test_layers.py:
an internal module never imports its own package facade;
every @dataclass is frozen=True, kw_only=True, slots=True;
the code has zero raw-SQL entry points, zero if TYPE_CHECKING: blocks and zero mocking;
every typing.cast carries a # typing-boundary: comment.
Inside each package
pgdorm.model: tables, columns, types and expressions
model
ext:pgdorm._pgdorm
_pgdorm
ext:pgdorm.enums
enums
pgdorm.model
model/__init__
pgdorm.model._combinators
_combinators
pgdorm.model->pgdorm.model._combinators
pgdorm.model._dto
_dto
pgdorm.model->pgdorm.model._dto
pgdorm.model._expr_builders
_expr_builders
pgdorm.model->pgdorm.model._expr_builders
pgdorm.model._extensions
_extensions
pgdorm.model->pgdorm.model._extensions
pgdorm.model._registry
_registry
pgdorm.model->pgdorm.model._registry
pgdorm.model._expr
_expr
pgdorm.model._combinators->pgdorm.model._expr
pgdorm.model._table
_table
pgdorm.model._dto->pgdorm.model._table
pgdorm.model._fts_json
_fts_json
pgdorm.model._expr_builders->pgdorm.model._fts_json
pgdorm.model._extensions->pgdorm.model._table
pgdorm.model._registry->pgdorm.model._table
pgdorm.model._arith
_arith
pgdorm.model._auto_ident
_auto_ident
pgdorm.model._auto_ident->ext:pgdorm._pgdorm
pgdorm.model._columns
_columns
pgdorm.model._defaults
_defaults
pgdorm.model._columns->pgdorm.model._defaults
pgdorm.model._defaults->pgdorm.model._expr
pgdorm.model._field_specs
_field_specs
pgdorm.model._defaults->pgdorm.model._field_specs
pgdorm.model._expr->pgdorm.model._arith
pgdorm.model._expr_ops
_expr_ops
pgdorm.model._expr->pgdorm.model._expr_ops
pgdorm.model._constraints
_constraints
pgdorm.model._ir_specs
_ir_specs
pgdorm.model._constraints->pgdorm.model._ir_specs
pgdorm.model._ir_specs->pgdorm.model._columns
pgdorm.model._field_specs->ext:pgdorm.enums
pgdorm.model._types
_types
pgdorm.model._field_specs->pgdorm.model._types
pgdorm.model._fields
_fields
pgdorm.model._table->pgdorm.model._fields
pgdorm.model._inheritance
_inheritance
pgdorm.model._table->pgdorm.model._inheritance
pgdorm.model._pydantic
_pydantic
pgdorm.model._table->pgdorm.model._pydantic
pgdorm.model._table_alias
_table_alias
pgdorm.model._table->pgdorm.model._table_alias
pgdorm.model._table_builder
_table_builder
pgdorm.model._table->pgdorm.model._table_builder
pgdorm.model._expr_ops->ext:pgdorm._pgdorm
pgdorm.model._window
_window
pgdorm.model._expr_ops->pgdorm.model._window
pgdorm.model._fts_json->pgdorm.model._table
pgdorm.model._window->ext:pgdorm.enums
pgdorm.model._window->pgdorm.model._types
pgdorm.model._fields->pgdorm.model._constraints
pgdorm.model._meta
_meta
pgdorm.model._inheritance->pgdorm.model._meta
pgdorm.model._rules
_rules
pgdorm.model._inheritance->pgdorm.model._rules
pgdorm.model._meta->pgdorm.model._columns
pgdorm.model._rules_constraints
_rules_constraints
pgdorm.model._rules->pgdorm.model._rules_constraints
pgdorm.model._pydantic->pgdorm.model._constraints
pgdorm.model._rules_inline
_rules_inline
pgdorm.model._rules_constraints->pgdorm.model._rules_inline
pgdorm.model._rules_inline->pgdorm.model._auto_ident
pgdorm.model._rules_inline->pgdorm.model._constraints
pgdorm.model._table_alias->pgdorm.model._columns
pgdorm.model._table_builder->pgdorm.model._meta
pgdorm.model._table_builder->pgdorm.model._rules
pgdorm.query: the typed query builder and compiler bridge
query
ext:pgdorm._pgdorm
_pgdorm
ext:pgdorm.enums
enums
ext:pgdorm.model
model
pgdorm.query
query/__init__
pgdorm.query._funcs
_funcs
pgdorm.query->pgdorm.query._funcs
pgdorm.query._prepare
_prepare
pgdorm.query->pgdorm.query._prepare
pgdorm.query._agg
_agg
pgdorm.query._funcs->pgdorm.query._agg
pgdorm.query._compile
_compile
pgdorm.query._prepare->pgdorm.query._compile
pgdorm.query._agg->ext:pgdorm._pgdorm
pgdorm.query._agg->ext:pgdorm.enums
pgdorm.query._agg->ext:pgdorm.model
pgdorm.query._by_name
_by_name
pgdorm.query._select
_select
pgdorm.query._by_name->pgdorm.query._select
pgdorm.query._select->pgdorm.query._agg
pgdorm.query._into
_into
pgdorm.query._select->pgdorm.query._into
pgdorm.query._lateral
_lateral
pgdorm.query._select->pgdorm.query._lateral
pgdorm.query._select_cols
_select_cols
pgdorm.query._select->pgdorm.query._select_cols
pgdorm.query._by_name_plan
_by_name_plan
pgdorm.query._by_name_plan->pgdorm.query._by_name
pgdorm.query._compile_compose
_compile_compose
pgdorm.query._compile->pgdorm.query._compile_compose
pgdorm.query._compile_dml
_compile_dml
pgdorm.query._compile->pgdorm.query._compile_dml
pgdorm.query._compile_select
_compile_select
pgdorm.query._compile_compose->pgdorm.query._compile_select
pgdorm.query._insert_select
_insert_select
pgdorm.query._compile_compose->pgdorm.query._insert_select
pgdorm.query._compile_dml->pgdorm.query._compile_select
pgdorm.query._cti
_cti
pgdorm.query._compile_dml->pgdorm.query._cti
pgdorm.query._merge
_merge
pgdorm.query._compile_dml->pgdorm.query._merge
pgdorm.query._compile_select->pgdorm.query._select
pgdorm.query._insert_select->pgdorm.query._by_name
pgdorm.query._compose
_compose
pgdorm.query._insert_select->pgdorm.query._compose
pgdorm.query._dml
_dml
pgdorm.query._cti->pgdorm.query._dml
pgdorm.query._merge->pgdorm.query._by_name
pgdorm.query._compose->pgdorm.query._select
pgdorm.query._dml->pgdorm.query._by_name_plan
pgdorm.query._dml->pgdorm.query._insert_select
pgdorm.query._joins
_joins
pgdorm.query._into->pgdorm.query._joins
pgdorm.query._joins->ext:pgdorm.enums
pgdorm.query._joins->ext:pgdorm.model
pgdorm.query._lateral->ext:pgdorm._pgdorm
pgdorm.query._lateral->pgdorm.query._joins
pgdorm.query._select_cols->ext:pgdorm._pgdorm
pgdorm.query._select_cols->pgdorm.query._joins
pgdorm.runtime: pools, transactions, telemetry and the doctor
runtime
ext:pgdorm._pgdorm
_pgdorm
ext:pgdorm.enums
enums
ext:pgdorm.model
model
ext:pgdorm.query
query
pgdorm.runtime
runtime/__init__
pgdorm.runtime._doctor
_doctor
pgdorm.runtime->pgdorm.runtime._doctor
pgdorm.runtime._pool
_pool
pgdorm.runtime._doctor->pgdorm.runtime._pool
pgdorm.runtime._extensions
_extensions
pgdorm.runtime._pool->pgdorm.runtime._extensions
pgdorm.runtime._listen
_listen
pgdorm.runtime._pool->pgdorm.runtime._listen
pgdorm.runtime._split
_split
pgdorm.runtime._pool->pgdorm.runtime._split
pgdorm.runtime._telemetry
_telemetry
pgdorm.runtime._pool->pgdorm.runtime._telemetry
pgdorm.runtime._exec_helpers
_exec_helpers
pgdorm.runtime._exec_helpers->ext:pgdorm._pgdorm
pgdorm.runtime._exec_helpers->ext:pgdorm.enums
pgdorm.runtime._exec_helpers->ext:pgdorm.model
pgdorm.runtime._exec_helpers->ext:pgdorm.query
pgdorm.runtime._executors
_executors
pgdorm.runtime._executors->pgdorm.runtime._exec_helpers
pgdorm.runtime._pipeline
_pipeline
pgdorm.runtime._executors->pgdorm.runtime._pipeline
pgdorm.runtime._pipeline->ext:pgdorm._pgdorm
pgdorm.runtime._pipeline->ext:pgdorm.enums
pgdorm.runtime._pipeline->ext:pgdorm.model
pgdorm.runtime._pipeline->ext:pgdorm.query
pgdorm.runtime._extensions->pgdorm.runtime._executors
pgdorm.runtime._listen->ext:pgdorm._pgdorm
pgdorm.runtime._split->ext:pgdorm.model
pgdorm.runtime._split->ext:pgdorm.query
pgdorm.runtime._telemetry->ext:pgdorm.enums
pgdorm.runtime._trace
_trace
pgdorm.runtime._telemetry->pgdorm.runtime._trace
pgdorm.runtime._trace->ext:pgdorm._pgdorm
pgdorm.runtime._trace->ext:pgdorm.model
pgdorm.migrate: five sub-layers, from catalog snapshots up to the CLI
migrate
cluster_pgdorm.migrate._catalog
migrate._catalog
cluster_pgdorm.migrate._plan
migrate._plan
cluster_pgdorm.migrate._exec
migrate._exec
cluster_pgdorm.migrate._assimilate
migrate._assimilate
cluster_pgdorm.migrate._cli
migrate._cli
pgdorm.migrate._catalog
migrate._catalog/__init__
pgdorm.migrate._catalog._canon
_canon
pgdorm.migrate._catalog->pgdorm.migrate._catalog._canon
pgdorm.migrate._catalog._from_tables
_from_tables
pgdorm.migrate._catalog->pgdorm.migrate._catalog._from_tables
pgdorm.migrate._catalog._from_pg
_from_pg
pgdorm.migrate._catalog._canon->pgdorm.migrate._catalog._from_pg
pgdorm.migrate._catalog._pooler
_pooler
pgdorm.migrate._catalog._from_pg->pgdorm.migrate._catalog._pooler
pgdorm.migrate._catalog._models
_models
pgdorm.migrate._catalog._from_tables->pgdorm.migrate._catalog._models
pgdorm.migrate._catalog._ident_norm
_ident_norm
pgdorm.migrate._catalog._json_serde
_json_serde
ext:pgdorm.model
model
pgdorm.migrate._catalog._json_serde->ext:pgdorm.model
pgdorm.migrate._catalog._models->pgdorm.migrate._catalog._ident_norm
pgdorm.migrate._catalog._models->pgdorm.migrate._catalog._json_serde
pgdorm.migrate._catalog._view_deps
_view_deps
pgdorm.migrate._catalog._models->pgdorm.migrate._catalog._view_deps
ext:pgdorm._pgdorm
_pgdorm
pgdorm.migrate._catalog._models->ext:pgdorm._pgdorm
ext:pgdorm.runtime
runtime
pgdorm.migrate._catalog._models->ext:pgdorm.runtime
pgdorm.migrate._catalog._pg_catalog
_pg_catalog
pgdorm.migrate._catalog._pg_catalog->ext:pgdorm.model
pgdorm.migrate._catalog._pooler->pgdorm.migrate._catalog._models
ext:pgdorm.enums
enums
pgdorm.migrate._catalog._pooler->ext:pgdorm.enums
pgdorm.migrate._catalog._view_deps->pgdorm.migrate._catalog._pg_catalog
ext:pgdorm.query
query
pgdorm.migrate._catalog._view_deps->ext:pgdorm.query
pgdorm.migrate._plan
migrate._plan/__init__
pgdorm.migrate._plan._ddl
_ddl
pgdorm.migrate._plan->pgdorm.migrate._plan._ddl
pgdorm.migrate._plan._diff
_diff
pgdorm.migrate._plan->pgdorm.migrate._plan._diff
pgdorm.migrate._plan._render
_render
pgdorm.migrate._plan->pgdorm.migrate._plan._render
pgdorm.migrate._plan._replay
_replay
pgdorm.migrate._plan->pgdorm.migrate._plan._replay
pgdorm.migrate._plan._hazards
_hazards
pgdorm.migrate._plan._ddl->pgdorm.migrate._plan._hazards
pgdorm.migrate._plan._order
_order
pgdorm.migrate._plan._diff->pgdorm.migrate._plan._order
pgdorm.migrate._plan._expr_rewrite
_expr_rewrite
pgdorm.migrate._plan._ops
_ops
pgdorm.migrate._plan._hazards->pgdorm.migrate._plan._ops
pgdorm.migrate._plan._op_base
_op_base
pgdorm.migrate._plan._op_base->pgdorm.migrate._catalog
ext:pgdorm.migrate.enums
migrate.enums
pgdorm.migrate._plan._op_base->ext:pgdorm.migrate.enums
pgdorm.migrate._plan._ops_col_attr
_ops_col_attr
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_col_attr
pgdorm.migrate._plan._ops_column
_ops_column
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_column
pgdorm.migrate._plan._ops_constraint
_ops_constraint
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_constraint
pgdorm.migrate._plan._ops_extension
_ops_extension
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_extension
pgdorm.migrate._plan._ops_index
_ops_index
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_index
pgdorm.migrate._plan._ops_misc
_ops_misc
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_misc
pgdorm.migrate._plan._ops_table
_ops_table
pgdorm.migrate._plan._ops->pgdorm.migrate._plan._ops_table
pgdorm.migrate._plan._ops_col_attr->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._ops_column->pgdorm.migrate._plan._expr_rewrite
pgdorm.migrate._plan._ops_column->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._seq_helpers
_seq_helpers
pgdorm.migrate._plan._ops_column->pgdorm.migrate._plan._seq_helpers
pgdorm.migrate._plan._ops_constraint->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._ops_extension->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._ops_index->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._ops_misc->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._ops_table->pgdorm.migrate._plan._expr_rewrite
pgdorm.migrate._plan._ops_table->pgdorm.migrate._plan._op_base
pgdorm.migrate._plan._ops_table->pgdorm.migrate._plan._seq_helpers
pgdorm.migrate._plan._order->pgdorm.migrate._plan._ops
pgdorm.migrate._plan._render->pgdorm.migrate._plan._ops
pgdorm.migrate._plan._replay->pgdorm.migrate._plan._ops
pgdorm.migrate._plan._seq_helpers->pgdorm.migrate._catalog
pgdorm.migrate._exec
migrate._exec/__init__
pgdorm.migrate._exec._runner
_runner
pgdorm.migrate._exec->pgdorm.migrate._exec._runner
pgdorm.migrate._exec._ledger
_ledger
pgdorm.migrate._exec._ledger->pgdorm.migrate._plan
pgdorm.migrate._exec._schema
_schema
pgdorm.migrate._exec._ledger->pgdorm.migrate._exec._schema
pgdorm.migrate._exec._runner->pgdorm.migrate._exec._ledger
pgdorm.migrate._exec._schema->pgdorm.migrate._catalog
pgdorm.migrate._assimilate
migrate._assimilate/__init__
pgdorm.migrate._assimilate._legacy
_legacy
pgdorm.migrate._assimilate->pgdorm.migrate._assimilate._legacy
pgdorm.migrate._assimilate._runner
_runner
pgdorm.migrate._assimilate->pgdorm.migrate._assimilate._runner
pgdorm.migrate._assimilate._adoption
_adoption
pgdorm.migrate._assimilate._adoption_impacts
_adoption_impacts
pgdorm.migrate._assimilate._adoption->pgdorm.migrate._assimilate._adoption_impacts
pgdorm.migrate._assimilate._adoption_ops
_adoption_ops
pgdorm.migrate._assimilate._adoption->pgdorm.migrate._assimilate._adoption_ops
pgdorm.migrate._assimilate._adoption_models
_adoption_models
pgdorm.migrate._assimilate._adoption_impacts->pgdorm.migrate._assimilate._adoption_models
pgdorm.migrate._assimilate._adoption_models->pgdorm.migrate._plan
pgdorm.migrate._assimilate._audit
_audit
pgdorm.migrate._assimilate._adoption_models->pgdorm.migrate._assimilate._audit
pgdorm.migrate._assimilate._adoption_ops->pgdorm.migrate._assimilate._adoption_models
pgdorm.migrate._assimilate._audit_table_checks
_audit_table_checks
pgdorm.migrate._assimilate._audit->pgdorm.migrate._assimilate._audit_table_checks
pgdorm.migrate._assimilate._audit_models
_audit_models
pgdorm.migrate._assimilate._audit_models->pgdorm.migrate._catalog
pgdorm.migrate._assimilate._rules
_rules
pgdorm.migrate._assimilate._audit_models->pgdorm.migrate._assimilate._rules
pgdorm.migrate._assimilate._audit_pg
_audit_pg
pgdorm.migrate._assimilate._audit_pg->pgdorm.migrate._assimilate._audit
pgdorm.migrate._assimilate._audit_table_checks->pgdorm.migrate._assimilate._audit_models
pgdorm.migrate._assimilate._codegen
_codegen
pgdorm.migrate._assimilate._codegen_columns
_codegen_columns
pgdorm.migrate._assimilate._codegen->pgdorm.migrate._assimilate._codegen_columns
pgdorm.migrate._assimilate._codegen_constraints
_codegen_constraints
pgdorm.migrate._assimilate._codegen_columns->pgdorm.migrate._assimilate._codegen_constraints
pgdorm.migrate._assimilate._codegen_enums
_codegen_enums
pgdorm.migrate._assimilate._codegen_columns->pgdorm.migrate._assimilate._codegen_enums
pgdorm.migrate._assimilate._codegen_constraints->pgdorm.migrate._assimilate._audit
pgdorm.migrate._assimilate._codegen_expr
_codegen_expr
pgdorm.migrate._assimilate._codegen_constraints->pgdorm.migrate._assimilate._codegen_expr
pgdorm.migrate._assimilate._codegen_project
_codegen_project
pgdorm.migrate._assimilate._codegen_enums->pgdorm.migrate._assimilate._codegen_project
pgdorm.migrate._assimilate._codegen_types
_codegen_types
pgdorm.migrate._assimilate._codegen_enums->pgdorm.migrate._assimilate._codegen_types
pgdorm.migrate._assimilate._codegen_expr->pgdorm.migrate._catalog
pgdorm.migrate._assimilate._codegen_project->pgdorm.migrate._assimilate._adoption
pgdorm.migrate._assimilate._codegen_types->pgdorm.migrate._assimilate._adoption
pgdorm.migrate._assimilate._external
_external
pgdorm.migrate._assimilate._external->pgdorm.migrate._assimilate._adoption
pgdorm.migrate._assimilate._legacy->ext:pgdorm.model
pgdorm.migrate._assimilate._rules->ext:pgdorm.migrate.enums
pgdorm.migrate._assimilate._runner->pgdorm.migrate._exec
pgdorm.migrate._assimilate._runner->pgdorm.migrate._assimilate._audit_pg
pgdorm.migrate._assimilate._runner->pgdorm.migrate._assimilate._codegen
pgdorm.migrate._assimilate._runner->pgdorm.migrate._assimilate._external
pgdorm.migrate._cli
migrate._cli/__init__
pgdorm.migrate._cli._app
_app
pgdorm.migrate._cli->pgdorm.migrate._cli._app
pgdorm.migrate._cli._commands
_commands
pgdorm.migrate._cli._app->pgdorm.migrate._cli._commands
pgdorm.migrate._cli._format
_format
pgdorm.migrate._cli._commands->pgdorm.migrate._cli._format
pgdorm.migrate._cli._parser
_parser
pgdorm.migrate._cli._commands->pgdorm.migrate._cli._parser
pgdorm.migrate._cli._format->pgdorm.migrate._exec
pgdorm.migrate._cli._parser->pgdorm.migrate._assimilate
pgdorm.migrate._cli._types
_types
pgdorm.migrate._cli._parser->pgdorm.migrate._cli._types
pgdorm.migrate._cli._types->pgdorm.migrate._plan
Coupling
Afferent coupling (Ca) counts the packages that import a package, and efferent coupling (Ce) counts the packages it imports. Instability, Ce/(Ca+Ce), runs from 0 (everything depends on it, so change it with care) to 1 (nothing depends on it, so it is free to change). In a healthy layering, instability rises as you move up the layers.
Most imported from other packages: pgdorm.model (47), pgdorm._pgdorm (43), pgdorm.enums (40), pgdorm.migrate._catalog (40), pgdorm.migrate.enums (24).
Widest importers: pgdorm.model (19), pgdorm.migrate._assimilate._runner (14), pgdorm.model._table (13), pgdorm.query._compile (13), pgdorm.query (12).
Rust crates
crates
cluster_ws
Cargo workspace (crates/)
pgdorm-compiler
pgdorm-compiler
pgdorm-ir
pgdorm-ir
pgdorm-compiler->pgdorm-ir
pgdorm-py
pgdorm-py
pgdorm-wire
pgdorm-wire
pgdorm-py->pgdorm-wire
pgdorm-wire->pgdorm-compiler
py
python/pgdorm
(imports _pgdorm)
py->pgdorm-py
PyO3
cargo machete reports no unused dependencies in the workspace.
pgdorm-ir: schema IR, types, values and the ERD renderer
pgdorm-ir
pgdorm_ir
lib.rs
pgdorm_ir::erd
erd
pgdorm_ir->pgdorm_ir::erd
pgdorm_ir::value
value
pgdorm_ir->pgdorm_ir::value
pgdorm_ir::erd::cards
erd::cards
pgdorm_ir::erd->pgdorm_ir::erd::cards
pgdorm_ir::erd::connectors
erd::connectors
pgdorm_ir::erd->pgdorm_ir::erd::connectors
pgdorm_ir::numeric
numeric
pgdorm_ir::value->pgdorm_ir::numeric
pgdorm_ir::erd::focus
erd::focus
pgdorm_ir::erd::cards->pgdorm_ir::erd::focus
pgdorm_ir::erd::layout
erd::layout
pgdorm_ir::erd::connectors->pgdorm_ir::erd::layout
pgdorm_ir::erd::graph
erd::graph
pgdorm_ir::erd::focus->pgdorm_ir::erd::graph
pgdorm_ir::erd::layout->pgdorm_ir::erd::graph
pgdorm_ir::erd::style
erd::style
pgdorm_ir::erd::layout->pgdorm_ir::erd::style
pgdorm_ir::schema
schema
pgdorm_ir::erd::graph->pgdorm_ir::schema
pgdorm_ir::schema->pgdorm_ir
pgdorm_ir::erd::style->pgdorm_ir::schema
pgdorm_ir::numeric->pgdorm_ir
pgdorm-compiler: SQL AST, writer and DDL emitter
pgdorm-compiler
pgdorm_compiler
lib.rs
pgdorm_compiler::ddl_expr
ddl_expr
pgdorm_compiler->pgdorm_compiler::ddl_expr
pgdorm_compiler::ddl_ops
ddl_ops
pgdorm_compiler->pgdorm_compiler::ddl_ops
pgdorm_compiler::ast
ast
pgdorm_compiler::ddl_expr->pgdorm_compiler::ast
pgdorm_compiler::ddl_ops::table
ddl_ops::table
pgdorm_compiler::ddl_ops->pgdorm_compiler::ddl_ops::table
pgdorm_compiler::ast_dml
ast_dml
pgdorm_compiler::ast->pgdorm_compiler::ast_dml
pgdorm_compiler::compose_dml
compose_dml
pgdorm_compiler::ast_dml->pgdorm_compiler::compose_dml
pgdorm_compiler::compose
compose
pgdorm_compiler::compose_dml->pgdorm_compiler::compose
pgdorm_compiler::emit
emit
pgdorm_compiler::compose_dml->pgdorm_compiler::emit
pgdorm_compiler::compose->pgdorm_compiler
pgdorm_compiler::emit::dml
emit::dml
pgdorm_compiler::emit->pgdorm_compiler::emit::dml
pgdorm_compiler::emit::insert_select
emit::insert_select
pgdorm_compiler::emit->pgdorm_compiler::emit::insert_select
pgdorm_compiler::emit::json_server
emit::json_server
pgdorm_compiler::emit->pgdorm_compiler::emit::json_server
pgdorm_compiler::emit::qualify
emit::qualify
pgdorm_compiler::emit->pgdorm_compiler::emit::qualify
pgdorm_compiler::emit::select
emit::select
pgdorm_compiler::emit->pgdorm_compiler::emit::select
pgdorm_compiler::ddl_ops::table->pgdorm_compiler
pgdorm_compiler::ddl_ops::alter
ddl_ops::alter
pgdorm_compiler::ddl_ops::alter->pgdorm_compiler
pgdorm_compiler::ddl_ops::sequence
ddl_ops::sequence
pgdorm_compiler::ddl_ops::sequence->pgdorm_compiler
pgdorm_compiler::emit::dml->pgdorm_compiler
pgdorm_compiler::emit::insert_select->pgdorm_compiler
pgdorm_compiler::writer
writer
pgdorm_compiler::emit::json_server->pgdorm_compiler::writer
pgdorm_compiler::emit::qualify->pgdorm_compiler::ast
pgdorm_compiler::emit::select->pgdorm_compiler
pgdorm_compiler::writer->pgdorm_compiler
pgdorm_compiler::expr
expr
pgdorm_compiler::expr->pgdorm_compiler
pgdorm-wire: the Tokio PostgreSQL v3 binary wire client
pgdorm-wire
pgdorm_wire
lib.rs
pgdorm_wire::arrow
arrow
pgdorm_wire->pgdorm_wire::arrow
pgdorm_wire::json
json
pgdorm_wire->pgdorm_wire::json
pgdorm_wire::listen
listen
pgdorm_wire->pgdorm_wire::listen
pgdorm_wire::arrow::copy_in
arrow::copy_in
pgdorm_wire::arrow->pgdorm_wire::arrow::copy_in
pgdorm_wire::json::numeric
json::numeric
pgdorm_wire::json->pgdorm_wire::json::numeric
pgdorm_wire::json::scalars
json::scalars
pgdorm_wire::json->pgdorm_wire::json::scalars
pgdorm_wire::conn
conn
pgdorm_wire::listen->pgdorm_wire::conn
pgdorm_wire::arrow::copy_in->pgdorm_wire
pgdorm_wire::codec
codec
pgdorm_wire::codec::composite
codec::composite
pgdorm_wire::codec->pgdorm_wire::codec::composite
pgdorm_wire::codec::composite->pgdorm_wire
pgdorm_wire::config
config
pgdorm_wire::config->pgdorm_wire
pgdorm_wire::conn::search_path
conn::search_path
pgdorm_wire::conn->pgdorm_wire::conn::search_path
pgdorm_wire::stream
stream
pgdorm_wire::conn->pgdorm_wire::stream
pgdorm_wire::transport
transport
pgdorm_wire::conn->pgdorm_wire::transport
pgdorm_wire::conn::search_path->pgdorm_wire::config
pgdorm_wire::conn::pipeline
conn::pipeline
pgdorm_wire::stream->pgdorm_wire::conn::pipeline
pgdorm_wire::tx
tx
pgdorm_wire::stream->pgdorm_wire::tx
pgdorm_wire::transport->pgdorm_wire
pgdorm_wire::conn::pipeline->pgdorm_wire
pgdorm_wire::copy
copy
pgdorm_wire::copy->pgdorm_wire
pgdorm_wire::json::numeric->pgdorm_wire
pgdorm_wire::json::scalars->pgdorm_wire
pgdorm_wire::observer
observer
pgdorm_wire::observer->pgdorm_wire
pgdorm_wire::pool
pool
pgdorm_wire::pool->pgdorm_wire
pgdorm_wire::pool_exec
pool_exec
pgdorm_wire::pool_exec->pgdorm_wire
pgdorm_wire::row
row
pgdorm_wire::row->pgdorm_wire::codec
pgdorm_wire::tx->pgdorm_wire::observer
pgdorm_wire::tx->pgdorm_wire::pool
pgdorm_wire::tx->pgdorm_wire::row
pgdorm-py: the PyO3 bindings behind pgdorm._pgdorm
pgdorm-py
_pgdorm
lib.rs
_pgdorm::ddl_ext
ddl_ext
_pgdorm->_pgdorm::ddl_ext
_pgdorm::expr
expr
_pgdorm->_pgdorm::expr
_pgdorm::pool
pool
_pgdorm->_pgdorm::pool
_pgdorm::ddl
ddl
_pgdorm::ddl_ext->_pgdorm::ddl
_pgdorm::expr->_pgdorm
_pgdorm::listen
listen
_pgdorm::pool->_pgdorm::listen
_pgdorm::pool::exec
pool::exec
_pgdorm::pool->_pgdorm::pool::exec
_pgdorm::convert
convert
_pgdorm::convert->_pgdorm
_pgdorm::ddl_helpers
ddl_helpers
_pgdorm::ddl->_pgdorm::ddl_helpers
_pgdorm::schema
schema
_pgdorm::ddl_helpers->_pgdorm::schema
_pgdorm::schema->_pgdorm
_pgdorm::decode_py
decode_py
_pgdorm::decode_py->_pgdorm
_pgdorm::hydrate
hydrate
_pgdorm::hydrate->_pgdorm::convert
_pgdorm::hydrate->_pgdorm::decode_py
_pgdorm::hydrate::nested
hydrate::nested
_pgdorm::hydrate::nested->_pgdorm::convert
_pgdorm::hydrate::table
hydrate::table
_pgdorm::hydrate::table->_pgdorm::convert
_pgdorm::listen->_pgdorm
_pgdorm::pool::tx
pool::tx
_pgdorm::pool::exec->_pgdorm::pool::tx
_pgdorm::pool::tx->_pgdorm::hydrate
_pgdorm::query
query
_pgdorm::pool::tx->_pgdorm::query
_pgdorm::query::insert_select
query::insert_select
_pgdorm::query->_pgdorm::query::insert_select
_pgdorm::query::specs
query::specs
_pgdorm::query::insert_select->_pgdorm::query::specs
_pgdorm::query::compose
query::compose
_pgdorm::query::compose->_pgdorm
_pgdorm::query::joins
query::joins
_pgdorm::query::specs->_pgdorm::query::joins
_pgdorm::query::joins->_pgdorm::expr
_pgdorm::query::joins->_pgdorm::query::compose
Size & complexity budget
AGENTS.md asks for focused modules of about 150–350 lines. tools/archmap/budget.toml turns that into a ratchet, and tests/architecture/test_archmap.py enforces it:
a new file must stay within 350 lines, and a new function within a cognitive complexity of 15;
existing overruns are grandfathered at their current size and must not grow;
python tools/archmap update only ever lowers a cap, so paid-down debt stays paid. Adding new debt takes an explicit --accept-new-debt, which shows up in review as a budget.toml diff.
File size: 31 Python modules and 18 Rust files are over the 350-line budget.
Cognitive complexity: 33 Python functions score over 15.
Grandfathered functions (cognitive-complexity caps)
Grandfathered files (line caps)
Hotspots
Size alone doesn't say where refactoring pays off. Following Adam Tornhill's Your Code as a Crime Scene , a hotspot is code that is both complex and changed often. The score multiplies the number of commits touching a file (following renames) by its total cognitive complexity, or by its line count for Rust. Hotspots move with every commit, so they are not committed here. Run the ranking locally instead:
uv run --no-sync python tools/archmap hotspots
Commands
# Check the import contracts (add --verbose to see every import chain)
uv run --no-sync lint-imports
# Browse and drill into the import graph in your browser (adds uvicorn for this run only)
uv run --no-sync --with uvicorn import-linter explore pgdorm
# Re-render stale diagrams, refresh snapshot.json + this page, and tighten budget.toml
# (needs Graphviz: `brew install graphviz`; cargo-modules for the Rust module maps)
uv run --no-sync python tools/archmap update
# Fail on stale diagrams, a stale snapshot or budget overruns (--rust also re-checks the cargo-modules maps)
uv run --no-sync python tools/archmap check --rust
# Rank refactoring hotspots: commits x cognitive complexity
uv run --no-sync python tools/archmap hotspots