# pradeepvrm/lmchat architecture

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

- Interactive diagram: https://gitdiagram.com/pradeepvrm/lmchat
- Repository: https://github.com/pradeepvrm/lmchat

## Overview

This repository implements a browser-based chat application: users submit messages, the Flask backend loads conversation history, requests a streamed completion from an OpenAI-compatible service, saves the reply, and streams it back to the browser. Users can also register or sign in and access conversation-list, history, and deletion endpoints. Authentication is handled by Appwrite, while chat data is stored in PostgreSQL. The tree and sampled code establish these backend routes and the chat client; the README is empty, and the other templates’ contents were not sampled, so their detailed behavior is not shown.

Main entry points: [`app.py`](https://github.com/pradeepvrm/lmchat/blob/main/app.py) (Chat endpoint), [`static/app.js`](https://github.com/pradeepvrm/lmchat/blob/main/static/app.js) (Chat client), [`templates/index.html`](https://github.com/pradeepvrm/lmchat/blob/main/templates/index.html) (Chat page), [`auth.py`](https://github.com/pradeepvrm/lmchat/blob/main/auth.py) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Browser interface"]
  node_chatui["Chat client<br/>[app.js]"]
  node_chatpage["Chat page<br/>[index.html]"]
  node_loginpage["Login page<br/>[login.html]"]
  node_registerpage["Registration page<br/>[register.html]"]
  node_sidebar["Sidebar template<br/>[sidebar.html]"]
end

subgraph group_backend["Flask application"]
  node_flask["Flask routes<br/>[app.py]"]
  node_chatendpoint["Chat endpoint<br/>[app.py]"]
  node_conversationapi["Conversation API<br/>[app.py]"]
  node_authroutes["Auth routes<br/>[app.py]"]
end

subgraph group_identity["Identity"]
  node_auth["Authentication<br/>[auth.py]"]
  node_appwrite["Appwrite"]
end

subgraph group_chatdata["Chat data"]
  node_dbhelpers["Conversation operations<br/>[db_helpers.py]"]
  node_models["ORM models<br/>[database.py]"]
  node_postgres[("PostgreSQL")]
end

node_user(("User"))
node_modelprovider["Chat model service"]

node_user -->|"opens"| node_chatpage
node_user -->|"opens"| node_loginpage
node_user -->|"opens"| node_registerpage
node_chatpage -->|"loads"| node_chatui
node_chatui -->|"posts message"| node_chatendpoint
node_flask -->|"renders"| node_chatpage
node_flask -->|"renders"| node_loginpage
node_flask -->|"renders"| node_registerpage
node_flask -->|"renders"| node_sidebar
node_chatendpoint -->|"creates anonymous session"| node_auth
node_authroutes -->|"registers or signs in"| node_auth
node_auth -->|"calls"| node_appwrite
node_chatendpoint -->|"loads and saves messages"| node_dbhelpers
node_conversationapi -->|"reads or deletes"| node_dbhelpers
node_dbhelpers -->|"reads and writes"| node_postgres
node_chatendpoint -->|"streams completion"| node_modelprovider
node_chatendpoint -->|"streams response"| node_chatui
node_models -->|"defines schema"| node_postgres

click node_chatui "https://github.com/pradeepvrm/lmchat/blob/main/static/app.js"
click node_chatpage "https://github.com/pradeepvrm/lmchat/blob/main/templates/index.html"
click node_loginpage "https://github.com/pradeepvrm/lmchat/blob/main/templates/login.html"
click node_registerpage "https://github.com/pradeepvrm/lmchat/blob/main/templates/register.html"
click node_sidebar "https://github.com/pradeepvrm/lmchat/blob/main/templates/sidebar.html"
click node_flask "https://github.com/pradeepvrm/lmchat/blob/main/app.py"
click node_chatendpoint "https://github.com/pradeepvrm/lmchat/blob/main/app.py"
click node_conversationapi "https://github.com/pradeepvrm/lmchat/blob/main/app.py"
click node_authroutes "https://github.com/pradeepvrm/lmchat/blob/main/app.py"
click node_auth "https://github.com/pradeepvrm/lmchat/blob/main/auth.py"
click node_dbhelpers "https://github.com/pradeepvrm/lmchat/blob/main/db_helpers.py"
click node_models "https://github.com/pradeepvrm/lmchat/blob/main/database.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_chatui,node_chatpage,node_loginpage,node_registerpage,node_sidebar,node_user toneBlue
class node_flask,node_chatendpoint,node_conversationapi,node_authroutes toneAmber
class node_auth,node_appwrite toneMint
class node_dbhelpers,node_models,node_postgres toneRose
class node_modelprovider toneIndigo
```

## Components

### Browser interface

- [Chat client](https://github.com/pradeepvrm/lmchat/blob/main/static/app.js): `static/app.js`
- [Chat page](https://github.com/pradeepvrm/lmchat/blob/main/templates/index.html): `templates/index.html`
- [Login page](https://github.com/pradeepvrm/lmchat/blob/main/templates/login.html): `templates/login.html`
- [Registration page](https://github.com/pradeepvrm/lmchat/blob/main/templates/register.html): `templates/register.html`
- [Sidebar template](https://github.com/pradeepvrm/lmchat/blob/main/templates/sidebar.html): `templates/sidebar.html`

### Flask application

- [Flask routes](https://github.com/pradeepvrm/lmchat/blob/main/app.py): `app.py`
- [Chat endpoint](https://github.com/pradeepvrm/lmchat/blob/main/app.py): `app.py`
- [Conversation API](https://github.com/pradeepvrm/lmchat/blob/main/app.py): `app.py`
- [Auth routes](https://github.com/pradeepvrm/lmchat/blob/main/app.py): `app.py`

### Identity

- [Authentication](https://github.com/pradeepvrm/lmchat/blob/main/auth.py): `auth.py`
- **Appwrite**

### Chat data

- [Conversation operations](https://github.com/pradeepvrm/lmchat/blob/main/db_helpers.py): `db_helpers.py`
- [ORM models](https://github.com/pradeepvrm/lmchat/blob/main/database.py): `database.py`
- **PostgreSQL**

### Other components

- **User**
- **Chat model service**

## Connections

- User → Chat page: opens
- User → Login page: opens
- User → Registration page: opens
- Chat page → Chat client: loads
- Chat client → Chat endpoint: posts message
- Flask routes → Chat page: renders
- Flask routes → Login page: renders
- Flask routes → Registration page: renders
- Flask routes → Sidebar template: renders
- Chat endpoint → Authentication: creates anonymous session
- Auth routes → Authentication: registers or signs in
- Authentication → Appwrite: calls
- Chat endpoint → Conversation operations: loads and saves messages
- Conversation API → Conversation operations: reads or deletes
- Conversation operations → PostgreSQL: reads and writes
- Chat endpoint → Chat model service: streams completion
- Chat endpoint → Chat client: streams response
- ORM models → PostgreSQL: defines schema
