05 — Engineering standards
BuiltRendered from 05-engineering-standards.md in the public repository. Edits belong there.
Where code belongs in MiCyte, which way imports may point, and the tests and budgets that enforce both.
Layers
| Layer | Paths | Contents |
|---|---|---|
| L1 core | micyte/core/ | Pure domain logic: datum documents, the address, hyphae and MSS engine (micyte/core/datum_semantics/engine.py), archetypes. No I/O |
| L2 ports | micyte/ports/ | Contracts: dataclasses and Protocols that describe what a store or service provides |
| L2 adapters | micyte/adapters/ (sql, filesystem_datum, commerce, hosted) and the host application's adapters | Implementations of ports |
| L3 | micyte/tools/, micyte/state_machine/, micyte/channels/, micyte/automation/, and the host application | Tools, shell state, the Flask host and the JS shell |
The host application is fnd_app/. It is not part of the public repository.
Dependency direction
Imports point inward:
tools / state_machine / host (L3)
│ may import
▼
adapters (L2, implement ports)
│ may import
▼
ports (L2, contracts)
│ may import
▼
core (L1)coreimports only the standard library andcore.adaptersimportportsandcore, never tools or the host.portsimport only the standard library andcore.- Only L3 wires concrete adapters to ports.
micyteimports nothing from the host application.
One exception to rule 1 exists: micyte/core/instance_baseline.py imports DocumentRequirement from micyte.ports.tool_package.
Enforcement
Architecture tests in fnd_app/tests/architecture/ parse each .py file in a package with ast and fail on a forbidden import:
| Test | Holds |
|---|---|
test_core_datum_ops_boundaries.py, test_core_datum_refs_boundaries.py, test_core_datum_rules_boundaries.py | These core packages import only the standard library and micyte.core |
test_state_machine_boundaries.py | micyte/state_machine imports only core and itself |
test_datum_store_port_boundaries.py, test_filesystem_adapter_boundaries.py | The store port and its adapters |
test_micyte_fnd_boundary.py | micyte does not import the host application, transitively |
test_micyte_carries_no_hosting_business.py | micyte contains no host's client relationships, price lists or account tooling |
test_no_duplicate_definitions.py, test_canonical_document_naming.py | No copied definitions; one document naming scheme |
Each import test has the same shape: a PACKAGE_DIR, a FORBIDDEN_IMPORT_PREFIXES tuple, an allowlist function, and an ast.walk over Import and ImportFrom nodes that collects violations into a list asserted empty. A new layering rule ships with a test in this shape.
One implementation per concept
- The address, hyphae and MSS engine has one home,
micyte/core/datum_semantics/engine.py.micyte/core/mss/datum_identity.pydelegates to it. - Reuse an existing module before adding one.
- Delete a stub nothing calls, or leave a one-line comment naming its caller.
Caching
Measure before optimizing. The common document is small.
_GLOBAL_CATALOG_CACHEinmicyte/adapters/sql/datum_store.pyholds the loaded catalog per(db_path, tenant_id), at most two entries, until the store's memo stamp (the database file's mtime and a door version) changes.SqliteSystemDatumStoreAdapter.replace_single_document_efficientin the same file replaces one document without re-encoding the others. Use it when a write touches one document.
Tests
| Directory | Holds |
|---|---|
micyte/tests/ (unit, contracts, adapters, architecture) | The public suite: tests of micyte.* alone, run by the public repository's CI |
fnd_app/tests/unit/ | One module at a time |
fnd_app/tests/integration/ | Components wired together |
fnd_app/tests/architecture/ | Layering, boundary, duplication and asset-manifest rules |
fnd_app/tests/contracts/ | Port contract conformance |
fnd_app/tests/adapters/ | Adapters against fakes and real stores |
fnd_app/tests/e2e/ | The portal booted against a provisioned instance |
fnd_app/tests/smoke/ | Pages render and serve |
The full suite is run in memory-capped batches by scripts/health_gate.sh. CI runs .github/workflows/tests.yml. The architecture guards alone:
python -m pytest fnd_app/tests/architecture -qFront-end budgets
The portal shell's JavaScript and stylesheet are held to gzip byte caps, declared as PORTAL_SHELL_*_BUDGET_GZIP_BYTES in the host and in benchmarks/budgets/optimization_budgets.json:
| Budget | Cap | Enforcement |
|---|---|---|
| Initial load | 375,000 | Hard |
| Total | 415,000 | Hard |
| Deferred tool renderers | 40,000 | Advisory |
scripts/benchmarks/check_optimization_budgets.py gzips the shipped files, compares them to the caps, and fails if the two declarations disagree. test_asset_manifest_module_presence.py asserts that every manifest entry is a real file, that module ids are unique, and that no v2_portal_*.js file ships unregistered. test_optimization_budget_measurement.py asserts that the checker measures the real files.
Each shell module declares a budget_group (initial_shell or deferred_tool_renderers). Put anything not needed for first paint in the deferred group.
Checklist before a pull request
- New code is in the layer that owns the concern.
- No import points outward.
- No second implementation of something that exists.
- No orphan stubs or unregistered
v2_portal_*.jsfiles. - No new on-disk datum authority; MOS is canonical and YAML is transport only.
- A new layering rule has its architecture test.
- New or grown shell modules are in the right
budget_groupand within budget. - Pages that describe the changed code are updated in the same change.