# aryansingh25/medical-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/aryansingh25/medical-assistant
- Repository: https://github.com/aryansingh25/medical-assistant

## Overview

##### Project type and purpose
- This is a full-stack Retrieval-Augmented Generation (RAG) application (“Medical Assistant”) with:
- A Streamlit-based frontend for uploading PDFs and querying them
- A FastAPI backend that handles document ingestion, vector store loading, and query handling
- Integration with external services (Google Gemini for embeddings, Pinecone for vector DB, Groq API for LLaMA inference)

##### File structure
- Top-level:
- client/ – Streamlit app (app.py, components/, utils/api.py, config.py)
- server/ – FastAPI app (main.py, routes/, modules/, middlewares/)
- server/uploaded_docs/ – local storage for raw PDFs
- main.py (possibly orchestration or alias to start scripts)
- Key modules in server/:
- pdf_handlers.py – PDF text extraction & chunking
- load_vectorstore.py – embedding generation & Pinecone indexing
- query_handlers.py & llm.py – retrieval of chunks + Groq API calls
- client/utils/api.py – HTTP wrappers for upload & ask endpoints

##### README for additional insights
- Confirms RAG pipeline steps: Upload → Extract/Chunk → Embed → Store → Retrieve → LLM → Display
- Tech stack table highlights: Streamlit | FastAPI | LangChain | Pinecone | Google Gemini | Groq API

##### Detailed capture of architectural elements
- Streamlit components (upload, chat UI, history download)
- Client.utils.api as the client↔server HTTP adapter
- Server/routes → server/modules handoff
- Clearly label LangChain orchestration between vector retrieval & Groq API

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        UIApp["Streamlit UI"]:::frontend
        UploadComp["Upload Component"]:::frontend
        ChatComp["Chat UI Component"]:::frontend
        HistoryComp["History Download Component"]:::frontend
        Config["Client Config"]:::frontend
        ClientAPI["Client HTTP Adapter"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FastAPIServer["FastAPI Server"]:::backend
        UploadRoute["/upload_pdfs Route"]:::backend
        AskRoute["/ask_question Route"]:::backend
        ExceptionHandler["Exception Handlers"]:::backend
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        direction TB
        PDFHandlers["PDF Extraction & Chunking"]:::processing
        LoadVector["Embedding & Vector Store Loader"]:::processing
        QueryHandlers["Query Handlers"]:::processing
        LLMConnector["LLM Integration (Groq LLaMA)"]:::processing
    end

    %% Data & External Services Layer
    subgraph "Data & External"
        direction TB
        LocalDocs["Local Document Storage"]:::data
        Pinecone["Pinecone Vector DB"]:::external
        GoogleGemini["Google Gemini Embeddings"]:::external
        GroqAPI["Groq API (LLaMA)"]:::external
    end

    %% Orchestration & Logging
    subgraph "Utilities"
        direction TB
        Launcher["Orchestration Launcher"]:::backend
        Logger["Logging Utility"]:::backend
    end

    %% User Interaction
    User["User"]:::external
    User -->|uses| UIApp
    UIApp --> UploadComp
    UIApp --> ChatComp
    UIApp --> HistoryComp
    UIApp --> Config
    UIApp --> ClientAPI

    %% Client to Server
    ClientAPI -->|POST /upload_pdfs| UploadRoute
    ClientAPI -->|POST /ask_question| AskRoute

    %% Server start
    Launcher --> FastAPIServer

    %% Routes to Business Logic
    UploadRoute --> ExceptionHandler
    AskRoute --> ExceptionHandler

    UploadRoute --> PDFHandlers
    PDFHandlers --> LoadVector
    LoadVector -->|embeds| GoogleGemini
    LoadVector -->|indexes| Pinecone
    PDFHandlers --> LocalDocs

    AskRoute --> QueryHandlers
    QueryHandlers --> Pinecone
    QueryHandlers --> LLMConnector
    LLMConnector --> GroqAPI

    %% Logging
    PDFHandlers --> Logger
    LoadVector --> Logger
    QueryHandlers --> Logger
    LLMConnector --> Logger
    UploadRoute --> Logger
    AskRoute --> Logger
    FastAPIServer --> Logger

    %% Click Events
    click UIApp "https://github.com/aryansingh25/medical-assistant/blob/main/client/app.py"
    click UploadComp "https://github.com/aryansingh25/medical-assistant/blob/main/client/components/upload.py"
    click ChatComp "https://github.com/aryansingh25/medical-assistant/blob/main/client/components/chatUI.py"
    click HistoryComp "https://github.com/aryansingh25/medical-assistant/blob/main/client/components/history_download.py"
    click Config "https://github.com/aryansingh25/medical-assistant/blob/main/client/config.py"
    click ClientAPI "https://github.com/aryansingh25/medical-assistant/blob/main/client/utils/api.py"
    click FastAPIServer "https://github.com/aryansingh25/medical-assistant/blob/main/server/main.py"
    click UploadRoute "https://github.com/aryansingh25/medical-assistant/blob/main/server/routes/upload_pdfs.py"
    click AskRoute "https://github.com/aryansingh25/medical-assistant/blob/main/server/routes/ask_question.py"
    click ExceptionHandler "https://github.com/aryansingh25/medical-assistant/blob/main/server/middlewares/exception_handlers.py"
    click PDFHandlers "https://github.com/aryansingh25/medical-assistant/blob/main/server/modules/pdf_handlers.py"
    click LoadVector "https://github.com/aryansingh25/medical-assistant/blob/main/server/modules/load_vectorstore.py"
    click QueryHandlers "https://github.com/aryansingh25/medical-assistant/blob/main/server/modules/query_handlers.py"
    click LLMConnector "https://github.com/aryansingh25/medical-assistant/blob/main/server/modules/llm.py"
    click LocalDocs "https://github.com/aryansingh25/medical-assistant/tree/main/server/uploaded_docs/"
    click Logger "https://github.com/aryansingh25/medical-assistant/blob/main/server/logger.py"
    click Launcher "https://github.com/aryansingh25/medical-assistant/blob/main/main.py"

    %% Styles
    classDef frontend fill:#D6EAF8,stroke:#3498DB,color:#154360
    classDef backend fill:#D5F5E3,stroke:#2ECC71,color:#145A32
    classDef processing fill:#FCF3CF,stroke:#F39C12,color:#7E5109
    classDef data fill:#E8DAEF,stroke:#9B59B6,color:#4A235A
    classDef external fill:#F5EEF8,stroke:#8E44AD,color:#512E5F
```
