# phantom-1111/mental-health-ai-chatbot architecture

> Architecture diagram of the GitHub repository phantom-1111/mental-health-ai-chatbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/phantom-1111/mental-health-ai-chatbot
- Repository: https://github.com/phantom-1111/mental-health-ai-chatbot

## Overview

This is a mental-health chatbot: a user submits text through either the API or interactive demo, the combined analyzer derives sentiment, emotion, and safety signals, and the response generator uses that analysis and conversation history to produce a supportive reply. The sampled API confirms the analysis and response calls; classifier implementations for sentiment and emotion were not sampled, so their internal model details are omitted.

Main entry points: [`api/main.py`](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/api/main.py) (Chat API), [`ml/combined/analyze.py`](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/combined/analyze.py) (Combined analyzer), [`llm/response.py`](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/llm/response.py) (Response generator), [`demo.py`](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/demo.py) (Terminal demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Chat interaction"]
  node_api["Chat API<br/>[main.py]"]
  node_demo["Terminal demo<br/>[demo.py]"]
  node_history[("Conversation history<br/>[main.py]")]
end

subgraph group_analysis["Text analysis"]
  node_analyzer["Combined analyzer<br/>[analyze.py]"]
  node_sentiment["Sentiment analysis"]
  node_emotion["Emotion analysis"]
  node_safety["Safety analysis"]
end

subgraph group_generation["Response generation"]
  node_generator["Response generator<br/>[response.py]"]
end

node_user(("User"))
node_groq["Groq chat service"]

node_user -->|"submits message"| node_api
node_user -->|"enters text"| node_demo
node_api -->|"analyzes text"| node_analyzer
node_demo -->|"analyzes text"| node_analyzer
node_analyzer -->|"calls"| node_sentiment
node_analyzer -->|"calls"| node_emotion
node_analyzer -->|"calls"| node_safety
node_api -->|"requests reply"| node_generator
node_demo -->|"requests reply"| node_generator
node_api -->|"updates"| node_history
node_api -->|"passes history"| node_generator
node_demo -->|"passes history"| node_generator
node_generator -->|"requests completion"| node_groq

click node_api "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/api/main.py"
click node_demo "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/demo.py"
click node_history "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/api/main.py"
click node_analyzer "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/combined/analyze.py"
click node_sentiment "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/sentiment/predict_function.py"
click node_emotion "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/emotion/predict_function.py"
click node_safety "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/safety/predict_function.py"
click node_generator "https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/llm/response.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_api,node_demo,node_history,node_user toneBlue
class node_analyzer,node_sentiment,node_emotion,node_safety toneAmber
class node_generator toneMint
class node_groq toneIndigo
```

## Components

### Chat interaction

- [Chat API](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/api/main.py): `api/main.py`
- [Terminal demo](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/demo.py): `demo.py`
- [Conversation history](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/api/main.py): `api/main.py`

### Text analysis

- [Combined analyzer](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/combined/analyze.py): `ml/combined/analyze.py`
- [Sentiment analysis](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/sentiment/predict_function.py): `ml/sentiment/predict_function.py`
- [Emotion analysis](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/emotion/predict_function.py): `ml/emotion/predict_function.py`
- [Safety analysis](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/ml/safety/predict_function.py): `ml/safety/predict_function.py`

### Response generation

- [Response generator](https://github.com/phantom-1111/mental-health-ai-chatbot/blob/master/llm/response.py): `llm/response.py`

### Other components

- **User**
- **Groq chat service**

## Connections

- User → Chat API: submits message
- User → Terminal demo: enters text
- Chat API → Combined analyzer: analyzes text
- Terminal demo → Combined analyzer: analyzes text
- Combined analyzer → Sentiment analysis: calls
- Combined analyzer → Emotion analysis: calls
- Combined analyzer → Safety analysis: calls
- Chat API → Response generator: requests reply
- Terminal demo → Response generator: requests reply
- Chat API → Conversation history: updates
- Chat API → Response generator: passes history
- Terminal demo → Response generator: passes history
- Response generator → Groq chat service: requests completion
