# roberttips/ai-chat-voice architecture

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

- Interactive diagram: https://gitdiagram.com/roberttips/ai-chat-voice
- Repository: https://github.com/roberttips/ai-chat-voice

## Overview

1. **Overall shape**
   - This is a small, single-page local chat app with a thin Node.js server and a browser-based frontend.
   - The core architecture is: **browser UI + Web Speech API + local Node proxy/server + local Ollama daemon**.

2. **Primary runtime boundaries**
   - **Browser**: renders the UI, manages conversation state, streams assistant replies, and handles speech synthesis/recognition.
   - **Node.js server (`server.js`)**: serves the static files and proxies requests to Ollama.
   - **Ollama**: provides model metadata and chat completions locally.
   - **User’s OS/browser speech stack**: supplies available voices and microphone recognition through the Web Speech API.

3. **Frontend module layout**
   - `scripts/app.js` is the browser entrypoint and event wiring layer.
   - `scripts/dom.js` centralizes DOM references.
   - `scripts/config.js` holds shared constants.
   - `scripts/ui.js` contains UI helpers.
   - `scripts/theme.js` handles system theme detection.
   - `scripts/models.js`, `scripts/chat.js`, and `scripts/speech.js` are the main feature modules.

4. **Chat data flow**
   - User input enters through the browser UI.
   - `chat.js` sends messages to the local server, which forwards them to Ollama.
   - Assistant responses are streamed back and rendered progressively in the UI.
   - Conversation state is maintained client-side so the browser can continue the dialogue and replay past assistant messages.

5. **Model discovery and selection**
   - `models.js` loads the list of available Ollama models from the local backend.
   - The selected model becomes part of the chat request path, so model choice is a user-controlled runtime dependency rather than a build-time setting.

6. **Voice and microphone subsystem**
   - `speech.js` wraps browser speech synthesis for auto-readout and per-message replay.
   - It also wraps speech recognition via `SpeechRecognition` or `webkitSpeechRecognition`.
   - Voice selection comes from the browser/OS-installed voices, not from Ollama.
   - Hands-free mode is a browser-side loop: after spoken output ends, the app listens for a short window, waits for a pause, then submits the transcript as the next message.

7. **UI behavior and presentation**
   - `ui.js` supports interaction patterns such as buttons, state changes, and message rendering.
   - `styles/main.css` provides the full visual layer and system-aware styling.
   - `theme.js` aligns the interface with the user’s light/dark system preference.

8. **Server responsibilities**
   - `server.js` is intentionally minimal: static file hosting plus an Ollama API proxy.
   - This avoids direct browser-to-Ollama coupling issues and keeps the browser talking to one local origin.
   - The repo has no external frontend dependencies or API keys; all AI traffic stays on the local machine.

9. **Operational dependencies**
   - The app requires Ollama to be running locally and at least one model to be installed.
   - Hands-free microphone mode depends on browser support for the Web Speech API, which is typically better in Chrome/Edge.
   - Because speech voices come from the browser and operating system, available voices can differ across environments even on the same machine.

10. **Architecture takeaway**
   - The important diagram boundaries are:
     - **Presentation and interaction in the browser**
     - **Local HTTP proxy/static server in Node**
     - **Local Ollama model inference**
     - **Browser/OS speech engines for TTS and STT**
   - Most of the app logic lives in the browser; the server is only an integration boundary.

Main entry points: [`scripts/app.js`](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/app.js) (App entry), [`scripts/speech.js`](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/speech.js) (Speech), [`server.js`](https://github.com/roberttips/ai-chat-voice/blob/main/server.js) (Server), [`scripts/ui.js`](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/ui.js) (UI helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser app"]
  node_index_html["App shell<br/>html entry<br/>[index.html]"]
  node_app_js["App entry<br/>browser entry<br/>[app.js]"]
  node_dom_js["DOM refs<br/>view wiring<br/>[dom.js]"]
  node_config_js["Config<br/>constants<br/>[config.js]"]
  node_ui_js["UI helpers<br/>presentation<br/>[ui.js]"]
  node_theme_js["Theme<br/>[theme.js]"]
  node_models_js["Model picker<br/>model discovery<br/>[models.js]"]
  node_chat_js["Chat flow<br/>conversation<br/>[chat.js]"]
  node_speech_js["Speech<br/>tts/stt<br/>[speech.js]"]
  node_styles_css["Styles<br/>css theme<br/>[main.css]"]
end

subgraph group_server["Local server"]
  node_server_js["Server<br/>node proxy<br/>[server.js]"]
end

subgraph group_external["External runtimes"]
  node_ollama[("Ollama<br/>model runtime")]
  node_speech_api(("Speech API<br/>browser/OS api"))
  node_system_theme(("System theme<br/>os preference"))
  node_user(("User<br/>operator"))
end

node_index_html -->|"loads"| node_app_js
node_app_js -->|"binds"| node_dom_js
node_app_js -->|"uses"| node_config_js
node_app_js -->|"orchestrates"| node_ui_js
node_app_js -->|"initializes"| node_theme_js
node_app_js -->|"initializes"| node_models_js
node_app_js -->|"connects"| node_chat_js
node_app_js -->|"connects"| node_speech_js
node_ui_js -->|"styled by"| node_styles_css
node_theme_js -->|"reads"| node_system_theme
node_models_js -->|"fetches"| node_server_js
node_chat_js -->|"posts to"| node_server_js
node_server_js -->|"proxies"| node_ollama
node_speech_js -->|"uses"| node_speech_api
node_user -->|"drives"| node_app_js
node_user -->|"speaks/listens"| node_speech_js

click node_index_html "https://github.com/roberttips/ai-chat-voice/blob/main/index.html"
click node_app_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/app.js"
click node_dom_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/dom.js"
click node_config_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/config.js"
click node_ui_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/ui.js"
click node_theme_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/theme.js"
click node_models_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/models.js"
click node_chat_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/chat.js"
click node_speech_js "https://github.com/roberttips/ai-chat-voice/blob/main/scripts/speech.js"
click node_styles_css "https://github.com/roberttips/ai-chat-voice/blob/main/styles/main.css"
click node_server_js "https://github.com/roberttips/ai-chat-voice/blob/main/server.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_index_html,node_app_js,node_dom_js,node_config_js,node_ui_js,node_theme_js,node_models_js,node_chat_js,node_speech_js,node_styles_css toneBlue
class node_server_js toneAmber
class node_ollama,node_speech_api,node_system_theme,node_user toneMint
```

## Components

### Browser app

Client-side UI, state, and speech interactions

- [App shell](https://github.com/roberttips/ai-chat-voice/blob/main/index.html): html entry · Single-page container for the browser app · `index.html`
- [App entry](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/app.js): browser entry · Wires UI events and coordinates feature modules · `scripts/app.js`
- [DOM refs](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/dom.js): view wiring · Centralized element lookup and shared handles · `scripts/dom.js`
- [Config](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/config.js): constants · Shared client-side constants and defaults · `scripts/config.js`
- [UI helpers](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/ui.js): presentation · Message rendering and interactive UI behavior · `scripts/ui.js`
- [Theme](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/theme.js): system theme · Adapts the UI to light and dark preferences · `scripts/theme.js`
- [Model picker](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/models.js): model discovery · Loads available local models and tracks selection · `scripts/models.js`
- [Chat flow](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/chat.js): conversation · Sends prompts, streams replies, and keeps chat state · `scripts/chat.js`
- [Speech](https://github.com/roberttips/ai-chat-voice/blob/main/scripts/speech.js): tts/stt · Wraps voice output and microphone recognition · `scripts/speech.js`
- [Styles](https://github.com/roberttips/ai-chat-voice/blob/main/styles/main.css): css theme · Visual styling and responsive presentation · `styles/main.css`

### Local server

Node static host and Ollama proxy

- [Server](https://github.com/roberttips/ai-chat-voice/blob/main/server.js): node proxy · Serves static files and forwards API calls to Ollama · `server.js`

### External runtimes

Local services and browser/OS APIs

- **Ollama**: model runtime · Local model metadata and chat completion provider
- **Speech API**: browser/OS api · System voices and microphone recognition support
- **System theme**: os preference · Light/dark appearance preference from the host environment
- **User**: operator · Types messages, selects models, and uses voice controls

## Connections

- App shell → App entry: loads · Bootstraps the browser application
- App entry → DOM refs: binds · Reads shared DOM references
- App entry → Config: uses · Applies shared runtime settings
- App entry → UI helpers: orchestrates · Coordinates rendering and interaction
- App entry → Theme: initializes · Sets up theme handling
- App entry → Model picker: initializes · Fetches model list for selection
- App entry → Chat flow: connects · Routes user messages into the chat pipeline
- App entry → Speech: connects · Enables speech output and voice input
- UI helpers → Styles: styled by · Presentation is driven by the stylesheet
- Theme → System theme: reads · Follows host light/dark preference
- Model picker → Server: fetches · Requests available models from the local backend
- Chat flow → Server: posts to · Sends chat requests through the local proxy
- Server → Ollama: proxies · Forwards model and chat API traffic locally
- Speech → Speech API: uses · Wraps browser speech synthesis and recognition
- User → App entry: drives · Provides input and controls the conversation
- User → Speech: speaks/listens · Uses hands-free and replay voice features
