# sahil123goyal/drug_monitor_recall architecture

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

- Interactive diagram: https://gitdiagram.com/sahil123goyal/drug_monitor_recall
- Repository: https://github.com/sahil123goyal/drug_monitor_recall

## Overview

Drug Recall Monitor manages household medicine inventory, fetches official recall candidates, assesses identity evidence, pauses for human input and approval, then records mock alert delivery and verification. The main path runs through the durable LangGraph worker; a Streamlit client uses the HTTP API rather than the database. Separate branches support notice fetching, optional Groq extraction, scheduled runs, and official-case evaluation. Source excerpts expose only part of the workflow, so links for unsampled subsystems rely on README statements or are omitted where ownership is unclear.

Main entry points: [`app/agents/graph.py`](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/graph.py) (Recall graph), [`app/api/routes.py`](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/api/routes.py) (FastAPI routes), [`frontend/views`](https://github.com/sahil123goyal/drug_monitor_recall/tree/main/frontend/views) (Streamlit pages), [`app/agents/repository.py`](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/repository.py) (Workflow repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User interfaces"]
  node_streamlit["Streamlit pages"]
  node_ui["UI shell<br/>[ui.py]"]
  node_api_client["Typed API client<br/>[api_client.py]"]
  node_results["Result presentation<br/>[presentation.py]"]
end

subgraph group_workflow["Recall workflow"]
  node_api["FastAPI routes<br/>[routes.py]"]
  node_worker["Durable run worker<br/>[run_worker.py]"]
  node_runtime["Graph runtime<br/>[runtime.py]"]
  node_graph["Recall graph<br/>[graph.py]"]
  node_contracts["Workflow contracts<br/>[contracts.py]"]
end

subgraph group_data["Persistence and sources"]
  node_repository["Workflow repository<br/>[repository.py]"]
  node_database[("PostgreSQL state<br/>[entities.py]")]
  node_sessions["Database sessions<br/>[session.py]"]
  node_notice_source["OpenFDA adapter<br/>[openfda.py]"]
  node_notice_store["Notice store<br/>[notice_store.py]"]
end

subgraph group_assessment["Assessment and verification"]
  node_matcher["Deterministic matcher<br/>[matcher.py]"]
  node_extraction["Groq extraction<br/>[extraction.py]"]
  node_verification["Notice verification<br/>[verification.py]"]
end

subgraph group_operations["Operations and evaluation"]
  node_scheduler["Run scheduler<br/>[scheduler.py]"]
  node_official_cases["Official cases<br/>[official_cases.py]"]
  node_official_runner["Official evaluator<br/>[official_runner.py]"]
  node_evaluations["Evaluation service<br/>[evaluations.py]"]
  node_settings["Settings<br/>[config.py]"]
end

node_household(("Household user"))

node_household -->|"uses"| node_streamlit
node_streamlit -->|"renders"| node_ui
node_ui -->|"requests"| node_api_client
node_api_client -->|"calls HTTP"| node_api
node_api -->|"queues runs"| node_worker
node_worker -->|"runs workflow"| node_runtime
node_runtime -->|"builds"| node_graph
node_graph -->|"uses state"| node_contracts
node_graph -->|"reads and writes"| node_repository
node_repository -->|"persists audit"| node_database
node_repository -->|"opens sessions"| node_sessions
node_graph -->|"fetches candidates"| node_notice_source
node_notice_source -->|"persists pages"| node_notice_store
node_graph -->|"assesses notices"| node_matcher
node_matcher -.->|"may use fields"| node_extraction
node_graph -->|"verifies alerts"| node_verification
node_api -->|"serves inventory and runs"| node_database
node_scheduler -.->|"schedules household runs"| node_database
node_scheduler -.->|"reads schedule settings"| node_settings
node_official_runner -->|"loads cases"| node_official_cases
node_official_runner -->|"executes cases"| node_graph
node_evaluations -->|"evaluates decisions"| node_matcher
node_api -->|"starts evaluations"| node_official_runner
node_streamlit -->|"presents results"| node_results

click node_streamlit "https://github.com/sahil123goyal/drug_monitor_recall/tree/main/frontend/views"
click node_ui "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/frontend/ui.py"
click node_api_client "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/frontend/api_client.py"
click node_api "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/api/routes.py"
click node_worker "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/run_worker.py"
click node_runtime "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/runtime.py"
click node_graph "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/graph.py"
click node_contracts "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/contracts.py"
click node_repository "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/repository.py"
click node_database "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/models/entities.py"
click node_sessions "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/db/session.py"
click node_notice_source "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/sources/openfda.py"
click node_notice_store "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/notice_store.py"
click node_matcher "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/matcher.py"
click node_extraction "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/extraction.py"
click node_verification "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/verification.py"
click node_scheduler "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/scheduler.py"
click node_official_cases "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/official_cases.py"
click node_official_runner "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/official_runner.py"
click node_evaluations "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/evaluations.py"
click node_results "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/frontend/presentation.py"
click node_settings "https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/core/config.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_streamlit,node_ui,node_api_client,node_results,node_household toneBlue
class node_api,node_worker,node_runtime,node_graph,node_contracts toneAmber
class node_repository,node_database,node_sessions,node_notice_source,node_notice_store toneMint
class node_matcher,node_extraction,node_verification toneRose
class node_scheduler,node_official_cases,node_official_runner,node_evaluations,node_settings toneIndigo
```

## Components

### User interfaces

- [Streamlit pages](https://github.com/sahil123goyal/drug_monitor_recall/tree/main/frontend/views): `frontend/views`
- [UI shell](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/frontend/ui.py): `frontend/ui.py`
- [Typed API client](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/frontend/api_client.py): `frontend/api_client.py`
- [Result presentation](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/frontend/presentation.py): `frontend/presentation.py`

### Recall workflow

- [FastAPI routes](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/api/routes.py): `app/api/routes.py`
- [Durable run worker](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/run_worker.py): `app/services/run_worker.py`
- [Graph runtime](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/runtime.py): `app/agents/runtime.py`
- [Recall graph](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/graph.py): `app/agents/graph.py`
- [Workflow contracts](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/contracts.py): `app/agents/contracts.py`

### Persistence and sources

- [Workflow repository](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/agents/repository.py): `app/agents/repository.py`
- [PostgreSQL state](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/models/entities.py): `app/models/entities.py`
- [Database sessions](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/db/session.py): `app/db/session.py`
- [OpenFDA adapter](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/sources/openfda.py): `app/sources/openfda.py`
- [Notice store](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/notice_store.py): `app/services/notice_store.py`

### Assessment and verification

- [Deterministic matcher](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/matcher.py): `app/services/matcher.py`
- [Groq extraction](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/extraction.py): `app/services/extraction.py`
- [Notice verification](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/verification.py): `app/services/verification.py`

### Operations and evaluation

- [Run scheduler](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/scheduler.py): `app/services/scheduler.py`
- [Official cases](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/official_cases.py): `app/services/official_cases.py`
- [Official evaluator](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/official_runner.py): `app/services/official_runner.py`
- [Evaluation service](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/services/evaluations.py): `app/services/evaluations.py`
- [Settings](https://github.com/sahil123goyal/drug_monitor_recall/blob/main/app/core/config.py): `app/core/config.py`

### Other components

- **Household user**

## Connections

- Household user → Streamlit pages: uses (evidence: `README.md`)
- Streamlit pages → UI shell: renders (evidence: `frontend/views/approvals.py`)
- UI shell → Typed API client: requests (evidence: `frontend/ui.py`)
- Typed API client → FastAPI routes: calls HTTP (evidence: `frontend/api_client.py`)
- FastAPI routes → Durable run worker: queues runs (evidence: `README.md`)
- Durable run worker → Graph runtime: runs workflow (evidence: `app/services/run_worker.py`)
- Graph runtime → Recall graph: builds (evidence: `app/agents/runtime.py`)
- Recall graph → Workflow contracts: uses state (evidence: `app/agents/graph.py`)
- Recall graph → Workflow repository: reads and writes (evidence: `app/agents/graph.py`)
- Workflow repository → PostgreSQL state: persists audit (evidence: `app/agents/repository.py`)
- Workflow repository → Database sessions: opens sessions (evidence: `app/agents/runtime.py`)
- Recall graph → OpenFDA adapter: fetches candidates (evidence: `app/agents/graph.py`)
- OpenFDA adapter → Notice store: persists pages (evidence: `app/sources/openfda.py`)
- Recall graph → Deterministic matcher: assesses notices (evidence: `app/agents/graph.py`)
- Deterministic matcher → Groq extraction: may use fields (evidence: `app/services/matcher.py`)
- Recall graph → Notice verification: verifies alerts (evidence: `app/agents/graph.py`)
- FastAPI routes → PostgreSQL state: serves inventory and runs (evidence: `app/api/routes.py`)
- Run scheduler → PostgreSQL state: schedules household runs (evidence: `README.md`)
- Run scheduler → Settings: reads schedule settings (evidence: `app/core/config.py`)
- Official evaluator → Official cases: loads cases (evidence: `app/services/official_runner.py`)
- Official evaluator → Recall graph: executes cases (evidence: `app/services/official_runner.py`)
- Evaluation service → Deterministic matcher: evaluates decisions (evidence: `app/services/evaluations.py`)
- FastAPI routes → Official evaluator: starts evaluations (evidence: `app/api/routes.py`)
- Streamlit pages → Result presentation: presents results (evidence: `frontend/views/approvals.py`)
