# nenncy/dischargesimplify architecture

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

- Interactive diagram: https://gitdiagram.com/nenncy/dischargesimplify
- Repository: https://github.com/nenncy/dischargesimplify

## Overview

##### Project Type and Purpose
- Full-stack AI-powered service:
– A FastAPI backend exposing three main endpoints (simplify, validate, assistant chat)
– A (future) Streamlit or similar frontend for clinician/patient interaction
- Purpose: Simplify complex medical discharge instructions via LLMs, validate them, and provide an interactive assistant chat.

##### File Structure
- Top-level:
– backend/
· main.py (FastAPI app entry)
· LLM_simplify.py (LLM invocation logic)
· patient_chat.py (assistant-chat logic)
– frontend/
· app.py (Streamlit or lightweight UI)
– requirements.txt, README.md
- No dedicated database directory yet (SQL planned), but FAISS indexing is part of the retrieval layer.

##### README for Insights
- Three API endpoints: /simplify, /validate, /assistant/chat
- LLM interface via Huggingface Transformers or OpenAI API
- Validation layer uses FAISS for semantic chunking/search
- Outputs structured JSON for EHR systems

##### Main Components
A. User Interface (Frontend)
– Clinician/Patient UI (Streamlit/app.py)
– Sends requests to backend endpoints
B. API Gateway / Backend (FastAPI)
– Endpoint: POST /simplify
· Orchestrates LLM_simplify module
– Endpoint: POST /validate
· Triggers validation pipeline (chunking → FAISS index → rule checks)
– Endpoint: POST /assistant/chat
· Routes to patient_chat module for interactive Q&A
C. LLM Layer
– Huggingface Transformers or OpenAI API (external service)
– Local or cloud model
D. Validation & Retrieval Layer
– Text chunker → FAISS semantic index
– Verification rules (medications, follow-ups, safety filters)
E. Data Store (future)
– SQL database for logs, audit, user/session data
F. External Integrations
– EHR systems (JSON output)
– Clinical oversight dashboards (future)

##### Relationships & Interactions
- Frontend → FastAPI:
– Simplify request → /simplify
– Validate request → /validate
– Chat interactions → /assistant/chat
- FastAPI → LLM:
– HTTP or SDK calls to model service
- FastAPI → FAISS:
– Build/query index in-memory or persistent store
- FastAPI → (future) SQL DB:
– Persist requests, logs, user data
- FastAPI → EHR:
– Push structured JSON output
- Patient ↔ Assistant Chat:
– Stateful session managed by patient_chat.py

##### Architectural Patterns & Principles
- Separation of concerns
– API layer vs. AI/validation logic vs. UI
- Modular services
– LLM_simplify.py & patient_chat.py as independent modules
- Extensibility points
– Swap in/out different LLM providers (configurable in code)
– Plug in FHIR-compliant output module in future

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "User Interface (Frontend)"
        direction TB
        UI["Clinician/Patient UI"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (FastAPI)"
        direction TB
        API["FastAPI\n(main.py)"]:::backend

        subgraph "Endpoints"
            direction TB
            Simplify["POST /simplify"]:::backend
            Validate["POST /validate"]:::backend
            Chat["POST /assistant/chat"]:::backend
        end

        API -->|"{ JSON }"| Simplify
        API -->|"{ JSON }"| Validate
        API -->|"{ chat msg }"| Chat

        Simplify -->|calls| LLM["LLM Simplifier\n(LLM_simplify.py)"]:::ai
        Validate -->|"chunk → query"| Chunker["Text Chunker"]:::validation
        Chunker -->|creates/indexes| FAISS["FAISS Semantic Index"]:::datastore
        FAISS -->|returns chunks| Validator["Verification Rules"]:::validation
        Validator -->|structured JSON| API

        Chat -->|routes| PatientChat["Patient Chat\n(patient_chat.py)"]:::ai
        PatientChat -->|stateful session| API
    end

    %% External Services and Data Stores
    subgraph "External & Future Components"
        direction TB
        AIService["Huggingface/OpenAI"]:::external
        EHR["EHR Systems"]:::external
        SQLDB["SQL Database (future)"]:::datastoreFuture
    end

    LLM -->|REST/SDK| AIService
    API -->|push JSON| EHR
    API -->|persist logs| SQLDB

    %% Click Events
    click UI "https://github.com/nenncy/dischargesimplify/blob/main/frontend/app.py"
    click API "https://github.com/nenncy/dischargesimplify/blob/main/backend/main.py"
    click LLM "https://github.com/nenncy/dischargesimplify/blob/main/backend/LLM_simplify.py"
    click PatientChat "https://github.com/nenncy/dischargesimplify/blob/main/backend/patient_chat.py"
    click README "https://github.com/nenncy/dischargesimplify/blob/main/README.md"
    click Requirements "https://github.com/nenncy/dischargesimplify/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1E88E5,stroke-width:2px;
    classDef backend fill:#FFF3E0,stroke:#FB8C00,stroke-width:2px;
    classDef ai fill:#E8F5E9,stroke:#43A047,stroke-width:2px,stroke-dasharray: 5 5;
    classDef validation fill:#FFFDE7,stroke:#FDD835,stroke-width:2px;
    classDef datastore fill:#F3E5F5,stroke:#8E24AA,stroke-width:2px;
    classDef external fill:#ECEFF1,stroke:#546E7A,stroke-width:2px,stroke-dasharray: 5 5;
    classDef datastoreFuture fill:#FCE4EC,stroke:#D81B60,stroke-width:2px,stroke-dasharray: 5 5;
```
