# deepanshugupta8772/modelswitch-chat architecture

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

- Interactive diagram: https://gitdiagram.com/deepanshugupta8772/modelswitch-chat
- Repository: https://github.com/deepanshugupta8772/modelswitch-chat

## Overview

ModelSwitch Chat is a React/FastAPI LLM chat application. A user submits a message through the composer; the frontend sends it to the chat route, which loads session history, checks the response cache, optionally simulates failures and attempts configured provider keys, then persists a successful exchange and returns reply metadata. The README also documents health monitoring and session-history retrieval. The backend excerpts show the orchestration and persistence boundaries; provider and cache relationships are supported by the README, while deployment details are omitted as runtime architecture.

Main entry points: [`backend/app/routes.py`](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/routes.py) (Chat and history routes), [`frontend/src/App.jsx`](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/App.jsx) (Chat application), [`backend/app/main.py`](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/main.py) (API server and health), [`backend/app/db.py`](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/db.py) (Session history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat frontend"]
  node_app["Chat application<br/>[App.jsx]"]
  node_composer["Message composer<br/>[Composer.jsx]"]
  node_api_client["Chat API client<br/>[api.js]"]
  node_message_view["Message display<br/>[Message.jsx]"]
  node_metadata_view["Reply metadata<br/>[Metadata.jsx]"]
end

subgraph group_api["Backend API"]
  node_chat_api["Chat and history routes<br/>[routes.py]"]
  node_app_server["API server and health<br/>[main.py]"]
  node_schemas["Request and response schemas<br/>[schemas.py]"]
  node_settings["Application settings<br/>[config.py]"]
end

subgraph group_inference["Inference resilience"]
  node_failure_sim["Failure simulation<br/>[simulate.py]"]
  node_inference_cache["Response cache<br/>[llm.py]"]
  node_llm_calls["Provider inference<br/>[llm.py]"]
end

subgraph group_state["Session state"]
  node_session_store[("Session history<br/>[db.py]")]
end

node_user(("Chat user"))
node_provider{{"LLM provider"}}

node_user -->|"submits chat"| node_app
node_app -->|"renders"| node_composer
node_app -->|"sends message"| node_api_client
node_api_client -->|"POST /chat"| node_chat_api
node_chat_api -->|"loads history"| node_session_store
node_chat_api -->|"checks cache"| node_inference_cache
node_chat_api -->|"parses simulation"| node_failure_sim
node_chat_api -->|"requests inference"| node_llm_calls
node_llm_calls -->|"calls model"| node_provider
node_chat_api -->|"saves exchange"| node_session_store
node_chat_api -->|"validates and shapes"| node_schemas
node_app_server -->|"registers routes"| node_chat_api
node_app_server -->|"initializes database"| node_session_store
node_chat_api -->|"reads settings"| node_settings
node_app_server -->|"configures health"| node_settings
node_app -->|"renders messages"| node_message_view
node_message_view -->|"renders metadata"| node_metadata_view

click node_app "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/App.jsx"
click node_composer "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/components/Composer.jsx"
click node_api_client "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/api.js"
click node_message_view "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/components/Message.jsx"
click node_metadata_view "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/components/Metadata.jsx"
click node_chat_api "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/routes.py"
click node_app_server "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/main.py"
click node_schemas "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/schemas.py"
click node_settings "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/config.py"
click node_failure_sim "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/simulate.py"
click node_inference_cache "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/llm.py"
click node_llm_calls "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/llm.py"
click node_session_store "https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/db.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_app,node_composer,node_api_client,node_message_view,node_metadata_view,node_user toneBlue
class node_chat_api,node_app_server,node_schemas,node_settings toneAmber
class node_failure_sim,node_inference_cache,node_llm_calls toneMint
class node_session_store toneRose
class node_provider toneIndigo
```

## Components

### Chat frontend

- [Chat application](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Message composer](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/components/Composer.jsx): `frontend/src/components/Composer.jsx`
- [Chat API client](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/api.js): `frontend/src/api.js`
- [Message display](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/components/Message.jsx): `frontend/src/components/Message.jsx`
- [Reply metadata](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/frontend/src/components/Metadata.jsx): `frontend/src/components/Metadata.jsx`

### Backend API

- [Chat and history routes](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/routes.py): `backend/app/routes.py`
- [API server and health](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/main.py): `backend/app/main.py`
- [Request and response schemas](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/schemas.py): `backend/app/schemas.py`
- [Application settings](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/config.py): `backend/app/config.py`

### Inference resilience

- [Failure simulation](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/simulate.py): `backend/app/simulate.py`
- [Response cache](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/llm.py): `backend/app/llm.py`
- [Provider inference](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/llm.py): `backend/app/llm.py`

### Session state

- [Session history](https://github.com/deepanshugupta8772/modelswitch-chat/blob/main/backend/app/db.py): `backend/app/db.py`

### Other components

- **Chat user**
- **LLM provider**

## Connections

- Chat user → Chat application: submits chat (evidence: `frontend/src/App.jsx`)
- Chat application → Message composer: renders (evidence: `frontend/src/App.jsx`)
- Chat application → Chat API client: sends message (evidence: `frontend/src/App.jsx`)
- Chat API client → Chat and history routes: POST /chat (evidence: `README.md`)
- Chat and history routes → Session history: loads history (evidence: `backend/app/routes.py`)
- Chat and history routes → Response cache: checks cache (evidence: `backend/app/routes.py`)
- Chat and history routes → Failure simulation: parses simulation (evidence: `backend/app/routes.py`)
- Chat and history routes → Provider inference: requests inference (evidence: `backend/app/routes.py`)
- Provider inference → LLM provider: calls model (evidence: `README.md`)
- Chat and history routes → Session history: saves exchange (evidence: `backend/app/routes.py`)
- Chat and history routes → Request and response schemas: validates and shapes (evidence: `backend/app/routes.py`)
- API server and health → Chat and history routes: registers routes (evidence: `backend/app/main.py`)
- API server and health → Session history: initializes database (evidence: `backend/app/main.py`)
- Chat and history routes → Application settings: reads settings (evidence: `backend/app/routes.py`)
- API server and health → Application settings: configures health (evidence: `backend/app/main.py`)
- Chat application → Message display: renders messages (evidence: `frontend/src/App.jsx`)
- Message display → Reply metadata: renders metadata (evidence: `frontend/src/components/Message.jsx`)
