# phani-stack/sovereignai architecture

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

- Interactive diagram: https://gitdiagram.com/phani-stack/sovereignai
- Repository: https://github.com/phani-stack/sovereignai

## Overview

SOVAI is a self-hosted AI workbench for private document, knowledge, chat, coding, calculation, and vision tasks. Its principal workflow runs from the browser through FastAPI into chat and agent orchestration, which routes work to local models, retrieval, and tools before returning results. Separate branches handle document upload/indexing, vision, authentication, and sandbox access. README capabilities include verification, reports, and security/audit views; where implementation links were not shown, those links are omitted or marked unverified.

Main entry points: [`backend/main.py`](https://github.com/phani-stack/sovereignai/blob/main/backend/main.py) (FastAPI Application), [`backend/core/agent/nodes.py`](https://github.com/phani-stack/sovereignai/blob/main/backend/core/agent/nodes.py) (Plan and Execute), [`backend/core/rag/retrive.py`](https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/retrive.py) (Knowledge Retrieval), [`backend/core/tools/registry.py`](https://github.com/phani-stack/sovereignai/blob/main/backend/core/tools/registry.py) (Python Tool Registry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Workspace and API"]
  node_web["Browser Workspace<br/>[app.js]"]
  node_api["FastAPI Application<br/>[main.py]"]
  node_chat_route["Chat Routes<br/>[chat.py]"]
  node_document_route["Document Routes<br/>[document.py]"]
  node_vision_route["Vision Routes<br/>[vision.py]"]
  node_sandbox_route["Sandbox Routes<br/>[sandbox.py]"]
  node_auth_route["Auth Routes<br/>[auth.py]"]
end

subgraph group_services["Product Services"]
  node_chat_service["Chat Service<br/>[chat_service.py]"]
  node_document_service["Document Service"]
  node_vision_service["Vision Service<br/>[vision_service.py]"]
  node_auth_service[("Access and Sessions<br/>[auth_service.py]")]
end

subgraph group_agent["Agent and Tools"]
  node_agent_graph["Agent Graph<br/>[graph.py]"]
  node_agent_nodes["Plan and Execute<br/>[nodes.py]"]
  node_tool_registry["Python Tool Registry<br/>[registry.py]"]
  node_doc_tools["Document Tools<br/>[document_tools.py]"]
end

subgraph group_local["Local AI and Knowledge"]
  node_model_manager["Local Model Router<br/>[model_manager.py]"]
  node_rag_embedding["Document Embeddings<br/>[embedding.py]"]
  node_loader_router["Document Loaders<br/>[loader_router.py]"]
  node_retrieval["Knowledge Retrieval<br/>[retrive.py]"]
  node_vectordb["RAG Indexing<br/>[vectordb.py]"]
  node_qdrant_search["Qdrant Search<br/>[search.py]"]
  node_qdrant[("Qdrant Store<br/>[client.py]")]
end

node_user(("Workbench User"))
node_ollama(("Local Ollama"))
node_sandbox_runtime["Isolated Runtime"]

node_user -->|"uses"| node_web
node_web -->|"sends requests"| node_api
node_api -->|"registers"| node_chat_route
node_api -->|"registers"| node_document_route
node_api -->|"registers"| node_vision_route
node_api -->|"registers"| node_sandbox_route
node_api -->|"registers"| node_auth_route
node_chat_route -->|"calls"| node_chat_service
node_document_route -->|"calls"| node_document_service
node_vision_route -->|"calls"| node_vision_service
node_auth_route -->|"authenticates"| node_auth_service
node_chat_service -->|"invokes"| node_agent_graph
node_agent_graph -->|"dispatches"| node_agent_nodes
node_agent_nodes -->|"selects model"| node_model_manager
node_agent_nodes -->|"retrieves context"| node_retrieval
node_agent_nodes -->|"gets tools"| node_tool_registry
node_tool_registry -->|"registers"| node_doc_tools
node_model_manager -->|"runs inference"| node_ollama
node_retrieval -->|"embeds query"| node_rag_embedding
node_retrieval -->|"searches"| node_qdrant_search
node_document_service -->|"indexes upload"| node_vectordb
node_vectordb -->|"embeds documents"| node_rag_embedding
node_rag_embedding -->|"loads documents"| node_loader_router
node_qdrant_search -->|"queries"| node_qdrant
node_sandbox_route -.->|"executes code"| node_sandbox_runtime
node_agent_nodes -.->|"may execute code"| node_sandbox_runtime
node_agent_nodes -->|"generates reports"| node_tool_registry

click node_web "https://github.com/phani-stack/sovereignai/blob/main/frontend/app.js"
click node_api "https://github.com/phani-stack/sovereignai/blob/main/backend/main.py"
click node_chat_route "https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/chat.py"
click node_document_route "https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/document.py"
click node_vision_route "https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/vision.py"
click node_sandbox_route "https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/sandbox.py"
click node_auth_route "https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/auth.py"
click node_chat_service "https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/chat_service.py"
click node_document_service "https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/document_service.py"
click node_vision_service "https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/vision_service.py"
click node_auth_service "https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/auth_service.py"
click node_agent_graph "https://github.com/phani-stack/sovereignai/blob/main/backend/core/agent/graph.py"
click node_agent_nodes "https://github.com/phani-stack/sovereignai/blob/main/backend/core/agent/nodes.py"
click node_tool_registry "https://github.com/phani-stack/sovereignai/blob/main/backend/core/tools/registry.py"
click node_doc_tools "https://github.com/phani-stack/sovereignai/blob/main/backend/core/tools/document_tools.py"
click node_model_manager "https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/models/model_manager.py"
click node_rag_embedding "https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/embedding.py"
click node_loader_router "https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/loaders/loader_router.py"
click node_retrieval "https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/retrive.py"
click node_vectordb "https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/vectordb.py"
click node_qdrant_search "https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/qdrant/search.py"
click node_qdrant "https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/qdrant/client.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_web,node_api,node_chat_route,node_document_route,node_vision_route,node_sandbox_route,node_auth_route,node_user toneBlue
class node_chat_service,node_document_service,node_vision_service,node_auth_service toneAmber
class node_agent_graph,node_agent_nodes,node_tool_registry,node_doc_tools toneMint
class node_model_manager,node_rag_embedding,node_loader_router,node_retrieval,node_vectordb,node_qdrant_search,node_qdrant toneRose
class node_ollama,node_sandbox_runtime toneIndigo
```

## Components

### Workspace and API

- [Browser Workspace](https://github.com/phani-stack/sovereignai/blob/main/frontend/app.js): `frontend/app.js`
- [FastAPI Application](https://github.com/phani-stack/sovereignai/blob/main/backend/main.py): `backend/main.py`
- [Chat Routes](https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/chat.py): `backend/api/routes/chat.py`
- [Document Routes](https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/document.py): `backend/api/routes/document.py`
- [Vision Routes](https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/vision.py): `backend/api/routes/vision.py`
- [Sandbox Routes](https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/sandbox.py): `backend/api/routes/sandbox.py`
- [Auth Routes](https://github.com/phani-stack/sovereignai/blob/main/backend/api/routes/auth.py): `backend/api/routes/auth.py`

### Product Services

- [Chat Service](https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/chat_service.py): `backend/core/services/chat_service.py`
- [Document Service](https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/document_service.py): `backend/core/services/document_service.py`
- [Vision Service](https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/vision_service.py): `backend/core/services/vision_service.py`
- [Access and Sessions](https://github.com/phani-stack/sovereignai/blob/main/backend/core/services/auth_service.py): `backend/core/services/auth_service.py`

### Agent and Tools

- [Agent Graph](https://github.com/phani-stack/sovereignai/blob/main/backend/core/agent/graph.py): `backend/core/agent/graph.py`
- [Plan and Execute](https://github.com/phani-stack/sovereignai/blob/main/backend/core/agent/nodes.py): `backend/core/agent/nodes.py`
- [Python Tool Registry](https://github.com/phani-stack/sovereignai/blob/main/backend/core/tools/registry.py): `backend/core/tools/registry.py`
- [Document Tools](https://github.com/phani-stack/sovereignai/blob/main/backend/core/tools/document_tools.py): `backend/core/tools/document_tools.py`

### Local AI and Knowledge

- [Local Model Router](https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/models/model_manager.py): `backend/infrastructure/models/model_manager.py`
- [Document Embeddings](https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/embedding.py): `backend/core/rag/embedding.py`
- [Document Loaders](https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/loaders/loader_router.py): `backend/infrastructure/loaders/loader_router.py`
- [Knowledge Retrieval](https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/retrive.py): `backend/core/rag/retrive.py`
- [RAG Indexing](https://github.com/phani-stack/sovereignai/blob/main/backend/core/rag/vectordb.py): `backend/core/rag/vectordb.py`
- [Qdrant Search](https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/qdrant/search.py): `backend/infrastructure/qdrant/search.py`
- [Qdrant Store](https://github.com/phani-stack/sovereignai/blob/main/backend/infrastructure/qdrant/client.py): `backend/infrastructure/qdrant/client.py`

### Other components

- **Workbench User**
- **Local Ollama**
- **Isolated Runtime**

## Connections

- Workbench User → Browser Workspace: uses
- Browser Workspace → FastAPI Application: sends requests
- FastAPI Application → Chat Routes: registers (evidence: `backend/main.py`)
- FastAPI Application → Document Routes: registers (evidence: `backend/main.py`)
- FastAPI Application → Vision Routes: registers (evidence: `backend/main.py`)
- FastAPI Application → Sandbox Routes: registers (evidence: `backend/main.py`)
- FastAPI Application → Auth Routes: registers (evidence: `backend/main.py`)
- Chat Routes → Chat Service: calls (evidence: `backend/api/routes/chat.py`)
- Document Routes → Document Service: calls (evidence: `backend/api/routes/document.py`)
- Vision Routes → Vision Service: calls (evidence: `backend/api/routes/vision.py`)
- Auth Routes → Access and Sessions: authenticates (evidence: `backend/api/routes/auth.py`)
- Chat Service → Agent Graph: invokes (evidence: `backend/core/services/chat_service.py`)
- Agent Graph → Plan and Execute: dispatches (evidence: `backend/core/agent/graph.py`)
- Plan and Execute → Local Model Router: selects model (evidence: `backend/core/agent/nodes.py`)
- Plan and Execute → Knowledge Retrieval: retrieves context (evidence: `backend/core/agent/nodes.py`)
- Plan and Execute → Python Tool Registry: gets tools (evidence: `backend/core/agent/nodes.py`)
- Python Tool Registry → Document Tools: registers (evidence: `backend/core/tools/registry.py`)
- Local Model Router → Local Ollama: runs inference
- Knowledge Retrieval → Document Embeddings: embeds query (evidence: `backend/core/rag/retrive.py`)
- Knowledge Retrieval → Qdrant Search: searches (evidence: `backend/core/rag/retrive.py`)
- Document Service → RAG Indexing: indexes upload (evidence: `backend/core/services/document_service.py`)
- RAG Indexing → Document Embeddings: embeds documents (evidence: `backend/core/rag/vectordb.py`)
- Document Embeddings → Document Loaders: loads documents (evidence: `backend/core/rag/embedding.py`)
- Qdrant Search → Qdrant Store: queries (evidence: `backend/infrastructure/qdrant/search.py`)
- Sandbox Routes → Isolated Runtime: executes code
- Plan and Execute → Isolated Runtime: may execute code
- Plan and Execute → Python Tool Registry: generates reports (evidence: `backend/core/agent/nodes.py`)
