# shaerware/ai_secretary_system architecture

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

- Interactive diagram: https://gitdiagram.com/shaerware/ai_secretary_system
- Repository: https://github.com/shaerware/ai_secretary_system

## Overview

AI Secretary System is a self-hosted assistant platform with an admin UI, chat APIs, local and cloud LLM options, speech, knowledge retrieval, and messaging channels. Users configure assistants and integrations in the admin panel, then interact through chat, Telegram, WhatsApp, or an embedded widget; requests reach domain APIs and supporting services, with persistent state in SQLite and Redis. The README documents capabilities beyond the sampled source, so those branches are included with unverified links shown as dashed. Evidence comes from README statements and SOURCE INDEX references; unsampled internals are not asserted.

Main entry points: [`db/database.py`](https://github.com/shaerware/ai_secretary_system/blob/main/db/database.py) (SQLite database), [`modules/chat/service.py`](https://github.com/shaerware/ai_secretary_system/blob/main/modules/chat/service.py) (Chat orchestration), [`modules/chat/router.py`](https://github.com/shaerware/ai_secretary_system/blob/main/modules/chat/router.py) (Chat API), [`modules/knowledge/service.py`](https://github.com/shaerware/ai_secretary_system/blob/main/modules/knowledge/service.py) (Knowledge retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User Interfaces"]
  node_admin["Admin panel<br/>[App.vue]"]
  node_mobile["Mobile app<br/>[App.vue]"]
end

subgraph group_api["API Domains"]
  node_chat_api["Chat API<br/>[router.py]"]
  node_llm_api["LLM API<br/>[router.py]"]
  node_speech_api["Speech API<br/>[router_tts.py]"]
  node_knowledge_api["Knowledge API<br/>[router_wiki_rag.py]"]
  node_core_api["Auth &amp; workspace<br/>[router_auth.py]"]
  node_monitor_api["Monitoring API<br/>[router_monitor.py]"]
end

subgraph group_ai["Assistant Runtime"]
  node_chat_service["Chat orchestration<br/>[service.py]"]
  node_knowledge_service["Knowledge retrieval<br/>[service.py]"]
  node_wiki_rag["Wiki RAG"]
  node_llm_service["LLM routing<br/>[service.py]"]
  node_cloud_llm["Cloud LLM providers"]
  node_local_llm["Local LLM"]
  node_speech["Speech engines<br/>[service.py]"]
  node_bridge["CLI provider bridge<br/>[manager.py]"]
end

subgraph group_integrations["Channels &amp; Business"]
  node_telegram["Telegram channel<br/>[service.py]"]
  node_whatsapp["WhatsApp channel<br/>[service.py]"]
  node_widget["Web chat widget<br/>[service.py]"]
  node_crm["CRM &amp; sales<br/>[service.py]"]
  node_commerce["Commerce<br/>[service.py]"]
  node_telephony["GSM telephony<br/>[service.py]"]
  node_kanban["Kanban<br/>[service.py]"]
end

subgraph group_data["Shared Infrastructure"]
  node_db[("SQLite database<br/>[database.py]")]
  node_redis[("Redis<br/>[redis_client.py]")]
  node_auth["Authentication<br/>[auth_manager.py]"]
  node_monitoring["Audit &amp; usage<br/>[service.py]"]
end

node_user(("Assistant user"))
node_admin_user(("Administrator"))
node_external_llm{{"Cloud model providers"}}

node_user -.->|"sends messages"| node_chat_api
node_admin_user -->|"configures system"| node_admin
node_user -.->|"chats through"| node_mobile
node_admin -.->|"manages access"| node_core_api
node_chat_api -->|"delegates chat"| node_chat_service
node_chat_api -->|"uses retrieval"| node_knowledge_service
node_chat_api -->|"routes generation"| node_llm_service
node_knowledge_api -.->|"manages knowledge"| node_knowledge_service
node_knowledge_api -->|"searches collections"| node_wiki_rag
node_llm_api -->|"manages models"| node_llm_service
node_llm_api -->|"invokes providers"| node_cloud_llm
node_llm_api -->|"manages local model"| node_local_llm
node_speech_api -->|"requests synthesis"| node_speech
node_chat_service -->|"serves channel"| node_telegram
node_chat_service -->|"serves channel"| node_whatsapp
node_chat_service -->|"serves channel"| node_widget
node_chat_service -.->|"persists conversations"| node_db
node_knowledge_service -->|"reads and writes"| node_db
node_wiki_rag -.->|"manages documents"| node_knowledge_service
node_llm_service -->|"loads configuration"| node_db
node_cloud_llm -.->|"calls provider"| node_external_llm
node_bridge -.->|"dispatches CLI requests"| node_external_llm
node_core_api -->|"authenticates users"| node_auth
node_core_api -->|"records audit"| node_monitoring
node_monitoring -->|"stores audit records"| node_db
node_monitor_api -.->|"serves metrics"| node_monitoring
node_admin -.->|"administers chat"| node_chat_api
node_crm -.->|"stores CRM data"| node_db
node_commerce -.->|"stores commerce data"| node_db
node_telephony -.->|"uses voice services"| node_speech
node_kanban -.->|"stores tasks"| node_db

click node_admin "https://github.com/shaerware/ai_secretary_system/blob/main/admin/src/App.vue"
click node_mobile "https://github.com/shaerware/ai_secretary_system/blob/main/mobile/src/App.vue"
click node_chat_api "https://github.com/shaerware/ai_secretary_system/blob/main/modules/chat/router.py"
click node_llm_api "https://github.com/shaerware/ai_secretary_system/blob/main/modules/llm/router.py"
click node_speech_api "https://github.com/shaerware/ai_secretary_system/blob/main/modules/speech/router_tts.py"
click node_knowledge_api "https://github.com/shaerware/ai_secretary_system/blob/main/modules/knowledge/router_wiki_rag.py"
click node_core_api "https://github.com/shaerware/ai_secretary_system/blob/main/modules/core/router_auth.py"
click node_monitor_api "https://github.com/shaerware/ai_secretary_system/blob/main/modules/monitoring/router_monitor.py"
click node_chat_service "https://github.com/shaerware/ai_secretary_system/blob/main/modules/chat/service.py"
click node_knowledge_service "https://github.com/shaerware/ai_secretary_system/blob/main/modules/knowledge/service.py"
click node_wiki_rag "https://github.com/shaerware/ai_secretary_system/blob/main/app/services/wiki_rag_service.py"
click node_llm_service "https://github.com/shaerware/ai_secretary_system/blob/main/modules/llm/service.py"
click node_cloud_llm "https://github.com/shaerware/ai_secretary_system/blob/main/cloud_llm_service.py"
click node_local_llm "https://github.com/shaerware/ai_secretary_system/blob/main/vllm_llm_service.py"
click node_speech "https://github.com/shaerware/ai_secretary_system/blob/main/modules/speech/service.py"
click node_telegram "https://github.com/shaerware/ai_secretary_system/blob/main/modules/channels/telegram/service.py"
click node_whatsapp "https://github.com/shaerware/ai_secretary_system/blob/main/modules/channels/whatsapp/service.py"
click node_widget "https://github.com/shaerware/ai_secretary_system/blob/main/modules/channels/widget/service.py"
click node_crm "https://github.com/shaerware/ai_secretary_system/blob/main/modules/crm/service.py"
click node_commerce "https://github.com/shaerware/ai_secretary_system/blob/main/modules/ecommerce/service.py"
click node_telephony "https://github.com/shaerware/ai_secretary_system/blob/main/modules/telephony/service.py"
click node_kanban "https://github.com/shaerware/ai_secretary_system/blob/main/modules/kanban/service.py"
click node_db "https://github.com/shaerware/ai_secretary_system/blob/main/db/database.py"
click node_redis "https://github.com/shaerware/ai_secretary_system/blob/main/db/redis_client.py"
click node_auth "https://github.com/shaerware/ai_secretary_system/blob/main/auth_manager.py"
click node_monitoring "https://github.com/shaerware/ai_secretary_system/blob/main/modules/monitoring/service.py"
click node_bridge "https://github.com/shaerware/ai_secretary_system/blob/main/services/bridge/src/providers/manager.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_admin,node_mobile,node_user toneBlue
class node_chat_api,node_llm_api,node_speech_api,node_knowledge_api,node_core_api,node_monitor_api toneAmber
class node_chat_service,node_knowledge_service,node_wiki_rag,node_llm_service,node_cloud_llm,node_local_llm,node_speech,node_bridge toneMint
class node_telegram,node_whatsapp,node_widget,node_crm,node_commerce,node_telephony,node_kanban toneRose
class node_db,node_redis,node_auth,node_monitoring,node_admin_user,node_external_llm toneIndigo
```

## Components

### User Interfaces

- [Admin panel](https://github.com/shaerware/ai_secretary_system/blob/main/admin/src/App.vue): `admin/src/App.vue`
- [Mobile app](https://github.com/shaerware/ai_secretary_system/blob/main/mobile/src/App.vue): `mobile/src/App.vue`

### API Domains

- [Chat API](https://github.com/shaerware/ai_secretary_system/blob/main/modules/chat/router.py): `modules/chat/router.py`
- [LLM API](https://github.com/shaerware/ai_secretary_system/blob/main/modules/llm/router.py): `modules/llm/router.py`
- [Speech API](https://github.com/shaerware/ai_secretary_system/blob/main/modules/speech/router_tts.py): `modules/speech/router_tts.py`
- [Knowledge API](https://github.com/shaerware/ai_secretary_system/blob/main/modules/knowledge/router_wiki_rag.py): `modules/knowledge/router_wiki_rag.py`
- [Auth & workspace](https://github.com/shaerware/ai_secretary_system/blob/main/modules/core/router_auth.py): `modules/core/router_auth.py`
- [Monitoring API](https://github.com/shaerware/ai_secretary_system/blob/main/modules/monitoring/router_monitor.py): `modules/monitoring/router_monitor.py`

### Assistant Runtime

- [Chat orchestration](https://github.com/shaerware/ai_secretary_system/blob/main/modules/chat/service.py): `modules/chat/service.py`
- [Knowledge retrieval](https://github.com/shaerware/ai_secretary_system/blob/main/modules/knowledge/service.py): `modules/knowledge/service.py`
- [Wiki RAG](https://github.com/shaerware/ai_secretary_system/blob/main/app/services/wiki_rag_service.py): `app/services/wiki_rag_service.py`
- [LLM routing](https://github.com/shaerware/ai_secretary_system/blob/main/modules/llm/service.py): `modules/llm/service.py`
- [Cloud LLM providers](https://github.com/shaerware/ai_secretary_system/blob/main/cloud_llm_service.py): `cloud_llm_service.py`
- [Local LLM](https://github.com/shaerware/ai_secretary_system/blob/main/vllm_llm_service.py): `vllm_llm_service.py`
- [Speech engines](https://github.com/shaerware/ai_secretary_system/blob/main/modules/speech/service.py): `modules/speech/service.py`
- [CLI provider bridge](https://github.com/shaerware/ai_secretary_system/blob/main/services/bridge/src/providers/manager.py): `services/bridge/src/providers/manager.py`

### Channels & Business

- [Telegram channel](https://github.com/shaerware/ai_secretary_system/blob/main/modules/channels/telegram/service.py): `modules/channels/telegram/service.py`
- [WhatsApp channel](https://github.com/shaerware/ai_secretary_system/blob/main/modules/channels/whatsapp/service.py): `modules/channels/whatsapp/service.py`
- [Web chat widget](https://github.com/shaerware/ai_secretary_system/blob/main/modules/channels/widget/service.py): `modules/channels/widget/service.py`
- [CRM & sales](https://github.com/shaerware/ai_secretary_system/blob/main/modules/crm/service.py): `modules/crm/service.py`
- [Commerce](https://github.com/shaerware/ai_secretary_system/blob/main/modules/ecommerce/service.py): `modules/ecommerce/service.py`
- [GSM telephony](https://github.com/shaerware/ai_secretary_system/blob/main/modules/telephony/service.py): `modules/telephony/service.py`
- [Kanban](https://github.com/shaerware/ai_secretary_system/blob/main/modules/kanban/service.py): `modules/kanban/service.py`

### Shared Infrastructure

- [SQLite database](https://github.com/shaerware/ai_secretary_system/blob/main/db/database.py): `db/database.py`
- [Redis](https://github.com/shaerware/ai_secretary_system/blob/main/db/redis_client.py): `db/redis_client.py`
- [Authentication](https://github.com/shaerware/ai_secretary_system/blob/main/auth_manager.py): `auth_manager.py`
- [Audit & usage](https://github.com/shaerware/ai_secretary_system/blob/main/modules/monitoring/service.py): `modules/monitoring/service.py`

### Other components

- **Assistant user**
- **Administrator**
- **Cloud model providers**

## Connections

- Assistant user → Chat API: sends messages (evidence: `README.md`)
- Administrator → Admin panel: configures system (evidence: `README.md`)
- Assistant user → Mobile app: chats through (evidence: `README.md`)
- Admin panel → Auth & workspace: manages access (evidence: `README.md`)
- Chat API → Chat orchestration: delegates chat (evidence: `modules/chat/router.py`)
- Chat API → Knowledge retrieval: uses retrieval (evidence: `modules/chat/router.py`)
- Chat API → LLM routing: routes generation (evidence: `modules/chat/router.py`)
- Knowledge API → Knowledge retrieval: manages knowledge (evidence: `README.md`)
- Knowledge API → Wiki RAG: searches collections (evidence: `modules/knowledge/router_wiki_rag.py`)
- LLM API → LLM routing: manages models (evidence: `modules/llm/router.py`)
- LLM API → Cloud LLM providers: invokes providers (evidence: `modules/llm/router.py`)
- LLM API → Local LLM: manages local model (evidence: `modules/llm/router.py`)
- Speech API → Speech engines: requests synthesis (evidence: `modules/speech/router_tts.py`)
- Chat orchestration → Telegram channel: serves channel (evidence: `modules/chat/router.py`)
- Chat orchestration → WhatsApp channel: serves channel (evidence: `modules/chat/router.py`)
- Chat orchestration → Web chat widget: serves channel (evidence: `modules/chat/router.py`)
- Chat orchestration → SQLite database: persists conversations (evidence: `README.md`)
- Knowledge retrieval → SQLite database: reads and writes (evidence: `modules/knowledge/service.py`)
- Wiki RAG → Knowledge retrieval: manages documents (evidence: `README.md`)
- LLM routing → SQLite database: loads configuration (evidence: `modules/llm/service.py`)
- Cloud LLM providers → Cloud model providers: calls provider (evidence: `README.md`)
- CLI provider bridge → Cloud model providers: dispatches CLI requests (evidence: `README.md`)
- Auth & workspace → Authentication: authenticates users (evidence: `modules/core/router_auth.py`)
- Auth & workspace → Audit & usage: records audit (evidence: `modules/core/router_auth.py`)
- Audit & usage → SQLite database: stores audit records (evidence: `modules/monitoring/service.py`)
- Monitoring API → Audit & usage: serves metrics (evidence: `README.md`)
- Admin panel → Chat API: administers chat (evidence: `README.md`)
- CRM & sales → SQLite database: stores CRM data (evidence: `README.md`)
- Commerce → SQLite database: stores commerce data (evidence: `README.md`)
- GSM telephony → Speech engines: uses voice services (evidence: `README.md`)
- Kanban → SQLite database: stores tasks (evidence: `README.md`)
