# mitohub74-sudo/chatwith architecture

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

- Interactive diagram: https://gitdiagram.com/mitohub74-sudo/chatwith
- Repository: https://github.com/mitohub74-sudo/chatwith

## Overview

Chatwith is a chat client with a Windows desktop app and a mobile H5/PWA. The main workflow is user input through the desktop renderer and IPC bridge to the main-process chat stream, which selects an OpenAI-compatible or AstrBot backend, then streams results back to the UI and saves the conversation. Sessions, configuration, and todos use local files; a separate reminder bubble handles due todos. The mobile app streams to AstrBot directly. The README documents an optional ECS HTTPS/tunnel deployment; its internal implementation is not mapped here.

Main entry points: [`src/main/ipc.ts`](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/ipc.ts) (IPC Handlers), [`src/main/chatStream.ts`](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/chatStream.ts) (Chat Streaming), [`mobile/src/App.tsx`](https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/App.tsx) (Mobile Chat App), [`src/renderer/src/App.tsx`](https://github.com/mitohub74-sudo/chatwith/blob/main/src/renderer/src/App.tsx) (Chat Window)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop Chat"]
  node_renderer_app["Chat Window<br/>[App.tsx]"]
  node_renderer_parts["Chat UI Components"]
  node_markdown["Markdown Rendering"]
end

subgraph group_runtime["Chat Runtime"]
  node_preload["Secure IPC Bridge<br/>[index.ts]"]
  node_ipc["IPC Handlers<br/>[ipc.ts]"]
  node_chatstream["Chat Streaming<br/>[chatStream.ts]"]
  node_config["Backend Configuration<br/>[config.ts]"]
end

subgraph group_local["Local Data And Reminders"]
  node_sessions["Session Management<br/>[sessionStore.ts]"]
  node_session_files[("Session Files<br/>[paths.ts]")]
  node_data_root[("User Data Directory<br/>[paths.ts]")]
  node_todos["Todo Management<br/>[todos.ts]"]
  node_todo_files[("Todo File<br/>[todos.ts]")]
  node_bubble["Reminder Bubble<br/>[bubble.ts]"]
end

subgraph group_mobile["Mobile Client"]
  node_mobile_app["Mobile Chat App<br/>[App.tsx]"]
  node_mobile_stream["Mobile SSE Client<br/>[astrbotSse.ts]"]
  node_mobile_markdown["Mobile Markdown<br/>[markdown.tsx]"]
end

node_desktop_user(("Desktop User"))
node_openai{{"OpenAI-Compatible API"}}
node_astrbot{{"AstrBot API"}}
node_mobile_user(("Mobile User"))
node_ecs{{"ECS HTTPS Tunnel"}}

node_desktop_user -->|"sends messages"| node_renderer_app
node_renderer_app -->|"renders"| node_renderer_parts
node_renderer_parts -->|"renders content"| node_markdown
node_renderer_app -->|"invokes chat IPC"| node_preload
node_preload -->|"invokes channels"| node_ipc
node_ipc -->|"dispatches chat"| node_chatstream
node_ipc -->|"manages sessions"| node_sessions
node_ipc -->|"reads status"| node_config
node_chatstream -->|"loads settings"| node_config
node_chatstream -->|"reads and writes"| node_sessions
node_chatstream -->|"streams requests"| node_openai
node_chatstream -->|"streams requests"| node_astrbot
node_sessions -->|"reads and writes"| node_session_files
node_session_files -->|"resides in"| node_data_root
node_ipc -->|"manages todos"| node_todos
node_bubble -->|"checks due items"| node_todos
node_todos -->|"reads and writes"| node_todo_files
node_mobile_user -->|"sends messages"| node_mobile_app
node_mobile_app -->|"requests stream"| node_mobile_stream
node_mobile_app -->|"renders content"| node_mobile_markdown
node_mobile_stream -->|"streams chat"| node_astrbot
node_mobile_app -.->|"uses HTTPS route"| node_ecs

click node_renderer_app "https://github.com/mitohub74-sudo/chatwith/blob/main/src/renderer/src/App.tsx"
click node_renderer_parts "https://github.com/mitohub74-sudo/chatwith/tree/main/src/renderer/src/components"
click node_markdown "https://github.com/mitohub74-sudo/chatwith/blob/main/src/renderer/src/components/MarkdownContent.tsx"
click node_preload "https://github.com/mitohub74-sudo/chatwith/blob/main/src/preload/index.ts"
click node_ipc "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/ipc.ts"
click node_chatstream "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/chatStream.ts"
click node_config "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/config.ts"
click node_sessions "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/sessionStore.ts"
click node_session_files "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/paths.ts"
click node_data_root "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/paths.ts"
click node_todos "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/todos.ts"
click node_todo_files "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/todos.ts"
click node_bubble "https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/bubble.ts"
click node_mobile_app "https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/App.tsx"
click node_mobile_stream "https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/lib/astrbotSse.ts"
click node_mobile_markdown "https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/lib/markdown.tsx"
click node_ecs "https://github.com/mitohub74-sudo/chatwith/tree/main/deploy/ecs"

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_renderer_app,node_renderer_parts,node_markdown,node_desktop_user,node_mobile_user toneBlue
class node_preload,node_ipc,node_chatstream,node_config toneAmber
class node_sessions,node_session_files,node_data_root,node_todos,node_todo_files,node_bubble,node_openai,node_astrbot toneMint
class node_mobile_app,node_mobile_stream,node_mobile_markdown toneRose
class node_ecs toneTeal
```

## Components

### Desktop Chat

- [Chat Window](https://github.com/mitohub74-sudo/chatwith/blob/main/src/renderer/src/App.tsx): `src/renderer/src/App.tsx`
- [Chat UI Components](https://github.com/mitohub74-sudo/chatwith/tree/main/src/renderer/src/components): `src/renderer/src/components`
- [Markdown Rendering](https://github.com/mitohub74-sudo/chatwith/blob/main/src/renderer/src/components/MarkdownContent.tsx): `src/renderer/src/components/MarkdownContent.tsx`

### Chat Runtime

- [Secure IPC Bridge](https://github.com/mitohub74-sudo/chatwith/blob/main/src/preload/index.ts): `src/preload/index.ts`
- [IPC Handlers](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/ipc.ts): `src/main/ipc.ts`
- [Chat Streaming](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/chatStream.ts): `src/main/chatStream.ts`
- [Backend Configuration](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/config.ts): `src/main/config.ts`

### Local Data And Reminders

- [Session Management](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/sessionStore.ts): `src/main/sessionStore.ts`
- [Session Files](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/paths.ts): `src/main/paths.ts`
- [User Data Directory](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/paths.ts): `src/main/paths.ts`
- [Todo Management](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/todos.ts): `src/main/todos.ts`
- [Todo File](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/todos.ts): `src/main/todos.ts`
- [Reminder Bubble](https://github.com/mitohub74-sudo/chatwith/blob/main/src/main/bubble.ts): `src/main/bubble.ts`

### Mobile Client

- [Mobile Chat App](https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/App.tsx): `mobile/src/App.tsx`
- [Mobile SSE Client](https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/lib/astrbotSse.ts): `mobile/src/lib/astrbotSse.ts`
- [Mobile Markdown](https://github.com/mitohub74-sudo/chatwith/blob/main/mobile/src/lib/markdown.tsx): `mobile/src/lib/markdown.tsx`

### Other components

- **Desktop User**
- **OpenAI-Compatible API**
- **AstrBot API**
- **Mobile User**
- [ECS HTTPS Tunnel](https://github.com/mitohub74-sudo/chatwith/tree/main/deploy/ecs): `deploy/ecs`

## Connections

- Desktop User → Chat Window: sends messages (evidence: `README.md`)
- Chat Window → Chat UI Components: renders (evidence: `src/renderer/src/App.tsx`)
- Chat UI Components → Markdown Rendering: renders content (evidence: `src/renderer/src/components/MessageList.tsx`)
- Chat Window → Secure IPC Bridge: invokes chat IPC (evidence: `src/renderer/src/App.tsx`)
- Secure IPC Bridge → IPC Handlers: invokes channels (evidence: `src/preload/index.ts`)
- IPC Handlers → Chat Streaming: dispatches chat (evidence: `src/main/ipc.ts`)
- IPC Handlers → Session Management: manages sessions (evidence: `src/main/ipc.ts`)
- IPC Handlers → Backend Configuration: reads status (evidence: `src/main/ipc.ts`)
- Chat Streaming → Backend Configuration: loads settings (evidence: `src/main/chatStream.ts`)
- Chat Streaming → Session Management: reads and writes (evidence: `src/main/chatStream.ts`)
- Chat Streaming → OpenAI-Compatible API: streams requests (evidence: `src/main/chatStream.ts`)
- Chat Streaming → AstrBot API: streams requests (evidence: `src/main/chatStream.ts`)
- Session Management → Session Files: reads and writes (evidence: `src/main/sessionStore.ts`)
- Session Files → User Data Directory: resides in (evidence: `src/main/paths.ts`)
- IPC Handlers → Todo Management: manages todos (evidence: `src/main/ipc.ts`)
- Reminder Bubble → Todo Management: checks due items (evidence: `src/main/bubble.ts`)
- Todo Management → Todo File: reads and writes (evidence: `src/main/todos.ts`)
- Mobile User → Mobile Chat App: sends messages (evidence: `README.md`)
- Mobile Chat App → Mobile SSE Client: requests stream (evidence: `mobile/src/App.tsx`)
- Mobile Chat App → Mobile Markdown: renders content (evidence: `mobile/src/App.tsx`)
- Mobile SSE Client → AstrBot API: streams chat (evidence: `README.md`)
- Mobile Chat App → ECS HTTPS Tunnel: uses HTTPS route (evidence: `README.md`)
