Skip to main content

System Architecture

One Health is a patient-centric care network composed of independently deployable services that communicate via HTTP + JWT, share immutable schemas through a versioned contracts package, and persist to a single MongoDB Atlas cluster.

Block diagram — services + responsibilities

Service-by-service responsibility matrix

ServicePortLanguageOwnsDoes NOT own
apps/web6200Next.js 15 / React 19UI, MSAL + GIS auth bootstrap, session-cookie validation at edgeBusiness logic, encryption, DB access
apps/api6201NestJS 10 / TypeScript strict22 modules of business domain, envelope encryption at repo boundary, CSRF, rate limiting, RBAC + consent guards, hash-chained auditUI rendering, LLM calls, retrieval
apps/ml6202FastAPI / Python 3.12 / Pydantic v2ASR + NER + CDS + Coding AI; sanitize → delimit → de-ID → schema-validate → audit pipeline; dual-LLM with audited fallbackPHI at rest (all PHI lives in api's DB)
memory-store6401FastAPI / motorKnowledge graph CRUD, hybrid retrieval (4 routes + classifier + serializer + audit), MCP server for Claude CodeAgent orchestration
research-engine6402FastAPI / motor5 agents (Researcher / Critic / Correlator / Replicator / Librarian), 12 trusted-source connectors, change-stream promotion pipelineData persistence (uses memory-store HTTP)
orchestrator6403FastAPI / motorHypothesis candidate lifecycle (6 phases), feasibility scoring, stakeholder approval, dispatch schedulingLLM calls (delegates to research-engine)
model-optimization6404FastAPI / motorDecision graph (15 node types), trace capture, DPO pair builder, outcome feedback, benchmark harnessNone (read-only consumer of other tiers' audit trails)

Deployment topology

Cross-service comms — inviolable rules

  1. HTTP + JWT only (FR-KIA-012). No shared database connections, no direct Python imports across services, no message-bus short-circuits.
  2. Shared schemas through packages/patientrx-contracts/ only. Single canonical source; no duplication. Published as contracts-v1.0.0 to GitHub Release + local mirror. See the consolidation PR #167 for how we eliminated the duplicate tree.
  3. Every inter-service call is audited on the caller side with {source, target, action, latency, outcome}.
  4. Failures fail-soft with audit trail — LLM fallback (FR-021a), retrieval fallback (SPEC-06), consent-service-unavailable → 500 with generic body.
  5. Rate limits per-consumer — the retrieve endpoint is 100/min; consumers use admin-token bypass for batch workloads.

What sits outside the diagram

  • GitHub Actions CI — 10+ required checks per PR (gitleaks, Semgrep, Trivy, npm-audit, pip-audit, group3-contract-tests, pattern-consistency, docs-coverage, mandatory-hooks-checklist, compliance-checklist)
  • Claude Code harness — 11 pre-edit / pre-bash / stop hooks at the developer's environment layer that block known anti-patterns at authoring time
  • BAA registryapps/api/src/config/baa-registry.yml; every outbound vendor registered + fail-closed on unsigned in prod

Deeper