# kongogaming/pocketai architecture

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

- Interactive diagram: https://gitdiagram.com/kongogaming/pocketai
- Repository: https://github.com/kongogaming/pocketai

## Overview

PocketAI is a local-first terminal assistant for chatting with Ollama and managing conversations, models, themes, and document-based RAG. The principal workflow runs from terminal input through the CLI: ordinary prompts stream responses from Ollama, while document-chat prompts retrieve relevant indexed chunks and ask Ollama using that context. Separate CLI commands manage setup, chat history, search, exports, models, and documents. The RAG indexing and retrieval links are visible in source; some CLI command-to-feature links rely on the README because the main-module excerpt is partial.

Main entry points: [`pocketai/main.py`](https://github.com/kongogaming/pocketai/blob/main/pocketai/main.py) (CLI orchestrator), [`pocketai/rag.py`](https://github.com/kongogaming/pocketai/blob/main/pocketai/rag.py) (RAG workflow), [`pocketai/ai.py`](https://github.com/kongogaming/pocketai/blob/main/pocketai/ai.py) (Chat streaming), [`pocketai/config.py`](https://github.com/kongogaming/pocketai/blob/main/pocketai/config.py) (Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Terminal app"]
  node_main["CLI orchestrator<br/>[main.py]"]
  node_ui["Terminal UI<br/>[ui.py]"]
end

subgraph group_chat["Chat and history"]
  node_chat_ai["Chat streaming<br/>[ai.py]"]
  node_chat_store[("Chat history store<br/>[storage.py]")]
  node_search["Conversation search<br/>[search.py]"]
  node_export["Conversation export<br/>[exporter.py]"]
end

subgraph group_rag["Document RAG"]
  node_rag["RAG workflow<br/>[rag.py]"]
  node_loaders["Document loaders<br/>[loaders.py]"]
  node_chunking["Text chunking<br/>[chunking.py]"]
  node_embeddings["Embedding client<br/>[embeddings.py]"]
  node_documents[("Document registry<br/>[documents.py]")]
  node_vectors[("Vector index<br/>[vectors.py]")]
end

subgraph group_support["Setup and settings"]
  node_setup["First-run setup<br/>[setup.py]"]
  node_setup_ui["Setup screens<br/>[setup_ui.py]"]
  node_config["Configuration<br/>[config.py]"]
  node_themes["Theme system<br/>[theme.py]"]
  node_models["Model manager<br/>[models.py]"]
  node_updater["Update checker<br/>[updater.py]"]
end

node_user(("Terminal user"))
node_ollama{{"Ollama server"}}

node_user -->|"enters commands"| node_main
node_main -->|"renders screens"| node_ui
node_main -->|"starts setup"| node_setup
node_setup -->|"uses prompts"| node_setup_ui
node_main -->|"loads settings"| node_config
node_main -->|"requests replies"| node_chat_ai
node_chat_ai -->|"streams chat"| node_ollama
node_main -->|"manages chats"| node_chat_store
node_main -->|"searches history"| node_search
node_main -->|"exports chats"| node_export
node_main -->|"manages models"| node_models
node_main -->|"checks updates"| node_updater
node_main -->|"sets theme"| node_themes
node_ui -->|"uses styles"| node_themes
node_chat_store -->|"reads model"| node_config
node_main -->|"indexes and queries"| node_rag
node_rag -->|"loads documents"| node_loaders
node_rag -->|"chunks text"| node_chunking
node_rag -->|"creates embeddings"| node_embeddings
node_rag -->|"registers files"| node_documents
node_rag -->|"indexes and searches"| node_vectors
node_rag -->|"asks with context"| node_chat_ai
node_embeddings -->|"requests vectors"| node_ollama
node_vectors -->|"loads settings"| node_config

click node_main "https://github.com/kongogaming/pocketai/blob/main/pocketai/main.py"
click node_ui "https://github.com/kongogaming/pocketai/blob/main/pocketai/ui.py"
click node_setup "https://github.com/kongogaming/pocketai/blob/main/pocketai/setup.py"
click node_setup_ui "https://github.com/kongogaming/pocketai/blob/main/pocketai/setup_ui.py"
click node_config "https://github.com/kongogaming/pocketai/blob/main/pocketai/config.py"
click node_themes "https://github.com/kongogaming/pocketai/blob/main/pocketai/theme.py"
click node_models "https://github.com/kongogaming/pocketai/blob/main/pocketai/models.py"
click node_updater "https://github.com/kongogaming/pocketai/blob/main/pocketai/updater.py"
click node_chat_ai "https://github.com/kongogaming/pocketai/blob/main/pocketai/ai.py"
click node_chat_store "https://github.com/kongogaming/pocketai/blob/main/pocketai/storage.py"
click node_search "https://github.com/kongogaming/pocketai/blob/main/pocketai/search.py"
click node_export "https://github.com/kongogaming/pocketai/blob/main/pocketai/exporter.py"
click node_rag "https://github.com/kongogaming/pocketai/blob/main/pocketai/rag.py"
click node_loaders "https://github.com/kongogaming/pocketai/blob/main/pocketai/loaders.py"
click node_chunking "https://github.com/kongogaming/pocketai/blob/main/pocketai/chunking.py"
click node_embeddings "https://github.com/kongogaming/pocketai/blob/main/pocketai/embeddings.py"
click node_documents "https://github.com/kongogaming/pocketai/blob/main/pocketai/documents.py"
click node_vectors "https://github.com/kongogaming/pocketai/blob/main/pocketai/vectors.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_main,node_ui,node_user toneBlue
class node_chat_ai,node_chat_store,node_search,node_export toneAmber
class node_rag,node_loaders,node_chunking,node_embeddings,node_documents,node_vectors,node_ollama toneMint
class node_setup,node_setup_ui,node_config,node_themes,node_models,node_updater toneRose
```

## Components

### Terminal app

- [CLI orchestrator](https://github.com/kongogaming/pocketai/blob/main/pocketai/main.py): `pocketai/main.py`
- [Terminal UI](https://github.com/kongogaming/pocketai/blob/main/pocketai/ui.py): `pocketai/ui.py`

### Chat and history

- [Chat streaming](https://github.com/kongogaming/pocketai/blob/main/pocketai/ai.py): `pocketai/ai.py`
- [Chat history store](https://github.com/kongogaming/pocketai/blob/main/pocketai/storage.py): `pocketai/storage.py`
- [Conversation search](https://github.com/kongogaming/pocketai/blob/main/pocketai/search.py): `pocketai/search.py`
- [Conversation export](https://github.com/kongogaming/pocketai/blob/main/pocketai/exporter.py): `pocketai/exporter.py`

### Document RAG

- [RAG workflow](https://github.com/kongogaming/pocketai/blob/main/pocketai/rag.py): `pocketai/rag.py`
- [Document loaders](https://github.com/kongogaming/pocketai/blob/main/pocketai/loaders.py): `pocketai/loaders.py`
- [Text chunking](https://github.com/kongogaming/pocketai/blob/main/pocketai/chunking.py): `pocketai/chunking.py`
- [Embedding client](https://github.com/kongogaming/pocketai/blob/main/pocketai/embeddings.py): `pocketai/embeddings.py`
- [Document registry](https://github.com/kongogaming/pocketai/blob/main/pocketai/documents.py): `pocketai/documents.py`
- [Vector index](https://github.com/kongogaming/pocketai/blob/main/pocketai/vectors.py): `pocketai/vectors.py`

### Setup and settings

- [First-run setup](https://github.com/kongogaming/pocketai/blob/main/pocketai/setup.py): `pocketai/setup.py`
- [Setup screens](https://github.com/kongogaming/pocketai/blob/main/pocketai/setup_ui.py): `pocketai/setup_ui.py`
- [Configuration](https://github.com/kongogaming/pocketai/blob/main/pocketai/config.py): `pocketai/config.py`
- [Theme system](https://github.com/kongogaming/pocketai/blob/main/pocketai/theme.py): `pocketai/theme.py`
- [Model manager](https://github.com/kongogaming/pocketai/blob/main/pocketai/models.py): `pocketai/models.py`
- [Update checker](https://github.com/kongogaming/pocketai/blob/main/pocketai/updater.py): `pocketai/updater.py`

### Other components

- **Terminal user**
- **Ollama server**

## Connections

- Terminal user → CLI orchestrator: enters commands (evidence: `README.md`)
- CLI orchestrator → Terminal UI: renders screens (evidence: `pocketai/main.py`)
- CLI orchestrator → First-run setup: starts setup (evidence: `pocketai/main.py`)
- First-run setup → Setup screens: uses prompts (evidence: `pocketai/setup.py`)
- CLI orchestrator → Configuration: loads settings (evidence: `pocketai/main.py`)
- CLI orchestrator → Chat streaming: requests replies (evidence: `pocketai/main.py`)
- Chat streaming → Ollama server: streams chat (evidence: `pocketai/ai.py`)
- CLI orchestrator → Chat history store: manages chats (evidence: `README.md`)
- CLI orchestrator → Conversation search: searches history (evidence: `README.md`)
- CLI orchestrator → Conversation export: exports chats (evidence: `README.md`)
- CLI orchestrator → Model manager: manages models (evidence: `README.md`)
- CLI orchestrator → Update checker: checks updates (evidence: `README.md`)
- CLI orchestrator → Theme system: sets theme (evidence: `pocketai/main.py`)
- Terminal UI → Theme system: uses styles (evidence: `pocketai/ui.py`)
- Chat history store → Configuration: reads model (evidence: `pocketai/storage.py`)
- CLI orchestrator → RAG workflow: indexes and queries (evidence: `pocketai/main.py`)
- RAG workflow → Document loaders: loads documents (evidence: `pocketai/rag.py`)
- RAG workflow → Text chunking: chunks text (evidence: `pocketai/rag.py`)
- RAG workflow → Embedding client: creates embeddings (evidence: `pocketai/rag.py`)
- RAG workflow → Document registry: registers files (evidence: `pocketai/rag.py`)
- RAG workflow → Vector index: indexes and searches (evidence: `pocketai/rag.py`)
- RAG workflow → Chat streaming: asks with context (evidence: `pocketai/rag.py`)
- Embedding client → Ollama server: requests vectors (evidence: `pocketai/embeddings.py`)
- Vector index → Configuration: loads settings (evidence: `pocketai/vectors.py`)
