# deepthi01-a/mental_health_chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/deepthi01-a/mental_health_chatbot
- Repository: https://github.com/deepthi01-a/mental_health_chatbot

## Overview

This notebook-style script builds a PDF-grounded mental-health chatbot. Its primary workflow initializes a Groq language model, ingests PDFs from ./data into a persistent Chroma vector store (or loads an existing store), constructs retrieval-based question answering, and serves responses through a Gradio chat UI. The same file also includes a separate terminal chat loop. The graph reflects the sampled source; no separate safety, crisis-response, or clinical-care subsystem is implemented here.

Main entry points: [`mental_health_chatbot.py`](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py) (Retrieval QA chain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_knowledge["Knowledge ingestion"]
  node_pdfs["PDF documents"]
  node_loader["PDF loading and splitting"]
  node_embeddings["Text embeddings"]
  node_vectorstore[("Chroma vector store")]
end

subgraph group_answering["Answer generation"]
  node_orchestrator["App initialization"]
  node_qa["Retrieval QA chain"]
  node_prompt["Compassionate prompt"]
  node_llm["Groq language model"]
end

subgraph group_interface["Chat interfaces"]
  node_gradio["Gradio UI"]
  node_handler["Chat response handler"]
  node_terminal["Terminal chat loop"]
end

node_user(("Chat user"))

node_user -->|"sends message"| node_gradio
node_gradio -->|"invokes"| node_handler
node_handler -->|"queries"| node_qa
node_qa -->|"returns answer"| node_handler
node_user -->|"enters query"| node_terminal
node_terminal -->|"queries"| node_qa
node_orchestrator -->|"initializes"| node_llm
node_orchestrator -->|"loads or creates"| node_vectorstore
node_orchestrator -->|"configures"| node_qa
node_pdfs -->|"provides PDFs"| node_loader
node_loader -->|"embeds chunks"| node_embeddings
node_loader -->|"stores chunks"| node_vectorstore
node_embeddings -->|"indexes vectors"| node_vectorstore
node_qa -->|"retrieves context"| node_vectorstore
node_qa -->|"formats context"| node_prompt
node_qa -->|"invokes model"| node_llm

click node_gradio "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_handler "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_terminal "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_orchestrator "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_loader "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_embeddings "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_vectorstore "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_qa "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_prompt "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py"
click node_llm "https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.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_pdfs,node_loader,node_embeddings,node_vectorstore,node_user toneBlue
class node_orchestrator,node_qa,node_prompt,node_llm toneAmber
class node_gradio,node_handler,node_terminal toneMint
```

## Components

### Knowledge ingestion

- **PDF documents**
- [PDF loading and splitting](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Text embeddings](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Chroma vector store](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`

### Answer generation

- [App initialization](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Retrieval QA chain](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Compassionate prompt](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Groq language model](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`

### Chat interfaces

- [Gradio UI](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Chat response handler](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`
- [Terminal chat loop](https://github.com/deepthi01-a/mental_health_chatbot/blob/main/mental_health_chatbot.py): `mental_health_chatbot.py`

### Other components

- **Chat user**

## Connections

- Chat user → Gradio UI: sends message (evidence: `mental_health_chatbot.py`)
- Gradio UI → Chat response handler: invokes (evidence: `mental_health_chatbot.py`)
- Chat response handler → Retrieval QA chain: queries (evidence: `mental_health_chatbot.py`)
- Retrieval QA chain → Chat response handler: returns answer (evidence: `mental_health_chatbot.py`)
- Chat user → Terminal chat loop: enters query (evidence: `mental_health_chatbot.py`)
- Terminal chat loop → Retrieval QA chain: queries (evidence: `mental_health_chatbot.py`)
- App initialization → Groq language model: initializes (evidence: `mental_health_chatbot.py`)
- App initialization → Chroma vector store: loads or creates (evidence: `mental_health_chatbot.py`)
- App initialization → Retrieval QA chain: configures (evidence: `mental_health_chatbot.py`)
- PDF documents → PDF loading and splitting: provides PDFs (evidence: `mental_health_chatbot.py`)
- PDF loading and splitting → Text embeddings: embeds chunks (evidence: `mental_health_chatbot.py`)
- PDF loading and splitting → Chroma vector store: stores chunks (evidence: `mental_health_chatbot.py`)
- Text embeddings → Chroma vector store: indexes vectors (evidence: `mental_health_chatbot.py`)
- Retrieval QA chain → Chroma vector store: retrieves context (evidence: `mental_health_chatbot.py`)
- Retrieval QA chain → Compassionate prompt: formats context (evidence: `mental_health_chatbot.py`)
- Retrieval QA chain → Groq language model: invokes model (evidence: `mental_health_chatbot.py`)
