# thirstybrain/medi-mind architecture

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

- Interactive diagram: https://gitdiagram.com/thirstybrain/medi-mind
- Repository: https://github.com/thirstybrain/medi-mind

## Overview

##### Project type and purpose
- This is a full-stack AI-powered healthcare chatbot.
- Frontend: React + TypeScript chat UI (Material UI + Axios).
- Backend: Python Django app (Haystack NLP pipeline, pymed article fetcher, HuggingFace Mixtral inference).
- Purpose: accept medical queries via a chat interface, retrieve PubMed articles, run an AI model, and return concise answers.

##### File structure
- Top-level:
- medi-mind-backend/… – Django project (“medi_minds”) with one app (“chatbot”), uses manage.py, settings.py, ASGI/WSGI entrypoints, local SQLite in development, .env for HUGGINGFACE_API_KEY.
- medi-minds-ui/… – React app (create-react-app TypeScript scaffold): src/, public/, package.json, tsconfig.json.
- Patterns & conventions:
- “chatbot/pipeline.py” encapsulates the NLP pipeline stages (keyword extraction → PubMed fetch → model inference).
- “views.py” + “urls.py” expose REST endpoints (e.g. POST /api/ask/).
- Frontend “Chatbot.tsx” calls backend via Axios.

##### Extract key architectural notes from README
- Backend stack: Haystack pipeline, pymed, HuggingFace Serverless Inference API.
- Frontend stack: React + Material UI + Axios.
- One main public API endpoint: POST /api/ask/.
- Dev vs. prod considerations: SQLite in dev, environment-based secrets, suggestions for Docker, reverse proxy, cloud services.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "Frontend"
        Chatbot["React UI<br/>(Chatbot.tsx)"]:::frontend
        App["App Entry<br/>(App.tsx)"]:::frontend
        Dependencies["package.json"]:::frontend
        Assets["public/index.html"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        subgraph "API Layer"
            ProjectURLs["Project URLs<br/>(urls.py)"]:::backend
            AppURLs["App URLs<br/>(chatbot/urls.py)"]:::backend
            Views["API Views<br/>(views.py)"]:::backend
        end
        subgraph "NLP Pipeline"
            KE["Keyword Extraction"]:::backend
            PF["PubMed Fetcher"]:::backend
            AG["Answer Generator"]:::backend
        end
        Models["Chat History Models<br/>(models.py)"]:::backend
        Settings["Django Settings<br/>(settings.py)"]:::config
        Env["Environment Variables<br/>(.env)"]:::config
        ASGI["ASGI Entrypoint<br/>(asgi.py)"]:::backend
        WSGI["WSGI Entrypoint<br/>(wsgi.py)"]:::backend
        Manage["Django Manage Script<br/>(manage.py)"]:::backend
    end

    %% Database
    DB[(SQLite Database)]:::db

    %% External Services
    PubMed["PubMed API"]:::external
    HF["HuggingFace Inference API"]:::external

    %% Connections
    App -->|renders| Chatbot
    Chatbot -->|POST /api/ask| AppURLs
    AppURLs -->|routes to| Views
    Views -->|invoke| KE
    KE -->|keywords| PF
    PF -->|fetch articles| PubMed
    PubMed -->|articles| PF
    PF -->|pass to| AG
    AG -->|inference| HF
    HF -->|response| AG
    AG -->|answer| Views
    Views -->|response JSON| Chatbot
    Views -.->|save chat| Models
    Models -->|persist| DB
    Settings -->|configures| ProjectURLs
    Settings -->|configures| AppURLs
    Env -->|provides| Settings
    Manage -->|starts| ASGI
    Manage -->|starts| WSGI
    ASGI -->|handles| ProjectURLs
    WSGI -->|handles| ProjectURLs

    %% Click Events
    click Chatbot "https://github.com/thirstybrain/medi-mind/blob/main/medi-minds-ui/src/Chatbot.tsx"
    click App "https://github.com/thirstybrain/medi-mind/blob/main/medi-minds-ui/src/App.tsx"
    click Dependencies "https://github.com/thirstybrain/medi-mind/blob/main/medi-minds-ui/package.json"
    click Assets "https://github.com/thirstybrain/medi-mind/blob/main/medi-minds-ui/public/index.html"
    click ProjectURLs "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/medi_minds/urls.py"
    click AppURLs "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/chatbot/urls.py"
    click Views "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/chatbot/views.py"
    click KE "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/chatbot/pipeline.py"
    click PF "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/chatbot/pipeline.py"
    click AG "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/chatbot/pipeline.py"
    click Models "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/chatbot/models.py"
    click DB "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/db.sqlite3"
    click Settings "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/medi_minds/settings.py"
    click Env "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/.env"
    click ASGI "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/medi_minds/asgi.py"
    click WSGI "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/medi_minds/wsgi.py"
    click Manage "https://github.com/thirstybrain/medi-mind/blob/main/medi-mind-backend/medi_minds/manage.py"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef db fill:#FFF2CC,stroke:#333,stroke-width:1px
    classDef config fill:#FFE4B5,stroke:#333,stroke-width:1px
```
