# harieswarreddygelli/ai-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/harieswarreddygelli/ai-chatbot
- Repository: https://github.com/harieswarreddygelli/ai-chatbot

## Overview

Local AI is a Flask chatbot with a browser chat interface, locally hosted Ollama inference, persistent conversations and memory, selectable assistant personalities, and optional web search with source references. The main workflow sends a user message through the browser to the Flask backend, which manages chat context and memory, selects a personality, optionally gathers web information, and streams a response from Ollama back to the browser. The backend excerpt is partial, so internal wiring beyond the documented workflow is shown only where supported.

Main entry points: [`app.py`](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py) (Chat orchestration), [`static/script.js`](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/static/script.js) (Chat UI), [`data/memory.json`](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/data/memory.json) (Persistent memory), [`chatbot/memory.py`](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/memory.py) (Chat history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Chat interface"]
  node_frontend["Chat UI<br/>[script.js]"]
  node_page["Chat page<br/>[index.html]"]
  node_markdown["Markdown renderer<br/>[markdown.js]"]
end

subgraph group_backend["Conversation backend"]
  node_backend_entry["Flask backend<br/>[app.py]"]
  node_chat_flow["Chat orchestration<br/>[app.py]"]
  node_personality["Personality prompts<br/>[personalities.py]"]
  node_search["Web search<br/>[app.py]"]
end

subgraph group_memory["Memory and history"]
  node_memory_logic["Memory extraction<br/>[app.py]"]
  node_memory_center["Memory center API<br/>[app.py]"]
  node_chat_store["Chat history<br/>[memory.py]"]
  node_summary_store["Chat summaries<br/>[summary.py]"]
  node_long_memory["Basic memory helpers<br/>[long_memory.py]"]
  node_chat_files[("Saved chats")]
  node_memory_files[("Persistent memory<br/>[memory.json]")]
  node_summary_files[("Saved summaries")]
end

subgraph group_integrations["AI and web integrations"]
  node_ollama["Ollama"]
  node_duckduckgo["DuckDuckGo"]
end

node_user(("User"))

node_user -->|"sends messages"| node_frontend
node_backend_entry -->|"renders page"| node_page
node_frontend -->|"calls API"| node_backend_entry
node_backend_entry -->|"dispatches chat"| node_chat_flow
node_chat_flow -->|"loads and saves"| node_chat_store
node_chat_flow -->|"selects prompt"| node_personality
node_chat_flow -->|"updates memory"| node_memory_logic
node_chat_flow -.->|"requests search"| node_search
node_chat_flow -->|"streams inference"| node_ollama
node_ollama -->|"returns tokens"| node_chat_flow
node_chat_flow -->|"streams response"| node_frontend
node_frontend -->|"renders responses"| node_markdown
node_search -.->|"queries web"| node_duckduckgo
node_memory_logic -->|"persists memory"| node_memory_files
node_memory_center -->|"reads and edits"| node_memory_files
node_frontend -->|"manages memories"| node_memory_center
node_chat_store -->|"reads and writes"| node_chat_files
node_summary_store -->|"reads and writes"| node_summary_files
node_long_memory -->|"reads and writes"| node_memory_files

click node_frontend "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/static/script.js"
click node_page "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/templates/index.html"
click node_markdown "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/static/markdown.js"
click node_backend_entry "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py"
click node_chat_flow "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py"
click node_personality "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/personalities.py"
click node_search "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py"
click node_memory_logic "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py"
click node_memory_center "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py"
click node_chat_store "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/memory.py"
click node_summary_store "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/summary.py"
click node_long_memory "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/long_memory.py"
click node_chat_files "https://github.com/harieswarreddygelli/ai-chatbot/tree/main/chats"
click node_memory_files "https://github.com/harieswarreddygelli/ai-chatbot/blob/main/data/memory.json"
click node_summary_files "https://github.com/harieswarreddygelli/ai-chatbot/tree/main/data/summaries"

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_frontend,node_page,node_markdown,node_user toneBlue
class node_backend_entry,node_chat_flow,node_personality,node_search toneAmber
class node_memory_logic,node_memory_center,node_chat_store,node_summary_store,node_long_memory,node_chat_files,node_memory_files,node_summary_files toneMint
class node_ollama,node_duckduckgo toneRose
```

## Components

### Chat interface

- [Chat UI](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/static/script.js): `static/script.js`
- [Chat page](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/templates/index.html): `templates/index.html`
- [Markdown renderer](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/static/markdown.js): `static/markdown.js`

### Conversation backend

- [Flask backend](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py): `app.py`
- [Chat orchestration](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py): `app.py`
- [Personality prompts](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/personalities.py): `chatbot/personalities.py`
- [Web search](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py): `app.py`

### Memory and history

- [Memory extraction](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py): `app.py`
- [Memory center API](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/app.py): `app.py`
- [Chat history](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/memory.py): `chatbot/memory.py`
- [Chat summaries](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/summary.py): `chatbot/summary.py`
- [Basic memory helpers](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/chatbot/long_memory.py): `chatbot/long_memory.py`
- [Saved chats](https://github.com/harieswarreddygelli/ai-chatbot/tree/main/chats): `chats`
- [Persistent memory](https://github.com/harieswarreddygelli/ai-chatbot/blob/main/data/memory.json): `data/memory.json`
- [Saved summaries](https://github.com/harieswarreddygelli/ai-chatbot/tree/main/data/summaries): `data/summaries`

### AI and web integrations

- **Ollama**
- **DuckDuckGo**

### Other components

- **User**

## Connections

- User → Chat UI: sends messages
- Flask backend → Chat page: renders page
- Chat UI → Flask backend: calls API
- Flask backend → Chat orchestration: dispatches chat
- Chat orchestration → Chat history: loads and saves
- Chat orchestration → Personality prompts: selects prompt
- Chat orchestration → Memory extraction: updates memory
- Chat orchestration → Web search: requests search
- Chat orchestration → Ollama: streams inference
- Ollama → Chat orchestration: returns tokens
- Chat orchestration → Chat UI: streams response
- Chat UI → Markdown renderer: renders responses
- Web search → DuckDuckGo: queries web
- Memory extraction → Persistent memory: persists memory
- Memory center API → Persistent memory: reads and edits
- Chat UI → Memory center API: manages memories
- Chat history → Saved chats: reads and writes
- Chat summaries → Saved summaries: reads and writes
- Basic memory helpers → Persistent memory: reads and writes
