Standards, Contracts & Extending
Thanks for helping the Astronaut Health Intelligence Platform (AHI). This page covers the contracts and conventions every change follows, and recipes for the most common changes.
Before you push
Setup and every command are in Setup, commands and troubleshooting. Before you push, run inside frontend/web:
npx tsc -b # typecheck
npm test # vitest: engine unit and scenario tests
npx vite build # production buildIf you changed engine rules or the simulator, also run npm run evaluate and commit the regenerated src/engine/evaluation.json and docs/model-card.md. The same checks run in CI (Documentation and deployment).
If you rebuilt the 3D atlas, also run npm run anatomy:validate. The files in public/anatomy/ are under CC BY-SA 4.0, not MIT: keep LICENSE.md next to them (3D anatomy assets).
Dev only pages served by npm run dev: /anatomy-lab.html (every visual state of the 3D body, layers, structure selection and the forced fallback) and /features-lab.html. In development the store is also exposed on window.__ahi for poking scenarios from the console. Where each file lives: Project structure.
Contracts
domain.tschanges are additive only. Add optional fields or new union members; never rename or remove a field other modules use. Mark additions with a short comment (the file uses "Additive (v2)").- The engine stays pure. No DOM, no React, no network in
src/engine/. It must run headless (the evaluation script does exactly that). - The store publishes only changed slices. If you add a slice, give it an engine version so unchanged data keeps its object reference.
- Adapters return canonical observations. Nothing downstream of an adapter knows which device produced a record.
Conventions
| Rule | Why |
|---|---|
| UI text in English, plain language first, technical term second | International judging; crew readability |
| No em dash or en dash characters anywhere: UI strings, docs, comments, commits. Use a period, comma, colon or parentheses | Project writing rule |
Every record carries data_origin; device data is SIMULATED and the UI always shows the badge | Transparency |
Missing data is null and becomes NO_DATA / DATA_STALE, never zero and never normal | Safety |
Fixed thresholds live only in src/engine/config.ts, labeled "demo configuration, not an official limit" | No invented NASA limits |
| No diagnosis, no medication, no treatment advice in any text | Decision support only |
| Status always combines color, icon and words | Accessibility |
Engine logic has vitest tests (*.test.ts next to the code) | Rules are the product |
npx tsc -b passes: erasableSyntaxOnly (no enum, no parameter properties) and noUnusedLocals are on | Build hygiene |
A quick check for forbidden dashes:
grep -rnP '\x{2014}|\x{2013}' --include=*.ts --include=*.tsx --include=*.md --exclude-dir=node_modules .Add a metric
- Contract: add the code to the
MetricCodeunion insrc/types/domain.ts(additive). - Catalog: add a
MetricDefinitioninsrc/engine/catalog.ts: label, short label, canonical unit, region, decimals, bad direction, a plain-language one liner and a display range (a chart range, never a clinical limit). - Rules: add a
METRIC_RULESentry insrc/engine/config.ts(continuous or event, context bucketed or not,minScale, acute and drift flags,staleMin, cadence, rule id). Add it toASTRONAUT_METRICSorCABIN_METRICS, and toFORECAST_METRICSif it should be projected. - Source: make an adapter emit it (see below).
- Recommendation: add a catalog entry for its rule id in
src/engine/recommendations.ts(title, why, audience, region, intervention kind, autonomy if it differs from the audience default). - Tests: cover the new rule in the engine tests; run
npm testandnpm run evaluateto check nominal false alerts stay at zero. - UI: the region detail, vitals and FHIR export pick metrics from the catalog. Add a LOINC code in
src/lib/fhir.tsonly if it is well established.
Add a device adapter
Adapters live in src/engine/sim/adapters.ts and implement DeviceAdapter: id, kind, name, assignedTo, metrics, read(simNow) returning HealthObservation[], optional readEvents(from, to) for daily backfill, and status(simNow) (state, battery, signal).
- Extend
BaseAdapterand build observations withmakeObservation(...)sodata_origin, quality and activity context are always set. - Model device behavior honestly: cadence,
DEGRADEDsignal withQUESTIONABLEvalues,DATA_STALE,OFFLINE. - Register it in the engine constructor (
src/engine/engine.ts, next to the otheraddAdapter(...)calls). - If it is a new kind, add it to
DeviceKindindomain.tsand describe its real counterpart and the path to real data insrc/features/datasources/DevicesTab.tsx.
A real adapter (file import or live feed) follows the same contract with data_origin: 'REAL_PUBLIC' (or MANUAL) and a filled source_reference. Nothing downstream changes.
Add a scenario
- Add the id to
ScenarioIdindomain.tsand aScenarioDefinition(name, description, target) toSCENARIOSincatalog.ts. - In
src/engine/sim/scenarios.ts, add its timing toSCENARIO_TIMINGand a severity function (0 to 1 over time from the scenario start). Feed it into the scenario effects thatsim/physiology.ts(body) orsim/cabin.ts(cabin) consume. - If an intervention should ease it, add a hypothetical relief entry (clearly a simulation device, never a clinical claim).
- Add it to the scenario list in
scripts/evaluate.ts(simulated hours and evaluation step), runnpm run evaluate, and document the timings in Demo scenarios and Results.
Add or rename an anatomical structure
The 3D atlas is generated. Never edit public/anatomy/*.glb or manifest.json by hand: change the rules and rebuild (3D anatomy assets).
- Rule: in
frontend/web/scripts/anatomy/export_atlas.py, edit the rule function of the system (rule_skeletal,rule_muscular,rule_cardio,rule_nervous,rule_visceral). A rule matches source objects by name and by their ancestor labels and returns the structure id, display name, system and tissue class. - Naming: follow the naming rules: kebab-case English anatomical ids, the side in the id for paired structures, ids stable between builds.
- License check: never add content from the two non commercial upstream models (ear, kidney), and keep the reproductive structures out (neutral reference body).
validate.mjsfails the build if one slips in. - Rebuild:
npm run anatomy:build -- --previews(needs Blender 4.5 LTS). Read the log for unmatched objects and dropped structures, and look at the preview sheets. - Renaming an id is a breaking change. If it is one of the seven required ids (
REQUIRED_STRUCTURE_IDSinsrc/features/anatomy/atlas/types.ts), the viewer, the validator and the tests rely on it: avoid it. For any other id, check the patterns inatlas/health.ts(brain structures are recognized by id) and bumpversionin the manifest writer (optimize.mjs). - Verify:
npm run anatomy:validate,npm test(the manifest contract test reads the real files) and a look at/anatomy-lab.html. - Document: update the numbers in 3D anatomy and, if the mapping changed, the mapping table.
A new tissue class needs three coordinated changes: the TissueClass union in atlas/types.ts, a material in TISSUE (viewer/tissueMaterials.ts) and the TISSUES list in validate.mjs.
Map a structure to a region
Which body region a structure reports under is decided in one file: src/features/anatomy/atlas/health.ts. The manifest never carries health rules.
- Check that a metric really relates to it. A structure may map to a region only if a metric of the catalog describes that body system. If nothing measures it, leave it context only. Do not map a structure just to give it a color.
- Edit
regionOfStructure(). The rules go by anatomical system and tissue class (for example the urinary system maps tokidneysonly for tissuekidney), not by a list of ids. - Say how the indicators relate. Update
REGION_RELATION(what the numbers are based on, and what they are not) andSYSTEM_INFO(coverage: monitored, partial or context) in plain, non diagnostic language. - Never list metrics in the mapping. Metrics come from
METRIC_CATALOGby region. To relate a new indicator, add a metric with the rightregion. - Tests: extend
atlas/health.test.ts(by rule) and runmanifest.contract.test.ts, which applies the rules to the real atlas. - Document: update the canonical mapping table.
A new body region is a contract change: add it to BodyRegionId in domain.ts (additive), to REGION_LABELS in the catalog and to REGIONS in src/features/anatomy/regions.ts.
Add a real dataset
Follow Pipeline, normalization and quality: discovery, fitness report, download into data/raw/<ACCESSION>/, manifest with SHA-256 in data/manifests/, a text only parser, the quality checklist, canonical output in data/processed/, a compact UI file in frontend/web/src/data/, and an entry in docs/data-source-inventory.md.
- Use the OSDR scripts in
frontend/web/scripts/osdr/as the model (allow listed hosts, files treated as untrusted data). - Label it
REAL_PUBLIC, keep it out of the simulated crew, and never use lab ranges as alert limits. - Show it in the Data and model dialog with full provenance.
Commits and pull requests
- Small, focused commits with an imperative subject ("Add hydration forecast").
- Describe what changed for the user and what was verified (typecheck, tests, build, evaluation).
- No em or en dash characters in commit messages either.