Skip to content

Architecture

A single aiohttp process serves the browser app, a JSON API and two WebSocket speech paths. State lives in one SQLite file with an append-only, hash-linked audit table.

flowchart LR
  B[Browser<br/>app/web] -->|JSON API| H[async_server.http]
  B -->|/api/realtime WS| R[Sarvam cascade]
  B -->|/api/gemini_live WS| G[Gemini Live native audio]
  H --> S[(Store<br/>SQLite + audit chain)]
  R --> V[voice.Voice]
  G --> F[gemini_live.answer_turn<br/>interpreter + policy]
  V --> S
  F --> S
  S --> O[Operation registry]
  O --> K[knowledge]
  O --> P[participants]
  O --> E[encounter.operations]
  E --> C[encounter.compiler]

Modules

Module Responsibility
app/core.py Store: transactions, tenant-scoped objects, audit writes, check_case gate. execute wraps every operation in a savepoint and audits success or denial atomically.
app/knowledge.py Authorized source ingestion, recommendation review, immutable releases, revocation, scoped retrieval.
app/participants.py Self-reported beta participant profiles (not authentication).
app/encounter/operations.py Encounter start and one-action-at-a-time act with epochs and idempotency.
app/encounter/compiler.py Compiles authored case JSON into an immutable, hashed version; review-gate policy.
app/encounter/interpreter.py Turns an utterance into one typed action (Gemini; keywords when no model is configured; fact questions fail closed when a configured model is down) and validates it against a closed action set and the case catalogue.
app/encounter/turns.py Interprets outside the DB transaction, discards client-supplied actions, then commits via act.
app/encounter/policy.py Pure disclosure policy: available facts, next level per fact, delivery bookkeeping. Shared by all three paths.
app/lexicon.py Colloquial expression lexicon, cue detection and clarification links.
app/transcript_checks.py Language-drift flags, transcript normalization and recognition-doubt checks for spoken input.
app/encounter/teaching.py Teaching/assessment mode, the three-rung hint ladder and assistance history.
app/encounter/variants.py Surface variants, next-exercise recommendation and attempt accounting.
app/encounter/workflows.py Morning Report, Tumor Board and Clinic Day stages: allowed actions, required reasoning, per-stage reviews.
app/encounter/reasoning.py Explicit reasoning controls and the reasoning history shown in session review.
app/encounter/improviser.py Bounded improvisation for unscripted questions: permitted negatives, everyday details, unknown; validator and pinning.
app/improvisations.py Reviewer queue for improvised answers: promote, allow negative, forbid.
app/encounter/services.py Examination and investigation services: synonym normalization, granularity rule, compound-order confirmation, distinct unavailable/ambiguous replies.
app/encounter/attendant.py Plans attendant lines (direct answers or authored interjections) and commits them as separately attributed events.
app/languages.py Per-language provider codes, script, spoken-register rule, Hindi-source realization note and wrong-script check.
app/encounter/speech_plan.py Per-turn speech plans (latency, disfluency budget, answer shape, certainty, markers), the realization guard, clause segmentation and session speech statistics.
app/encounter/prosody.py Per-turn emotion, pace and temperature within the persona's range; reversible within-response pauses for speech.
app/demo.py Bundled case library and catalogue.
app/voice.py Request/response voice path (Gemini by default, Sarvam fallback): model selects at most one fact ID, policy checks it, model realizes only that fact; TTS; playback reports; budgets.
app/gemini_live.py Gemini Live path: one answer_trainee tool. The server interprets its own transcript of the learner's words, applies the policy and returns only permitted wording plus a delivery note (or guidance). One fact per turn; disclosure only after confirmed playback.
app/authoring.py Versioned faculty authoring, explicit persona dimensions, reviewer approval and the authored-case catalogue.
app/annotations.py Blind expert annotation tasks, blinding audit and the agreement report.
app/agreement.py Credit confusion, safety sensitivity, ICC(A,1), weighted kappa and cluster-bootstrap intervals.
app/dashboards.py Reviewer case-by-skill and learner-by-skill matrices, trajectories and drill-down to evidence.
app/records.py Formative-only marking and export, transcript retention sweep, learner appeals and reviewer resolution.
app/retrieval.py Spaced factual retrieval: cards from finished cases, Leitner scheduling, separate history.
app/evidence.py Evidence records for assessable opportunities and the diagnostic-kernel chain, from delivered events only.
app/progress.py Practice score, attempt kinds, per-specialty progress series with filters, and the evidence-banded debrief.
app/specialties.py Specialty tracks and the fallback lookup for encounters pinned before cases named a specialty.
app/observers.py Deterministic observers across nine anchor domains, critical-action rules, degraded-audio suspension and reconciliation with semantic claims.
app/compare.py Matched comparison with scripted and prompt-only baselines.
app/encounter/conditions.py Evaluation conditions and their assignment.
app/gating.py Pre-speech gate: Clef, Clef-flash, Jev, MuRIL and lexicon adapters, circuit breaker, shadow routing.
app/gating_eval.py Labelled gate evaluation set and per-model, per-language metrics.
app/gemini_speech.py Gemini realization, recorded-turn transcription and TTS with pause tags; PCM to WAV.
app/verbatim_tts.py Verbatim TTS for checked sentences on the Live path (Gemini 3.8 TTS, Sarvam fallback).
app/consistency.py Adversarial consistency suite and case-version blocking.
app/session_feedback.py Semantic (Gemini) observer: domain-tagged claims that must cite reliable events; attached as annotations by observers.reconcile.
app/history_store.py Session review and opt-in, expiring audio storage.
app/access.py Trial codes exchanged for expiring scoped sessions; separate docs-only sessions.
app/docs_site.py Serves the built docs at /docs behind DOCS_ACCESS_PHRASE with an HttpOnly, SameSite=Strict cookie and a docs-scoped CSP.

Trust boundaries

  • Patient realizer sees: opening, persona speech style, and only the current level of a permitted patient-voice fact. Never truth, ddx, kernel, unsafe, actions, closure, assessment, review, or a fact's clinical note. Enforced by tests in test_case_compiler.py.
  • Assessor (feedback, future observers) sees the clinical truth after the encounter ends.
  • Learner text is treated as data in every model prompt. The interpreter can only return a closed set of action types and fact ids from the current catalogue; anything else becomes unclear.