# abelmou/healthcare-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/abelmou/healthcare-assistant
- Repository: https://github.com/abelmou/healthcare-assistant

## Overview

#### Purpose and Entry Points
This is a local, Python-based healthcare assistant combining document-question answering, prescription OCR, and pharmacy discovery. It exposes several independently runnable UIs:
- Main Streamlit portal: `main.py`
- Document/RAG Streamlit assistant: `app_streamlit.py`
- Conversational Chainlit assistant: `app_chainlit.py`
- Prescription OCR UI: `ocr.py`
- Pharmacy locator UI: `pharmascysol.py`

#### RAG Knowledge Pipeline
The retrieval layer is centered in `rag.py`, with persisted Chroma vector-store artifacts under `chroma_db/chroma.sqlite3` and `chroma_db/55367a26-0c7a-497d-8e7f-3675c6b8c9f0/`. It is intended to ingest, chunk, embed, and retrieve health-document context before generation. Seed/source materials reside in `data/World-Health-Organization.pdf` and corrected prescription text files in `data/`.

#### LLM Orchestration Boundary
LangChain provides the application’s LLM/RAG orchestration, while Ollama is the local model-serving dependency (the README specifies `llama3.2`). UI applications should delegate health-query answering to the retrieval layer rather than treating Streamlit or Chainlit as model backends. This creates a clear boundary between interaction shells (`app_streamlit.py`, `app_chainlit.py`) and retrieval/generation (`rag.py`).

#### Document Assistant Interfaces
Two interfaces serve the question-answering workflow:
- `app_streamlit.py` provides a browser-oriented document assistant.
- `app_chainlit.py`, with supporting chat content in `chainlit.md`, provides a chat-focused interface.
Both are alternate delivery surfaces for multilingual health queries (Darija, Arabic, English) over the RAG knowledge base.

#### Prescription OCR Flow
`ocr.py` is a separate Streamlit workflow for uploading/scanning prescription images, applying image processing and handwriting/OCR extraction, then producing usable prescription text. The repository includes OCR-related experiments in `notebooks/Prescription_Handwritten_Text_Recognition.ipynb` and corrected OCR outputs under `data/corrected_ordonnance_*.txt`, indicating a pipeline boundary between raw image recognition and downstream clinical-document use.

#### Pharmacy Discovery Flow
`pharmascysol.py` implements the pharmacy-locator capability. Its responsibility is distinct from RAG: it uses user geolocation and external map/place data or browser-accessible location services to identify nearby pharmacies/providers. It is launched independently, rather than as a required step in document retrieval.

#### Runtime and Persistence
Material runtime dependencies are Python 3.9+, Streamlit, Chainlit, LangChain, ChromaDB, Ollama, OpenCV, PDF parsing/processing libraries, and optionally ElevenLabs for text-to-speech. Persistent local state is committed under `chroma_db/`; source documents and derived prescription text are stored under `data/`. No server-side healthcare-provider API integration is evidenced; provider API integration is described as future work.

Main entry points: [`rag.py`](https://github.com/abelmou/healthcare-assistant/blob/main/rag.py) (RAG pipeline), [`ocr.py`](https://github.com/abelmou/healthcare-assistant/blob/main/ocr.py) (Image processing & OCR), [`main.py`](https://github.com/abelmou/healthcare-assistant/blob/main/main.py) (Main portal), [`pharmascysol.py`](https://github.com/abelmou/healthcare-assistant/blob/main/pharmascysol.py) (Pharmacy locator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Runnable interfaces"]
  node_portal["Main portal<br/>Streamlit entry point<br/>[main.py]"]
  node_document_ui["Document assistant<br/>Streamlit UI<br/>[app_streamlit.py]"]
  node_chat_ui["Chat assistant<br/>Chainlit UI<br/>[app_chainlit.py]"]
  node_chat_content["Chat content<br/>Chainlit content<br/>[chainlit.md]"]
  node_locator_ui["Pharmacy locator<br/>Streamlit UI<br/>[pharmascysol.py]"]
end

subgraph group_knowledge["Knowledge &amp; generation"]
  node_rag{{"RAG pipeline<br/>LangChain retrieval service<br/>[rag.py]"}}
  node_ollama{{"Local LLM<br/>Ollama / llama3.2"}}
  node_chroma_db[("Chroma vector store<br/>persistent vector DB<br/>[chroma.sqlite3]")]
  node_chroma_artifacts[("Vector artifacts<br/>Chroma collection data")]
  node_health_pdf["WHO health source<br/>PDF knowledge source"]
end

subgraph group_ocr["Prescription OCR"]
  node_ocr_ui["Prescription OCR UI<br/>Streamlit UI<br/>[ocr.py]"]
  node_prescription_images["Prescription images<br/>uploaded scans"]
  node_ocr_processing{{"Image processing &amp; OCR<br/>OpenCV and handwriting OCR<br/>[ocr.py]"}}
  node_corrected_text["Corrected prescriptions<br/>derived text corpus"]
  node_ocr_notebook["OCR experiment<br/>notebook"]
end

node_geolocation(("User geolocation<br/>browser location input"))
node_maps_places{{"Map/place services<br/>external location data"}}

node_portal -->|"launches"| node_document_ui
node_portal -->|"launches"| node_ocr_ui
node_portal -->|"launches"| node_locator_ui
node_document_ui -->|"health query"| node_rag
node_chat_ui -->|"health query"| node_rag
node_chat_content -->|"supports"| node_chat_ui
node_health_pdf -->|"ingest and chunk"| node_rag
node_corrected_text -.->|"optional source text"| node_rag
node_rag -->|"stores and retrieves embeddings"| node_chroma_db
node_chroma_db -->|"persists collection"| node_chroma_artifacts
node_rag -->|"generation"| node_ollama
node_prescription_images -->|"scan input"| node_ocr_processing
node_ocr_ui -->|"runs extraction"| node_ocr_processing
node_ocr_processing -->|"produces text"| node_corrected_text
node_ocr_notebook -.->|"experiments with"| node_ocr_processing
node_geolocation -->|"location"| node_locator_ui
node_locator_ui -->|"nearby lookup"| node_maps_places

click node_portal "https://github.com/abelmou/healthcare-assistant/blob/main/main.py"
click node_document_ui "https://github.com/abelmou/healthcare-assistant/blob/main/app_streamlit.py"
click node_chat_ui "https://github.com/abelmou/healthcare-assistant/blob/main/app_chainlit.py"
click node_chat_content "https://github.com/abelmou/healthcare-assistant/blob/main/chainlit.md"
click node_ocr_ui "https://github.com/abelmou/healthcare-assistant/blob/main/ocr.py"
click node_locator_ui "https://github.com/abelmou/healthcare-assistant/blob/main/pharmascysol.py"
click node_rag "https://github.com/abelmou/healthcare-assistant/blob/main/rag.py"
click node_chroma_db "https://github.com/abelmou/healthcare-assistant/blob/main/chroma_db/chroma.sqlite3"
click node_health_pdf "https://github.com/abelmou/healthcare-assistant/blob/main/data/World-Health-Organization.pdf"
click node_ocr_processing "https://github.com/abelmou/healthcare-assistant/blob/main/ocr.py"
click node_ocr_notebook "https://github.com/abelmou/healthcare-assistant/blob/main/notebooks/Prescription_Handwritten_Text_Recognition.ipynb"

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_portal,node_document_ui,node_chat_ui,node_chat_content,node_locator_ui toneBlue
class node_rag,node_ollama,node_chroma_db,node_chroma_artifacts,node_health_pdf toneAmber
class node_ocr_ui,node_prescription_images,node_ocr_processing,node_corrected_text,node_ocr_notebook toneMint
class node_geolocation,node_maps_places toneNeutral
```

## Components

### Runnable interfaces

Independent local UI entry points.

- [Main portal](https://github.com/abelmou/healthcare-assistant/blob/main/main.py): Streamlit entry point · `main.py`
- [Document assistant](https://github.com/abelmou/healthcare-assistant/blob/main/app_streamlit.py): Streamlit UI · Browser-oriented health question interface. · `app_streamlit.py`
- [Chat assistant](https://github.com/abelmou/healthcare-assistant/blob/main/app_chainlit.py): Chainlit UI · Chat-focused multilingual health interface. · `app_chainlit.py`
- [Chat content](https://github.com/abelmou/healthcare-assistant/blob/main/chainlit.md): Chainlit content · `chainlit.md`
- [Pharmacy locator](https://github.com/abelmou/healthcare-assistant/blob/main/pharmascysol.py): Streamlit UI · Independent nearby-pharmacy discovery workflow. · `pharmascysol.py`

### Knowledge & generation

Local retrieval and answer-generation boundary.

- [RAG pipeline](https://github.com/abelmou/healthcare-assistant/blob/main/rag.py): LangChain retrieval service · Ingests, chunks, embeds, retrieves, and generates answers. · `rag.py`
- **Local LLM**: Ollama / llama3.2
- [Chroma vector store](https://github.com/abelmou/healthcare-assistant/blob/main/chroma_db/chroma.sqlite3): persistent vector DB · `chroma_db/chroma.sqlite3`
- **Vector artifacts**: Chroma collection data
- [WHO health source](https://github.com/abelmou/healthcare-assistant/blob/main/data/World-Health-Organization.pdf): PDF knowledge source · `data/World-Health-Organization.pdf`

### Prescription OCR

Prescription recognition and correction workflow.

- [Prescription OCR UI](https://github.com/abelmou/healthcare-assistant/blob/main/ocr.py): Streamlit UI · `ocr.py`
- **Prescription images**: uploaded scans · Input images supplied through the OCR workflow.
- [Image processing & OCR](https://github.com/abelmou/healthcare-assistant/blob/main/ocr.py): OpenCV and handwriting OCR · Extracts prescription text from scanned images. · `ocr.py`
- **Corrected prescriptions**: derived text corpus · Corrected OCR output available for downstream document use.
- [OCR experiment](https://github.com/abelmou/healthcare-assistant/blob/main/notebooks/Prescription_Handwritten_Text_Recognition.ipynb): notebook · `notebooks/Prescription_Handwritten_Text_Recognition.ipynb`

### Other components

- **User geolocation**: browser location input
- **Map/place services**: external location data · External or browser-accessible nearby-place lookup.

## Connections

- Main portal → Document assistant: launches
- Main portal → Prescription OCR UI: launches
- Main portal → Pharmacy locator: launches
- Document assistant → RAG pipeline: health query
- Chat assistant → RAG pipeline: health query
- Chat content → Chat assistant: supports
- WHO health source → RAG pipeline: ingest and chunk
- Corrected prescriptions → RAG pipeline: optional source text
- RAG pipeline → Chroma vector store: stores and retrieves embeddings
- Chroma vector store → Vector artifacts: persists collection
- RAG pipeline → Local LLM: generation
- Prescription images → Image processing & OCR: scan input
- Prescription OCR UI → Image processing & OCR: runs extraction
- Image processing & OCR → Corrected prescriptions: produces text
- OCR experiment → Image processing & OCR: experiments with
- User geolocation → Pharmacy locator: location
- Pharmacy locator → Map/place services: nearby lookup
