# talha-ai-spec/nexusmind architecture

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

- Interactive diagram: https://gitdiagram.com/talha-ai-spec/nexusmind
- Repository: https://github.com/talha-ai-spec/nexusmind

## Overview

NexusMind is a local-first, multimodal AI workspace: people use its web UI for streaming chat, image tasks, document RAG, and voice conversations. The principal chat flow runs from the web chat through the API’s chat route and service, which selects local or cloud models and streams results back. Other product branches cover image generation, voice, the document library, and observability. Edges reflect README workflow statements and shown wiring; unsampled implementation details are not asserted.

Main entry points: [`copilot-app/api/app/main.py`](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/main.py) (API application), [`copilot-app/api/app/voice/routes.py`](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/voice/routes.py) (Voice API), [`copilot-app/api/app/providers/registry.py`](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/providers/registry.py) (Provider selection), [`copilot-app/api/app/providers/base.py`](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/providers/base.py) (Model providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workspace"]
  node_webchat["Chat interface<br/>[chat-app.tsx]"]
  node_chat_hook["Chat state<br/>[use-chat.ts]"]
  node_webapi["Web API client<br/>[api.ts]"]
end

subgraph group_api["API and chat"]
  node_apiapp["API application<br/>[main.py]"]
  node_chatroute["Chat route<br/>[chat.py]"]
  node_chatservice["Chat streaming<br/>[chat.py]"]
  node_registry["Provider selection<br/>[registry.py]"]
  node_provider["Model providers<br/>[base.py]"]
end

subgraph group_media["Media features"]
  node_vision["Vision capability<br/>[vision.py]"]
  node_imageui["Image tools"]
  node_imageroute["Image routes<br/>[images.py]"]
  node_imagegen["Image generation<br/>[image_gen.py]"]
end

subgraph group_voice["Voice conversations"]
  node_voiceui["Voice session UI<br/>[voice-session.tsx]"]
  node_voiceroutes["Voice API<br/>[routes.py]"]
  node_voiceagent["LiveKit agent<br/>[voice_agent.py]"]
  node_app_llm["API-backed LLM<br/>[app_llm.py]"]
end

subgraph group_library["Document library"]
  node_libraryui["Library workspace<br/>[documents.tsx]"]
  node_libroutes["Library routes<br/>[routes.py]"]
  node_libservice["Library service<br/>[service.py]"]
  node_libdb[("Document records<br/>[db.py]")]
  node_ragengine["RAG engine contract<br/>[engine.py]"]
  node_offline["Offline RAG<br/>[offline.py]"]
  node_gemini_search["Gemini File Search<br/>[gemini.py]"]
end

node_person(("User"))
node_ollama{{"Ollama"}}
node_cloudmodels{{"Cloud models"}}
node_imageengines{{"Image engines"}}
node_livekit{{"LiveKit"}}

node_person -->|"uses"| node_webchat
node_webchat -->|"updates"| node_chat_hook
node_chat_hook -->|"requests"| node_webapi
node_webapi -->|"calls"| node_chatroute
node_apiapp -->|"mounts"| node_chatroute
node_chatroute -->|"handles chat"| node_chatservice
node_chatservice -->|"selects models"| node_registry
node_registry -->|"dispatches"| node_provider
node_provider -->|"serves locally"| node_ollama
node_provider -->|"falls back"| node_cloudmodels
node_registry -->|"checks capability"| node_vision
node_person -->|"requests images"| node_imageui
node_imageui -->|"submits"| node_imageroute
node_apiapp -->|"mounts"| node_imageroute
node_imageroute -->|"invokes"| node_imagegen
node_imagegen -->|"generates with"| node_imageengines
node_person -->|"starts voice"| node_voiceui
node_voiceui -->|"creates session"| node_voiceroutes
node_apiapp -->|"mounts"| node_voiceroutes
node_voiceroutes -->|"dispatches agent"| node_livekit
node_livekit -->|"connects agent"| node_voiceagent
node_voiceagent -->|"uses"| node_app_llm
node_app_llm -->|"streams chat"| node_voiceroutes
node_person -->|"manages documents"| node_libraryui
node_libraryui -->|"uses library API"| node_libroutes
node_apiapp -->|"mounts"| node_libroutes
node_libroutes -->|"delegates"| node_libservice
node_libservice -->|"reads and writes"| node_libdb
node_libservice -->|"indexes and answers"| node_ragengine
node_ragengine -->|"implemented by"| node_offline
node_ragengine -->|"implemented by"| node_gemini_search

click node_webchat "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/chat/chat-app.tsx"
click node_chat_hook "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/hooks/use-chat.ts"
click node_webapi "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/lib/api.ts"
click node_apiapp "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/main.py"
click node_chatroute "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/routes/chat.py"
click node_chatservice "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/services/chat.py"
click node_registry "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/providers/registry.py"
click node_provider "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/providers/base.py"
click node_vision "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/vision.py"
click node_imageui "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/chat/image-gen-dialog.tsx"
click node_imageroute "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/routes/images.py"
click node_imagegen "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/services/image_gen.py"
click node_voiceui "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/voice/voice-session.tsx"
click node_voiceroutes "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/voice/routes.py"
click node_voiceagent "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/agent/voice_agent.py"
click node_app_llm "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/agent/app_llm.py"
click node_libraryui "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/library/documents.tsx"
click node_libroutes "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/routes.py"
click node_libservice "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/service.py"
click node_libdb "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/db.py"
click node_ragengine "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/engine.py"
click node_offline "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/offline.py"
click node_gemini_search "https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/gemini.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_webchat,node_chat_hook,node_webapi,node_person toneBlue
class node_apiapp,node_chatroute,node_chatservice,node_registry,node_provider toneAmber
class node_vision,node_imageui,node_imageroute,node_imagegen toneMint
class node_voiceui,node_voiceroutes,node_voiceagent,node_app_llm toneRose
class node_libraryui,node_libroutes,node_libservice,node_libdb,node_ragengine,node_offline,node_gemini_search,node_ollama,node_cloudmodels,node_imageengines,node_livekit toneIndigo
```

## Components

### Web workspace

- [Chat interface](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/chat/chat-app.tsx): `copilot-app/web/components/chat/chat-app.tsx`
- [Chat state](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/hooks/use-chat.ts): `copilot-app/web/hooks/use-chat.ts`
- [Web API client](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/lib/api.ts): `copilot-app/web/lib/api.ts`

### API and chat

- [API application](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/main.py): `copilot-app/api/app/main.py`
- [Chat route](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/routes/chat.py): `copilot-app/api/app/routes/chat.py`
- [Chat streaming](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/services/chat.py): `copilot-app/api/app/services/chat.py`
- [Provider selection](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/providers/registry.py): `copilot-app/api/app/providers/registry.py`
- [Model providers](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/providers/base.py): `copilot-app/api/app/providers/base.py`

### Media features

- [Vision capability](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/vision.py): `copilot-app/api/app/vision.py`
- [Image tools](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/chat/image-gen-dialog.tsx): `copilot-app/web/components/chat/image-gen-dialog.tsx`
- [Image routes](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/routes/images.py): `copilot-app/api/app/routes/images.py`
- [Image generation](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/services/image_gen.py): `copilot-app/api/app/services/image_gen.py`

### Voice conversations

- [Voice session UI](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/voice/voice-session.tsx): `copilot-app/web/components/voice/voice-session.tsx`
- [Voice API](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/voice/routes.py): `copilot-app/api/app/voice/routes.py`
- [LiveKit agent](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/agent/voice_agent.py): `copilot-app/agent/voice_agent.py`
- [API-backed LLM](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/agent/app_llm.py): `copilot-app/agent/app_llm.py`

### Document library

- [Library workspace](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/web/components/library/documents.tsx): `copilot-app/web/components/library/documents.tsx`
- [Library routes](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/routes.py): `copilot-app/api/app/library/routes.py`
- [Library service](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/service.py): `copilot-app/api/app/library/service.py`
- [Document records](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/db.py): `copilot-app/api/app/library/db.py`
- [RAG engine contract](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/engine.py): `copilot-app/api/app/library/engine.py`
- [Offline RAG](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/offline.py): `copilot-app/api/app/library/offline.py`
- [Gemini File Search](https://github.com/talha-ai-spec/nexusmind/blob/main/copilot-app/api/app/library/gemini.py): `copilot-app/api/app/library/gemini.py`

### Other components

- **User**
- **Ollama**
- **Cloud models**
- **Image engines**
- **LiveKit**

## Connections

- User → Chat interface: uses (evidence: `README.md`)
- Chat interface → Chat state: updates (evidence: `README.md`)
- Chat state → Web API client: requests (evidence: `README.md`)
- Web API client → Chat route: calls (evidence: `README.md`)
- API application → Chat route: mounts (evidence: `copilot-app/api/app/main.py`)
- Chat route → Chat streaming: handles chat (evidence: `copilot-app/api/app/routes/chat.py`)
- Chat streaming → Provider selection: selects models (evidence: `copilot-app/api/app/providers/registry.py`)
- Provider selection → Model providers: dispatches (evidence: `copilot-app/api/app/providers/registry.py`)
- Model providers → Ollama: serves locally (evidence: `README.md`)
- Model providers → Cloud models: falls back (evidence: `README.md`)
- Provider selection → Vision capability: checks capability (evidence: `copilot-app/api/app/providers/registry.py`)
- User → Image tools: requests images (evidence: `README.md`)
- Image tools → Image routes: submits (evidence: `README.md`)
- API application → Image routes: mounts (evidence: `copilot-app/api/app/main.py`)
- Image routes → Image generation: invokes (evidence: `copilot-app/api/app/routes/images.py`)
- Image generation → Image engines: generates with (evidence: `README.md`)
- User → Voice session UI: starts voice (evidence: `README.md`)
- Voice session UI → Voice API: creates session (evidence: `README.md`)
- API application → Voice API: mounts (evidence: `copilot-app/api/app/main.py`)
- Voice API → LiveKit: dispatches agent
- LiveKit → LiveKit agent: connects agent (evidence: `README.md`)
- LiveKit agent → API-backed LLM: uses (evidence: `copilot-app/agent/voice_agent.py`)
- API-backed LLM → Voice API: streams chat (evidence: `copilot-app/agent/app_llm.py`)
- User → Library workspace: manages documents (evidence: `README.md`)
- Library workspace → Library routes: uses library API (evidence: `README.md`)
- API application → Library routes: mounts (evidence: `copilot-app/api/app/main.py`)
- Library routes → Library service: delegates (evidence: `copilot-app/api/app/library/routes.py`)
- Library service → Document records: reads and writes (evidence: `copilot-app/api/app/library/service.py`)
- Library service → RAG engine contract: indexes and answers (evidence: `copilot-app/api/app/library/service.py`)
- RAG engine contract → Offline RAG: implemented by (evidence: `README.md`)
- RAG engine contract → Gemini File Search: implemented by (evidence: `README.md`)
