# wefrdstho/hearth-ai architecture

> Architecture diagram of the GitHub repository wefrdstho/hearth-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wefrdstho/hearth-ai
- Repository: https://github.com/wefrdstho/hearth-ai

## Overview

HEARTH is a research system for turning patient-authorized voice or text conversations into longitudinal context that clinicians can review. The main path runs from patient input through session orchestration, perception, safety and cognitive analysis, then memory and response generation; clinician-facing synthesis and review are related capabilities. The README documents the app and workspace, but their implementation files are not present in the supplied tree. Arrows are limited to relationships shown in excerpts or explicitly documented in the README; other wiring is not inferred.

Main entry points: [`backend/app/services/session_orchestrator/pipeline.py`](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/session_orchestrator/pipeline.py) (Session Pipeline), [`backend/app/main.py`](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/main.py) (Backend API), [`backend/app/services/llm_service.py`](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/llm_service.py) (LLM Adapter), [`apps/patient_app`](https://github.com/wefrdstho/hearth-ai/tree/main/apps/patient_app) (Patient App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Patient and Clinician Experience"]
  node_patient["Patient App"]
  node_clinician["Clinician Workspace"]
end

subgraph group_api_security["API and Authorization"]
  node_api["Backend API<br/>[main.py]"]
  node_auth["JWT Authorization<br/>[auth.py]"]
  node_consent["Consent and Access"]
end

subgraph group_conversation["Conversation Processing"]
  node_session["Session Pipeline<br/>[pipeline.py]"]
  node_perception["Input Perception"]
  node_safety["Safety Evaluation<br/>[safety_engine.py]"]
  node_signals["Signal Extraction"]
  node_interpretation["Observation Rules"]
  node_speech["Speech Services<br/>[speech_service.py]"]
end

subgraph group_cognition["Memory and Intelligence"]
  node_decision["Understanding Decisions"]
  node_memory[("Semantic Memory")]
  node_policy["Conversation Policy"]
  node_reasoning["Reasoning Service<br/>[service.py]"]
  node_llm["LLM Adapter<br/>[llm_service.py]"]
  node_runtime["AI Runtime"]
  node_clinical["Clinical Intelligence"]
  node_story["Story Compiler"]
end

subgraph group_persistence["Persistence and Learning"]
  node_datasets["Dataset Review<br/>[review_service.py]"]
  node_database[("Application Database<br/>[database.py]")]
end

node_patient_actor(("Patient"))
node_clinician_actor(("Clinician"))
node_ollama["Ollama"]

node_patient_actor -->|"uses"| node_patient
node_patient -->|"sends turns"| node_api
node_clinician_actor -->|"uses"| node_clinician
node_clinician -->|"reviews context"| node_api
node_api -->|"authenticates"| node_auth
node_auth -->|"checks access"| node_consent
node_api -->|"routes sessions"| node_session
node_session -.->|"processes input"| node_perception
node_session -->|"evaluates safety"| node_safety
node_session -->|"extracts signals"| node_signals
node_signals -.->|"provides signals"| node_interpretation
node_session -.->|"evaluates understanding"| node_decision
node_decision -.->|"compares memories"| node_memory
node_session -->|"indexes and retrieves"| node_memory
node_session -.->|"uses policy"| node_policy
node_session -->|"generates response"| node_llm
node_llm -->|"builds prompt"| node_reasoning
node_llm -->|"selects provider"| node_runtime
node_runtime -.->|"generates with"| node_ollama
node_session -.->|"supports voice"| node_speech
node_session -.->|"analyzes understanding"| node_clinical
node_session -.->|"compiles stories"| node_story
node_clinical -.->|"provides synthesis"| node_clinician
node_api -.->|"persists records"| node_database
node_clinician -.->|"reviews examples"| node_datasets

click node_patient "https://github.com/wefrdstho/hearth-ai/tree/main/apps/patient_app"
click node_api "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/main.py"
click node_auth "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/dependencies/auth.py"
click node_consent "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/access_control_service.py"
click node_session "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/session_orchestrator/pipeline.py"
click node_perception "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/perception/services/perception_service.py"
click node_safety "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/safety/engine/safety_engine.py"
click node_signals "https://github.com/wefrdstho/hearth-ai/tree/main/hearth_core/signal_extraction"
click node_interpretation "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/interpretation/rules/observation_rule_engine.py"
click node_decision "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/understanding_decision/rules/understanding_decision_engine.py"
click node_memory "https://github.com/wefrdstho/hearth-ai/tree/main/hearth_core/semantic_memory"
click node_policy "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/conversation_director/services/conversation_policy_service.py"
click node_reasoning "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/reasoning/services/service.py"
click node_llm "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/llm_service.py"
click node_runtime "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/ai_runtime/services/runtime_services.py"
click node_speech "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/speech_service.py"
click node_clinical "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/clinical_intelligence/services/clinical_intelligence_service.py"
click node_story "https://github.com/wefrdstho/hearth-ai/tree/main/hearth_core/story_compiler"
click node_datasets "https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/dataset_learning/review/review_service.py"
click node_database "https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/core/database.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_patient,node_clinician toneBlue
class node_api,node_auth,node_consent toneAmber
class node_session,node_perception,node_safety,node_signals,node_interpretation,node_speech toneMint
class node_decision,node_memory,node_policy,node_reasoning,node_llm,node_runtime,node_clinical,node_story toneRose
class node_datasets,node_database,node_patient_actor,node_clinician_actor,node_ollama toneIndigo
```

## Components

### Patient and Clinician Experience

- [Patient App](https://github.com/wefrdstho/hearth-ai/tree/main/apps/patient_app): `apps/patient_app`
- **Clinician Workspace**

### API and Authorization

- [Backend API](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [JWT Authorization](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/dependencies/auth.py): `backend/app/dependencies/auth.py`
- [Consent and Access](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/access_control_service.py): `backend/app/services/access_control_service.py`

### Conversation Processing

- [Session Pipeline](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/session_orchestrator/pipeline.py): `backend/app/services/session_orchestrator/pipeline.py`
- [Input Perception](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/perception/services/perception_service.py): `hearth_core/perception/services/perception_service.py`
- [Safety Evaluation](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/safety/engine/safety_engine.py): `hearth_core/safety/engine/safety_engine.py`
- [Signal Extraction](https://github.com/wefrdstho/hearth-ai/tree/main/hearth_core/signal_extraction): `hearth_core/signal_extraction`
- [Observation Rules](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/interpretation/rules/observation_rule_engine.py): `hearth_core/interpretation/rules/observation_rule_engine.py`
- [Speech Services](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/speech_service.py): `backend/app/services/speech_service.py`

### Memory and Intelligence

- [Understanding Decisions](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/understanding_decision/rules/understanding_decision_engine.py): `hearth_core/understanding_decision/rules/understanding_decision_engine.py`
- [Semantic Memory](https://github.com/wefrdstho/hearth-ai/tree/main/hearth_core/semantic_memory): `hearth_core/semantic_memory`
- [Conversation Policy](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/conversation_director/services/conversation_policy_service.py): `hearth_core/conversation_director/services/conversation_policy_service.py`
- [Reasoning Service](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/reasoning/services/service.py): `hearth_core/reasoning/services/service.py`
- [LLM Adapter](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/services/llm_service.py): `backend/app/services/llm_service.py`
- [AI Runtime](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/ai_runtime/services/runtime_services.py): `hearth_core/ai_runtime/services/runtime_services.py`
- [Clinical Intelligence](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/clinical_intelligence/services/clinical_intelligence_service.py): `hearth_core/clinical_intelligence/services/clinical_intelligence_service.py`
- [Story Compiler](https://github.com/wefrdstho/hearth-ai/tree/main/hearth_core/story_compiler): `hearth_core/story_compiler`

### Persistence and Learning

- [Dataset Review](https://github.com/wefrdstho/hearth-ai/blob/main/hearth_core/dataset_learning/review/review_service.py): `hearth_core/dataset_learning/review/review_service.py`
- [Application Database](https://github.com/wefrdstho/hearth-ai/blob/main/backend/app/core/database.py): `backend/app/core/database.py`

### Other components

- **Patient**
- **Clinician**
- **Ollama**

## Connections

- Patient → Patient App: uses
- Patient App → Backend API: sends turns
- Clinician → Clinician Workspace: uses
- Clinician Workspace → Backend API: reviews context
- Backend API → JWT Authorization: authenticates
- JWT Authorization → Consent and Access: checks access
- Backend API → Session Pipeline: routes sessions
- Session Pipeline → Input Perception: processes input
- Session Pipeline → Safety Evaluation: evaluates safety (evidence: `backend/app/services/session_orchestrator/pipeline.py`)
- Session Pipeline → Signal Extraction: extracts signals (evidence: `backend/app/services/session_orchestrator/pipeline.py`)
- Signal Extraction → Observation Rules: provides signals (evidence: `hearth_core/interpretation/rules/observation_rule_engine.py`)
- Session Pipeline → Understanding Decisions: evaluates understanding
- Understanding Decisions → Semantic Memory: compares memories
- Session Pipeline → Semantic Memory: indexes and retrieves (evidence: `backend/app/services/session_orchestrator/pipeline.py`)
- Session Pipeline → Conversation Policy: uses policy (evidence: `backend/app/services/session_orchestrator/pipeline.py`)
- Session Pipeline → LLM Adapter: generates response (evidence: `backend/app/services/session_orchestrator/pipeline.py`)
- LLM Adapter → Reasoning Service: builds prompt (evidence: `backend/app/services/llm_service.py`)
- LLM Adapter → AI Runtime: selects provider (evidence: `backend/app/services/llm_service.py`)
- AI Runtime → Ollama: generates with
- Session Pipeline → Speech Services: supports voice
- Session Pipeline → Clinical Intelligence: analyzes understanding
- Session Pipeline → Story Compiler: compiles stories (evidence: `backend/app/services/session_orchestrator/pipeline.py`)
- Clinical Intelligence → Clinician Workspace: provides synthesis
- Backend API → Application Database: persists records
- Clinician Workspace → Dataset Review: reviews examples
