# asbadef/homunculus-ai architecture

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

- Interactive diagram: https://gitdiagram.com/asbadef/homunculus-ai
- Repository: https://github.com/asbadef/homunculus-ai

## Overview

MedPilot-AI is a clinical monitoring and response system: device and clinical observations feed a rules-based early-warning engine, whose alerts are presented to clinicians for review and escalation—not automated orders. Clinicians interact through a web dashboard or mobile companion, with admission and hospital-configuration workflows alongside live monitoring. The repository also includes an optional ML scoring seam and a standalone MEDIBUS ventilator bridge. Connections are limited to README statements and relationships visible in the supplied source index or excerpts; several subsystem details are represented by their existing directories because their source was not sampled.

Main entry points: [`homunculus-engine/src/homunculus/pipeline.py`](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/pipeline.py) (Rules Pipeline), [`homunculus-engine/src/homunculus/api/app.py`](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/api/app.py) (Live Board API), [`dashboard/src/main.jsx`](https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/main.jsx) (Web Mode Selector), [`homunculus-engine/src/homunculus/db.py`](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/db.py) (Application Database)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Data Ingestion"]
  node_medibus["MEDIBUS Bridge<br/>[run.py]"]
end

subgraph group_clinical["Clinical Engine"]
  node_engine["Rules Pipeline<br/>[pipeline.py]"]
  node_rules["Clinical Rules"]
  node_recommendations["Alert Recommendations<br/>[engine.py]"]
  node_ml["Optional ML Scorer<br/>[scorer.py]"]
end

subgraph group_platform["Hospital Platform"]
  node_api["Live Board API<br/>[app.py]"]
  node_admission["Admission Workflow<br/>[service.py]"]
  node_escalation["Escalation Workflow<br/>[service.py]"]
  node_auth["Identity and Auth"]
  node_tenant["Hospital Configuration<br/>[router.py]"]
  node_database[("Application Database<br/>[db.py]")]
end

subgraph group_web["Web Dashboard"]
  node_webentry["Web Mode Selector<br/>[main.jsx]"]
  node_webclinical["Clinical Dashboard<br/>[ClinicalDemo.jsx]"]
  node_webclinicaldata["Clinical Demo Data<br/>[clinicalDemo.js]"]
  node_webapi["Web API Client<br/>[backendApi.js]"]
end

subgraph group_mobile["Mobile Companion"]
  node_mobileprovider["Mobile Board State<br/>[BoardProvider.tsx]"]
  node_mobiletransport["Mobile Live Transport<br/>[sseTransport.ts]"]
  node_mobileauth["Mobile Auth Client<br/>[authClient.ts]"]
  node_mobiletokens[("Secure Token Store<br/>[secureTokens.ts]")]
end

node_clinician(("Clinician"))
node_devices(("Clinical Devices"))

node_devices -.->|"sends serial data"| node_medibus
node_medibus -.->|"forwards observations"| node_engine
node_engine -->|"evaluates"| node_rules
node_engine -->|"builds alerts"| node_recommendations
node_engine -->|"optionally scores"| node_ml
node_api -.->|"ingests observations"| node_engine
node_api -.->|"escalates alerts"| node_escalation
node_api -.->|"serves admissions"| node_admission
node_admission -->|"reads and writes"| node_database
node_escalation -.->|"reads and writes"| node_database
node_tenant -->|"reads and writes"| node_database
node_auth -->|"uses models"| node_database
node_clinician -->|"selects mode"| node_webentry
node_webentry -->|"renders live view"| node_webclinical
node_webentry -->|"creates demo state"| node_webclinicaldata
node_webentry -->|"configures live store"| node_webapi
node_webapi -.->|"requests board data"| node_api
node_clinician -.->|"uses companion"| node_mobileprovider
node_mobileprovider -->|"opens live stream"| node_mobiletransport
node_mobileprovider -->|"creates auth client"| node_mobileauth
node_mobileauth -->|"stores session tokens"| node_mobiletokens
node_mobiletransport -.->|"streams board data"| node_api

click node_medibus "https://github.com/asbadef/homunculus-ai/blob/main/medibus/src/medibus/run.py"
click node_engine "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/pipeline.py"
click node_rules "https://github.com/asbadef/homunculus-ai/tree/main/homunculus-engine/src/homunculus/rules"
click node_recommendations "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/reco/engine.py"
click node_ml "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/model/scorer.py"
click node_api "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/api/app.py"
click node_admission "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/admission/service.py"
click node_escalation "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/escalation/service.py"
click node_auth "https://github.com/asbadef/homunculus-ai/tree/main/homunculus-engine/src/homunculus/auth"
click node_tenant "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/tenant/router.py"
click node_database "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/db.py"
click node_webentry "https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/main.jsx"
click node_webclinical "https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/ClinicalDemo.jsx"
click node_webclinicaldata "https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/clinicalDemo.js"
click node_webapi "https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/backendApi.js"
click node_mobileprovider "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/store/BoardProvider.tsx"
click node_mobiletransport "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/transport/sseTransport.ts"
click node_mobileauth "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/transport/authClient.ts"
click node_mobiletokens "https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/store/secureTokens.ts"

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_medibus toneBlue
class node_engine,node_rules,node_recommendations,node_ml toneAmber
class node_api,node_admission,node_escalation,node_auth,node_tenant,node_database toneMint
class node_webentry,node_webclinical,node_webclinicaldata,node_webapi toneRose
class node_mobileprovider,node_mobiletransport,node_mobileauth,node_mobiletokens,node_clinician,node_devices toneIndigo
```

## Components

### Data Ingestion

- [MEDIBUS Bridge](https://github.com/asbadef/homunculus-ai/blob/main/medibus/src/medibus/run.py): `medibus/src/medibus/run.py`

### Clinical Engine

- [Rules Pipeline](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/pipeline.py): `homunculus-engine/src/homunculus/pipeline.py`
- [Clinical Rules](https://github.com/asbadef/homunculus-ai/tree/main/homunculus-engine/src/homunculus/rules): `homunculus-engine/src/homunculus/rules`
- [Alert Recommendations](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/reco/engine.py): `homunculus-engine/src/homunculus/reco/engine.py`
- [Optional ML Scorer](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/model/scorer.py): `homunculus-engine/src/homunculus/model/scorer.py`

### Hospital Platform

- [Live Board API](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/api/app.py): `homunculus-engine/src/homunculus/api/app.py`
- [Admission Workflow](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/admission/service.py): `homunculus-engine/src/homunculus/admission/service.py`
- [Escalation Workflow](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/escalation/service.py): `homunculus-engine/src/homunculus/escalation/service.py`
- [Identity and Auth](https://github.com/asbadef/homunculus-ai/tree/main/homunculus-engine/src/homunculus/auth): `homunculus-engine/src/homunculus/auth`
- [Hospital Configuration](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/tenant/router.py): `homunculus-engine/src/homunculus/tenant/router.py`
- [Application Database](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-engine/src/homunculus/db.py): `homunculus-engine/src/homunculus/db.py`

### Web Dashboard

- [Web Mode Selector](https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/main.jsx): `dashboard/src/main.jsx`
- [Clinical Dashboard](https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/ClinicalDemo.jsx): `dashboard/src/ClinicalDemo.jsx`
- [Clinical Demo Data](https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/clinicalDemo.js): `dashboard/src/clinicalDemo.js`
- [Web API Client](https://github.com/asbadef/homunculus-ai/blob/main/dashboard/src/backendApi.js): `dashboard/src/backendApi.js`

### Mobile Companion

- [Mobile Board State](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/store/BoardProvider.tsx): `homunculus-mobile/src/store/BoardProvider.tsx`
- [Mobile Live Transport](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/transport/sseTransport.ts): `homunculus-mobile/src/transport/sseTransport.ts`
- [Mobile Auth Client](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/transport/authClient.ts): `homunculus-mobile/src/transport/authClient.ts`
- [Secure Token Store](https://github.com/asbadef/homunculus-ai/blob/main/homunculus-mobile/src/store/secureTokens.ts): `homunculus-mobile/src/store/secureTokens.ts`

### Other components

- **Clinician**
- **Clinical Devices**

## Connections

- Clinical Devices → MEDIBUS Bridge: sends serial data (evidence: `README.md`)
- MEDIBUS Bridge → Rules Pipeline: forwards observations (evidence: `README.md`)
- Rules Pipeline → Clinical Rules: evaluates (evidence: `homunculus-engine/src/homunculus/pipeline.py`)
- Rules Pipeline → Alert Recommendations: builds alerts (evidence: `homunculus-engine/src/homunculus/pipeline.py`)
- Rules Pipeline → Optional ML Scorer: optionally scores (evidence: `homunculus-engine/src/homunculus/pipeline.py`)
- Live Board API → Rules Pipeline: ingests observations (evidence: `homunculus-engine/src/homunculus/api/app.py`)
- Live Board API → Escalation Workflow: escalates alerts
- Live Board API → Admission Workflow: serves admissions
- Admission Workflow → Application Database: reads and writes (evidence: `homunculus-engine/src/homunculus/admission/service.py`)
- Escalation Workflow → Application Database: reads and writes
- Hospital Configuration → Application Database: reads and writes (evidence: `homunculus-engine/src/homunculus/tenant/router.py`)
- Identity and Auth → Application Database: uses models (evidence: `homunculus-engine/src/homunculus/auth/models.py`)
- Clinician → Web Mode Selector: selects mode (evidence: `dashboard/src/main.jsx`)
- Web Mode Selector → Clinical Dashboard: renders live view (evidence: `dashboard/src/main.jsx`)
- Web Mode Selector → Clinical Demo Data: creates demo state (evidence: `dashboard/src/main.jsx`)
- Web Mode Selector → Web API Client: configures live store (evidence: `dashboard/src/main.jsx`)
- Web API Client → Live Board API: requests board data
- Clinician → Mobile Board State: uses companion
- Mobile Board State → Mobile Live Transport: opens live stream (evidence: `homunculus-mobile/src/store/BoardProvider.tsx`)
- Mobile Board State → Mobile Auth Client: creates auth client (evidence: `homunculus-mobile/src/store/BoardProvider.tsx`)
- Mobile Auth Client → Secure Token Store: stores session tokens (evidence: `homunculus-mobile/src/transport/authClient.ts`)
- Mobile Live Transport → Live Board API: streams board data
