# yuazhi/yuazhi-chat architecture

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

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

## Overview

yuazhi-chat is a browser-based AI chat application with PHP account and conversation APIs, a JavaScript chat client, and an AI image-generation proxy. The main flow is an authenticated user opening the chat UI, sending prompts through the client API layer, and seeing responses; image prompts use a separate proxy. PHP also handles account actions and persisted chat history. The README describes broader messaging features, but the sampled files do not verify WebSockets, group chat, offline push, or Redis; those connections are omitted. Database persistence is visible in the PHP API, while db.js appears separate and is not shown in the request path.

Main entry points: [`index.php`](https://github.com/yuazhi/yuazhi-chat/blob/main/index.php) (Chat page), [`main.js`](https://github.com/yuazhi/yuazhi-chat/blob/main/main.js) (Chat interactions), [`api.js`](https://github.com/yuazhi/yuazhi-chat/blob/main/api.js) (API client), [`login.php`](https://github.com/yuazhi/yuazhi-chat/blob/main/login.php) (Login and registration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_chat_ui["Chat page<br/>[index.php]"]
  node_chat_runtime["Chat interactions<br/>[main.js]"]
  node_api_client["API client<br/>[api.js]"]
  node_browser_cache["Offline cache<br/>[sw.js]"]
end

subgraph group_backend["PHP services"]
  node_chat_api["Chat API<br/>[api.php]"]
end

subgraph group_persistence["Persistence"]
  node_config["Database config<br/>[config.php]"]
  node_mysql[("MySQL data")]
  node_db_helpers["JS data helpers<br/>[db.js]"]
end

subgraph group_identity["Account access"]
  node_auth_pages["Login and registration<br/>[login.php]"]
  node_registration["Registration page<br/>[register.php]"]
  node_account_api["Account actions<br/>[api.php]"]
  node_recovery["Password recovery"]
  node_reset["Password reset<br/>[reset-password.php]"]
  node_logout["Logout<br/>[logout.php]"]
end

subgraph group_ai["AI integrations"]
  node_draw_client["Drawing request<br/>[api.js]"]
  node_draw_proxy["Drawing proxy<br/>[draw_proxy.php]"]
  node_image_service["Image generation API"]
  node_llm_service["Chat completion API"]
  node_download["Image download proxy<br/>[download_proxy.php]"]
end

node_user(("User"))

node_user -->|"opens"| node_chat_ui
node_chat_ui -.->|"hosts"| node_chat_runtime
node_chat_runtime -->|"calls"| node_api_client
node_api_client -->|"sends prompts"| node_llm_service
node_registration -->|"posts registration"| node_account_api
node_auth_pages -->|"posts login"| node_account_api
node_chat_api -->|"reads and writes"| node_mysql
node_draw_client -->|"posts prompt"| node_draw_proxy
node_draw_proxy -->|"requests image"| node_image_service
node_chat_ui -->|"registers worker"| node_browser_cache
node_db_helpers -->|"queries"| node_mysql
node_user -->|"signs in"| node_auth_pages
node_user -->|"registers"| node_registration

click node_chat_ui "https://github.com/yuazhi/yuazhi-chat/blob/main/index.php"
click node_chat_runtime "https://github.com/yuazhi/yuazhi-chat/blob/main/main.js"
click node_api_client "https://github.com/yuazhi/yuazhi-chat/blob/main/api.js"
click node_chat_api "https://github.com/yuazhi/yuazhi-chat/blob/main/api.php"
click node_auth_pages "https://github.com/yuazhi/yuazhi-chat/blob/main/login.php"
click node_registration "https://github.com/yuazhi/yuazhi-chat/blob/main/register.php"
click node_account_api "https://github.com/yuazhi/yuazhi-chat/blob/main/api.php"
click node_recovery "https://github.com/yuazhi/yuazhi-chat/blob/main/forgot-password.php"
click node_reset "https://github.com/yuazhi/yuazhi-chat/blob/main/reset-password.php"
click node_logout "https://github.com/yuazhi/yuazhi-chat/blob/main/logout.php"
click node_config "https://github.com/yuazhi/yuazhi-chat/blob/main/config.php"
click node_db_helpers "https://github.com/yuazhi/yuazhi-chat/blob/main/db.js"
click node_draw_client "https://github.com/yuazhi/yuazhi-chat/blob/main/api.js"
click node_draw_proxy "https://github.com/yuazhi/yuazhi-chat/blob/main/draw_proxy.php"
click node_download "https://github.com/yuazhi/yuazhi-chat/blob/main/download_proxy.php"
click node_browser_cache "https://github.com/yuazhi/yuazhi-chat/blob/main/sw.js"

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_chat_ui,node_chat_runtime,node_api_client,node_browser_cache,node_user toneBlue
class node_chat_api toneAmber
class node_config,node_mysql,node_db_helpers toneMint
class node_auth_pages,node_registration,node_account_api,node_recovery,node_reset,node_logout toneRose
class node_draw_client,node_draw_proxy,node_image_service,node_llm_service,node_download toneIndigo
```

## Components

### Chat client

- [Chat page](https://github.com/yuazhi/yuazhi-chat/blob/main/index.php): `index.php`
- [Chat interactions](https://github.com/yuazhi/yuazhi-chat/blob/main/main.js): `main.js`
- [API client](https://github.com/yuazhi/yuazhi-chat/blob/main/api.js): `api.js`
- [Offline cache](https://github.com/yuazhi/yuazhi-chat/blob/main/sw.js): `sw.js`

### PHP services

- [Chat API](https://github.com/yuazhi/yuazhi-chat/blob/main/api.php): `api.php`

### Persistence

- [Database config](https://github.com/yuazhi/yuazhi-chat/blob/main/config.php): `config.php`
- **MySQL data**
- [JS data helpers](https://github.com/yuazhi/yuazhi-chat/blob/main/db.js): `db.js`

### Account access

- [Login and registration](https://github.com/yuazhi/yuazhi-chat/blob/main/login.php): `login.php`
- [Registration page](https://github.com/yuazhi/yuazhi-chat/blob/main/register.php): `register.php`
- [Account actions](https://github.com/yuazhi/yuazhi-chat/blob/main/api.php): `api.php`
- [Password recovery](https://github.com/yuazhi/yuazhi-chat/blob/main/forgot-password.php): `forgot-password.php`
- [Password reset](https://github.com/yuazhi/yuazhi-chat/blob/main/reset-password.php): `reset-password.php`
- [Logout](https://github.com/yuazhi/yuazhi-chat/blob/main/logout.php): `logout.php`

### AI integrations

- [Drawing request](https://github.com/yuazhi/yuazhi-chat/blob/main/api.js): `api.js`
- [Drawing proxy](https://github.com/yuazhi/yuazhi-chat/blob/main/draw_proxy.php): `draw_proxy.php`
- **Image generation API**
- **Chat completion API**
- [Image download proxy](https://github.com/yuazhi/yuazhi-chat/blob/main/download_proxy.php): `download_proxy.php`

### Other components

- **User**

## Connections

- User → Chat page: opens (evidence: `index.php`)
- Chat page → Chat interactions: hosts
- Chat interactions → API client: calls (evidence: `main.js`)
- API client → Chat completion API: sends prompts (evidence: `api.js`)
- Registration page → Account actions: posts registration (evidence: `register.php`)
- Login and registration → Account actions: posts login (evidence: `login.php`)
- Chat API → MySQL data: reads and writes (evidence: `api.php`)
- Drawing request → Drawing proxy: posts prompt (evidence: `api.js`)
- Drawing proxy → Image generation API: requests image (evidence: `draw_proxy.php`)
- Chat page → Offline cache: registers worker (evidence: `index.php`)
- JS data helpers → MySQL data: queries (evidence: `db.js`)
- User → Login and registration: signs in (evidence: `login.php`)
- User → Registration page: registers (evidence: `register.php`)
