Code Architecture¶
How the genesis_mesh package is put together, which way its imports may
point, and where a change goes. The layer table below is the one
genesis_mesh/tests/test_architecture.py enforces; keep the two in step.
For the protocol’s concepts, see Architecture.
Package map¶
Protocol core (usable without the Network Authority)
Package |
Holds |
|---|---|
|
Strict JSON input for signed records and request bodies (refusal reasons shared with every SDK) |
|
Pydantic records and pure helpers (canonical JSON, digests, freshness); |
|
Ed25519 keys, signing, admin and node request signatures |
|
Protocol logic, |
|
Multi-step orchestration over |
Network Authority (na_service/)
Module |
Holds |
|---|---|
|
Composition root: |
|
|
|
One Flask blueprint per feature: parse, authenticate, rate-limit, call a service |
|
Application logic per feature (evidence store, out-of-band, remediation, grants, edge, audit packs, boundary policy, key history, agreements) |
|
|
|
Request signatures, the error envelope, rate limits, the signing key |
|
Operator pages, the surface catalog ( |
Tools and the rest
Package |
Holds |
|---|---|
|
The |
|
Logging and redaction, the node’s audit log, process-level mediation, JOSE/SPIFFE/VC bridges |
|
The mesh node runtime. Dormant (0007: Dormant core packages are internal): no new features, and new work does not build on them without a decision. They are not listed in the public contract, but they still back stable surfaces: the |
Outside the package: conformance/ (vector generators, the runner, the
vectors the SDKs copy), contract/public-surface.json (the classified public
surface), scripts/ (release, upgrade rehearsal, smoke), interop/ (the
four-language scenario), changelog.d/ and upgrade.d/ (fragments folded at
release).
Layers¶
Lowest first. A module may import its own layer and every layer listed
before it, except routes, which have their own list. Imports under
if TYPE_CHECKING: are type-only and not counted.
Layer |
Modules |
May import |
|---|---|---|
foundation |
|
foundation |
models |
|
foundation |
crypto |
|
models, foundation |
trust |
|
crypto, models, foundation; not another trust module |
peripheral |
|
trust and every layer before it |
workflows |
|
peripheral and every layer before it |
na_service |
the rest of |
workflows and every layer before it |
services |
|
na_service and every layer before it |
routes |
|
only routes, services, na_service, models, foundation |
composition |
|
routes and every layer before it |
cli |
|
every layer |
Two more rules:
No trust module imports another. A trust module is
trust/<name>.pyor a packagetrust/<name>/; a trust→trust import signals a missing abstraction (thetrustpackage itself may re-export).Route files make no database calls. A route calls a service method;
<anything>.dbinna_service/routes/is a database call.
The violations of 2026-10-16 are allowlisted in the test (25 layer edges,
27 trust→trust edges, 114 database calls in 14 route files). The test fails
on a new violation and on an allowlisted one that is gone, so the lists only
shrink. The one import cycle between cli and na_service is
operator_console/rendering.py reading the Click tree for the
/cli-reference page; it stays allowlisted until the CLI reference is generated.
Request flow¶
flowchart LR
client["client / SDK"] --> route["routes/<feature>.py<br/>auth, rate limit, strict JSON body"]
route --> service["services/<feature>.py<br/>NA rules"]
service --> trust["trust/*<br/>verify, sign"]
service --> db["db_*.py mixins<br/>SQLite / PostgreSQL"]
service --> evidence["services/evidence_store.py<br/>append evidence"]
trust --> models["models/*"]
route --> errors["errors.py<br/>error envelope"]
app_factory.build_app(NASettings)(used bygenesis-mesh na startandwsgi.py) orserver.create_app()buildsNetworkAuthorityService, which constructs the services and registers every blueprint.A route checks the rate limit and the caller (
auth.py: admin or node request signatures), reads the body witherrors.request_json_object()(which parses withstrict_json) and validates it into a model.The route calls one service method. The service applies the NA’s rules, verifies and signs through
trust/*, reads and writes throughservice.db, records audit events and appends evidence.A refusal raises an
ApiErrorsubclass with a stable code;errors.pyrenders the envelope with the request ID.
The CLI parses options in cli/* and calls trust/* offline or a workflow;
calls to a Network Authority go through workflows/remote.py. The SDKs read
the same records and refuse the same input: the conformance vectors pin both
sides.
Where a change goes¶
Each recipe lists the files to touch and the test that fails when one is
missed. Where no test catches a miss, it says so; review checks those.
Every user-visible change also adds a changelog.d/<version>/ fragment, and
an operator step an upgrade.d/<version>/ fragment.
An HTTP route¶
na_service/routes/<feature>.py: the blueprint; a new file is registered inroutes/__init__.pyandserver.py(_register_blueprints).na_service/services/<feature>.py: the logic, exported fromservices/__init__.pyand constructed inserver.py.operator_console/surfaces.py: the route’s surface entry.contract/public-surface.json(route, level, new error codes), thenpython scripts/render_public_contract.py.Docs:
docs/api/trust-http.mdordocs/reference/network-authority-api.md, anddocs/stability.mdfor a new surface.
Fails when missed: test_na_public.py::test_surface_catalog_lists_every_registered_route,
test_public_contract.py (test_every_http_route_is_classified_with_its_methods,
test_every_error_code_is_listed, test_rendered_contract_page_is_current),
test_architecture.py (a route importing trust/crypto or calling
.db). Docs: no test.
A setting¶
na_service/settings.py: theNASettingsfield and its parsing inload_settings().na_service/app_factory.py(build_apppasses it),server.py(create_app,NetworkAuthorityService.__init__: parameter, docstring, validation).docs/reference/configuration.md.
Fails when missed: nothing. A missed pass-through silently keeps the
default, so add a test that builds the app from the variable and observes
the NA, as
test_local_governed_na.py::test_build_app_trusts_exactly_the_configured_proxies
does.
A database migration¶
na_service/migrations/NNN_<name>.sql, numbered next after the highest, andNNN_<name>.postgres.sqlwhen PostgreSQL needs other SQL.The
db_<area>.pymixin (a new one joinsNADatabase’s bases indb.py).scripts/upgrade_rehearsal.pywhen the rehearsal must exercise the new table;upgrade.d/<version>/<name>.mdfor the operator.
Fails when missed: test_migration_numbering.py (duplicate, gapped or
unnumbered files fail at load), the PostgreSQL job (dialect differences),
“Upgrade rehearsals” (an upgrade from every supported version).
An evidence record kind¶
About 14 registration points today (a kind registry is planned in
ops/plan-architecture.md, Track 2):
models/evidence_store.py(EntryKind) and the kind’s model;models/canonical_registry.py(signed models,OMIT_WHEN_NONE);models/key_succession.py(NA_RECORD_TIME_FIELDS).trust/evidence_store.py(kind tables and the verifier’s branch).na_service/services/evidence_store.py(retention),services/audit_pack.py,workflows/audit_pack.py.A migration when the entry-kind constraint changes (both dialects).
scripts/export_reference_corpus.py; the conformance generator, thenpython conformance/generate_vectors.py field_registry.contract/public-surface.json,docs/schemas/gm.evidence.event.v1.json,docs/reference/evidence-event-schema.md; the SDK verifiers.
Fails when missed: test_canonical_registry.py
(test_the_committed_registry_matches_the_models,
test_entry_kinds_are_the_models), test_conformance.py,
test_public_contract.py::test_every_signed_model_is_classified. A missed
retention or audit-pack table is not caught by a dedicated test.
A gate type¶
A class implementing
ConfiguredGateTypeand its entry inBUILTIN_GATE_TYPES(trust/context/registry.py); docs and tests.
Fails when missed: a policy naming a gate type that is not installed is
refused (unknown_gate_type), so the gate’s own tests fail. This is the
seam to copy.
A CLI command¶
cli/<domain>_ops.py; a new top-level group is added incli/ops.py(register_operational_commands) orcli/main.py.contract/public-surface.json(cli_commands), thenpython scripts/render_public_contract.py;docs/reference/cli.md.Logic beyond parsing goes in
workflows/(never imported back byworkflows/).
Fails when missed: test_public_contract.py::test_every_cli_command_is_classified
and test_rendered_contract_page_is_current; test_architecture.py
(workflows importing cli). cli.md: no test.
A conformance suite¶
A generator (
conformance/generate_vectors.pyorconformance/<suite>_vectors.py) andconformance/vectors/<suite>.json.A runner in
conformance/runner.py(SUITE_RUNNERS);conformance/CONFORMANCE.md.cmplines in.github/workflows/interop.ymland the copies and harnesses in the SDKs.
Fails when missed: test_conformance.py (a registered suite with no file
or a failing vector). A vector file with no runner is not run: register it.
An error code¶
The code at the raise site (
raise ConflictError(..., code="...")), or a newLiteraltype added topublic_contract_support.error_codes().contract/public-surface.json(error_codes), the rendered contract page, and the route’s docs.
Fails when missed: test_public_contract.py::test_every_error_code_is_listed.
A code built at run time escapes the scan: write it as a literal.
Node runtime internals¶
The dormant mesh node runtime’s internals (control plane, runtime dispatch, transport connections) are on their own page.