# dasrohit15/safespace architecture

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

- Interactive diagram: https://gitdiagram.com/dasrohit15/safespace
- Repository: https://github.com/dasrohit15/safespace

## Overview

SafeSpace is a mental-health chat application: a user submits a message through Streamlit, FastAPI passes it to a LangGraph agent, and the backend returns the agent’s response and reported tool name for display. The agent offers therapeutic guidance through Ollama/MedGemma, a hard-coded nearby-therapist response, and an emergency-call tool using Twilio. The README is empty, and the tree does not include the imported config module, so those details are not mapped. Edges reflect the provided excerpts; unsampled integrations are omitted.

Main entry points: [`ai_agent.py`](https://github.com/dasrohit15/safespace/blob/main/ai_agent.py) (Agent runtime), [`main.py`](https://github.com/dasrohit15/safespace/blob/main/main.py) (Ask API), [`frontend.py`](https://github.com/dasrohit15/safespace/blob/main/frontend.py) (Chat UI), [`tools.py`](https://github.com/dasrohit15/safespace/blob/main/tools.py) (MedGemma client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Chat interface"]
  node_frontend["Chat UI<br/>[frontend.py]"]
end

subgraph group_backend["API backend"]
  node_api["Ask API<br/>[main.py]"]
end

subgraph group_agent["Agent and tools"]
  node_agent_runtime["Agent runtime<br/>[ai_agent.py]"]
  node_therapist_tool["Therapeutic guidance<br/>[ai_agent.py]"]
  node_emergency_tool["Emergency call tool<br/>[ai_agent.py]"]
  node_therapist_finder["Therapist finder<br/>[ai_agent.py]"]
  node_medgemma["MedGemma client<br/>[tools.py]"]
  node_twilio_client["Twilio client<br/>[tools.py]"]
end

subgraph group_integrations["External services"]
  node_openrouter["OpenRouter API"]
  node_ollama["Ollama service"]
  node_twilio["Twilio service"]
end

node_user(("User"))

node_user -->|"enters message"| node_frontend
node_frontend -->|"POSTs message"| node_api
node_api -->|"streams request"| node_agent_runtime
node_agent_runtime -->|"parses stream"| node_api
node_api -->|"returns response"| node_frontend
node_agent_runtime -->|"registers tool"| node_therapist_tool
node_agent_runtime -->|"registers tool"| node_emergency_tool
node_agent_runtime -->|"registers tool"| node_therapist_finder
node_agent_runtime -->|"configures model"| node_openrouter
node_therapist_tool -->|"calls"| node_medgemma
node_medgemma -->|"requests completion"| node_ollama
node_emergency_tool -->|"calls"| node_twilio_client
node_twilio_client -->|"places call"| node_twilio

click node_frontend "https://github.com/dasrohit15/safespace/blob/main/frontend.py"
click node_api "https://github.com/dasrohit15/safespace/blob/main/main.py"
click node_agent_runtime "https://github.com/dasrohit15/safespace/blob/main/ai_agent.py"
click node_therapist_tool "https://github.com/dasrohit15/safespace/blob/main/ai_agent.py"
click node_emergency_tool "https://github.com/dasrohit15/safespace/blob/main/ai_agent.py"
click node_therapist_finder "https://github.com/dasrohit15/safespace/blob/main/ai_agent.py"
click node_medgemma "https://github.com/dasrohit15/safespace/blob/main/tools.py"
click node_twilio_client "https://github.com/dasrohit15/safespace/blob/main/tools.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_frontend,node_user toneBlue
class node_api toneAmber
class node_agent_runtime,node_therapist_tool,node_emergency_tool,node_therapist_finder,node_medgemma,node_twilio_client toneMint
class node_openrouter,node_ollama,node_twilio toneRose
```

## Components

### Chat interface

- [Chat UI](https://github.com/dasrohit15/safespace/blob/main/frontend.py): `frontend.py`

### API backend

- [Ask API](https://github.com/dasrohit15/safespace/blob/main/main.py): `main.py`

### Agent and tools

- [Agent runtime](https://github.com/dasrohit15/safespace/blob/main/ai_agent.py): `ai_agent.py`
- [Therapeutic guidance](https://github.com/dasrohit15/safespace/blob/main/ai_agent.py): `ai_agent.py`
- [Emergency call tool](https://github.com/dasrohit15/safespace/blob/main/ai_agent.py): `ai_agent.py`
- [Therapist finder](https://github.com/dasrohit15/safespace/blob/main/ai_agent.py): `ai_agent.py`
- [MedGemma client](https://github.com/dasrohit15/safespace/blob/main/tools.py): `tools.py`
- [Twilio client](https://github.com/dasrohit15/safespace/blob/main/tools.py): `tools.py`

### External services

- **OpenRouter API**
- **Ollama service**
- **Twilio service**

### Other components

- **User**

## Connections

- User → Chat UI: enters message (evidence: `frontend.py`)
- Chat UI → Ask API: POSTs message (evidence: `frontend.py`)
- Ask API → Agent runtime: streams request (evidence: `main.py`)
- Agent runtime → Ask API: parses stream (evidence: `main.py`)
- Ask API → Chat UI: returns response (evidence: `main.py`)
- Agent runtime → Therapeutic guidance: registers tool (evidence: `ai_agent.py`)
- Agent runtime → Emergency call tool: registers tool (evidence: `ai_agent.py`)
- Agent runtime → Therapist finder: registers tool (evidence: `ai_agent.py`)
- Agent runtime → OpenRouter API: configures model (evidence: `ai_agent.py`)
- Therapeutic guidance → MedGemma client: calls (evidence: `ai_agent.py`)
- MedGemma client → Ollama service: requests completion (evidence: `tools.py`)
- Emergency call tool → Twilio client: calls (evidence: `ai_agent.py`)
- Twilio client → Twilio service: places call (evidence: `tools.py`)
