# pewdiepie-archdaemon/odysseus architecture

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

- Interactive diagram: https://gitdiagram.com/pewdiepie-archdaemon/odysseus
- Repository: https://github.com/pewdiepie-archdaemon/odysseus

## Overview

1. **Overall shape**
   - Odysseus is a self-hosted AI workspace built around a Python backend and a browser UI. The backend exposes feature-specific HTTP routes, runs agent/model orchestration, and persists user/session state; the frontend is a large static JavaScript app that renders the workspace and streams live updates.

2. **Bootstrap and deployment boundary**
   - `app.py`, `launcher.py`, and `src/app_initializer.py` are the main startup path. Docker is a first-class deployment target (`Dockerfile`, `docker-compose*.yml`, entrypoint scripts), with additional Windows/macOS launch/build scripts and a packaged app spec (`Odysseus.spec`).

3. **Frontend surface**
   - `static/` is not a small asset folder; it contains the UI application itself. It is organized into feature modules for chat, documents, email, calendar, compare, gallery, notes, tasks, settings, search, model picking, and rich editor tooling. The UI talks to backend routes, renders streaming agent responses, and manages local session/UI state.

4. **Request routing layer**
   - `routes/` is the HTTP API and page-delivery layer. Each domain has its own route module, which keeps the feature boundaries visible: auth, sessions, chat, documents, email, calendar, notes, tasks, search, presets, preferences, uploads, model/provider selection, backups, diagnostics, admin actions, webhook handling, and MCP/skills integration.

5. **Core application infrastructure**
   - `core/` and many `src/` modules hold the cross-cutting plumbing: database access, session management, auth, middleware, platform compatibility, logging safety, atomic file IO, constants, exceptions, and shared models. This is the layer that enforces multi-user boundaries, persistence rules, and safe filesystem/network behavior.

6. **Agent and chat runtime**
   - The central AI flow lives in `src/agent_loop.py`, `src/chat_handler.py`, `src/chat_processor.py`, `src/llm_core.py`, and related modules. A chat request is turned into model calls, tool calls, and streamed output; the result is recorded back into session/chat history. This is the main orchestration path for interactive assistant behavior.

7. **Tooling and execution model**
   - Tool handling is a major subsystem: `src/tool_*`, `src/tool_execution.py`, `src/tool_policy.py`, `src/tool_security.py`, and `src/tool_schemas.py` define how tools are discovered, parsed, validated, and executed. `src/agent_tools/` and `src/tools/` contain the concrete tool implementations for files, web, search, system actions, documents, notes, calendar, contacts, vault, research, and model interaction. Strong confinement and prompt-injection defenses are part of the architecture, not an afterthought.

8. **Domain services**
   - `services/` contains the heavier business logic for major features:
     - `services/search/` for provider querying, caching, ranking, content extraction, and analytics.
     - `services/research/` for multi-step web research and synthesis.
     - `services/memory/` and RAG modules for memory extraction, vectorization, and recall.
     - `services/docs/` for document processing/rendering.
     - `services/shell/`, `services/stt/`, `services/tts/`, `services/hwfit/`, and `services/youtube/` for local automation, voice, hardware-aware model fit, and media ingestion.
   - These services are called from routes, tools, or the agent runtime rather than directly from the UI.

9. **Data pipelines**
   - The repo’s main data flows are: browser action → route → service/orchestrator → persistence/external system → streamed response back to the UI. Common sinks/sources are the application database, the filesystem for uploads/docs/gallery/backups, and vector/search stores for memory and RAG. Several modules and scripts indicate support for migrations and backfills across these stores.

10. **External integrations**
   - The system integrates with multiple outside domains: LLM providers and local model endpoints, web search providers, IMAP/SMTP email, CalDAV/CardDAV, MCP servers, and companion tooling for Claude/Codex. `config/searxng/` shows SearxNG is a supported search backend, and `integrations/` plus `mcp_servers/` are explicit adapter boundaries.

11. **Background work and orchestration**
   - Scheduled and asynchronous work is handled separately from request/response traffic via `src/bg_jobs.py`, `src/task_scheduler.py`, `src/bg_monitor.py`, and related task/session helpers. This is where reminders, polling, sync, and long-running jobs are kept from blocking the interactive UI.

12. **Security and tenancy**
   - Security is structural: auth, API tokens, device flow, 2FA, owner scoping, path confinement, SSRF hardening, URL safety, secret handling, and security headers are spread across the app stack. The large test suite is heavily focused on regression prevention for these boundaries, which suggests tenant isolation and safe tool execution are core architectural requirements.

13. **Ops, packaging, and ecosystem**
   - GitHub Actions, container scanning, dependency review, and secret scanning support the delivery pipeline. The repo also includes CLI entrypoints in `scripts/`, service installers, backup/restore docs, and integration-specific shims, showing that Odysseus is designed to be operated as a self-contained local platform rather than a single-purpose app.

14. **What to draw in an architecture diagram**
   - The diagram should center on the Python backend as the orchestration hub, with the browser UI on one side and external services/model providers on the other. Around the hub, show separate domains for chat/agents, documents/uploads, search/research, memory/RAG, email/calendar/contacts sync, model/provider management, and background jobs, all tied together by shared auth/session/database infrastructure and a strict tool/security layer.

Main entry points: [`routes`](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/routes) (Routes), [`services`](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/services) (Services), [`static/js`](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/static/js) (UI modules), [`Dockerfile`](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/Dockerfile) (Deployment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_bootstrap["Bootstrap"]
  node_app_py["App entry<br/>bootstrap<br/>[app.py]"]
  node_launcher_py["Launcher<br/>bootstrap<br/>[launcher.py]"]
  node_app_initializer["Init<br/>bootstrap<br/>[app_initializer.py]"]
end

subgraph group_group_backend["Backend"]
  node_routes_layer["Routes"]
  node_core_infra["Core infra<br/>platform core"]
  node_agent_runtime["Agent loop<br/>orchestration<br/>[agent_loop.py]"]
  node_chat_pipeline["Chat pipeline<br/>chat runtime<br/>[chat_handler.py]"]
  node_tooling_layer["Tools<br/>tooling<br/>[tool_execution.py]"]
  node_bg_jobs["Background jobs<br/>async jobs<br/>[bg_jobs.py]"]
  node_model_llm["Model stack<br/>llm/provider<br/>[llm_core.py]"]
  node_memory_rag["Memory/RAG<br/>retrieval<br/>[rag_manager.py]"]
  node_search_research["Search/Research<br/>external query<br/>[service.py]"]
  node_document_uploads["Docs/Uploads<br/>content handling"]
  node_sync_automation["Sync/Automation<br/>domain sync<br/>[caldav_sync.py]"]
end

subgraph group_group_ui["Frontend"]
  node_static_ui["Static UI<br/>browser app<br/>[app.js]"]
  node_workspace_modules["UI modules<br/>feature modules"]
end

subgraph group_group_services["Domain services"]
  node_services_domain["Services"]
end

subgraph group_group_integrations["Integrations"]
  node_integrations_boundary["Adapters<br/>integration boundary"]
  node_mcp_servers["MCP servers<br/>integration servers"]
end

subgraph group_group_ops["Ops"]
  node_deployment_ops["Deployment<br/>ops packaging"]
end

node_app_py -->|"starts"| node_app_initializer
node_launcher_py -->|"launches"| node_app_py
node_app_initializer -->|"registers"| node_routes_layer
node_app_initializer -->|"configures"| node_core_infra
node_routes_layer -->|"dispatches chat"| node_chat_pipeline
node_routes_layer -->|"dispatches docs"| node_document_uploads
node_routes_layer -->|"dispatches search"| node_search_research
node_routes_layer -->|"dispatches sync"| node_sync_automation
node_routes_layer -->|"dispatches models"| node_model_llm
node_routes_layer -->|"queues jobs"| node_bg_jobs
node_chat_pipeline -->|"uses"| node_agent_runtime
node_agent_runtime -->|"invokes tools"| node_tooling_layer
node_agent_runtime -->|"calls models"| node_model_llm
node_tooling_layer -->|"executes via"| node_services_domain
node_memory_rag -->|"uses"| node_services_domain
node_search_research -->|"uses"| node_services_domain
node_document_uploads -->|"uses"| node_services_domain
node_sync_automation -->|"uses"| node_services_domain
node_static_ui -->|"calls API"| node_routes_layer
node_workspace_modules -->|"implements"| node_static_ui
node_workspace_modules -->|"streams chat"| node_chat_pipeline
node_workspace_modules -->|"manages docs"| node_document_uploads
node_workspace_modules -->|"drives search"| node_search_research
node_integrations_boundary -->|"hosts"| node_mcp_servers
node_routes_layer -->|"exposes adapters"| node_integrations_boundary
node_deployment_ops -->|"packages"| node_app_py
node_deployment_ops -->|"ships"| node_static_ui
node_deployment_ops -->|"bundles"| node_integrations_boundary
node_bg_jobs -->|"persists state"| node_core_infra
node_core_infra -->|"supports"| node_model_llm

click node_app_py "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/app.py"
click node_launcher_py "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/launcher.py"
click node_app_initializer "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/app_initializer.py"
click node_routes_layer "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/routes"
click node_core_infra "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/core"
click node_agent_runtime "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/agent_loop.py"
click node_chat_pipeline "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/chat_handler.py"
click node_tooling_layer "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/tool_execution.py"
click node_bg_jobs "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/bg_jobs.py"
click node_model_llm "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/llm_core.py"
click node_memory_rag "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/rag_manager.py"
click node_search_research "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/services/search/service.py"
click node_document_uploads "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/document_processor.py"
click node_sync_automation "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/caldav_sync.py"
click node_static_ui "https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/static/app.js"
click node_workspace_modules "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/static/js"
click node_services_domain "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/services"
click node_integrations_boundary "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/integrations"
click node_mcp_servers "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/mcp_servers"
click node_deployment_ops "https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/Dockerfile"

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_app_py,node_launcher_py,node_app_initializer toneBlue
class node_routes_layer,node_core_infra,node_agent_runtime,node_chat_pipeline,node_tooling_layer,node_bg_jobs,node_model_llm,node_memory_rag,node_search_research,node_document_uploads,node_sync_automation toneAmber
class node_static_ui,node_workspace_modules toneMint
class node_services_domain toneRose
class node_integrations_boundary,node_mcp_servers toneIndigo
class node_deployment_ops toneTeal
```

## Components

### Bootstrap

Startup, launcher, and packaging boundary.

- [App entry](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/app.py): bootstrap · Primary Python entrypoint for server startup. · `app.py`
- [Launcher](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/launcher.py): bootstrap · Alternate launch path and environment setup. · `launcher.py`
- [Init](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/app_initializer.py): bootstrap · Application initialization and wiring. · `src/app_initializer.py`

### Backend

Python application core, request routing, orchestration, and shared infrastructure.

- [Routes](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/routes): http routes · Feature-specific HTTP/page delivery modules for auth, sessions, chat, documents, email, calendar, search, presets, uploads, models, and admin flows. · `routes`
- [Core infra](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/core): platform core · Database, auth, middleware, session manager, models, constants, exceptions, and safe filesystem/logging helpers. · `core`
- [Agent loop](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/agent_loop.py): orchestration · Chat request orchestration, model calls, tool calls, streaming, and response recording. · `src/agent_loop.py`
- [Chat pipeline](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/chat_handler.py): chat runtime · Chat handling and processing stages that prepare, execute, and stream assistant responses. · `src/chat_handler.py`
- [Tools](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/tool_execution.py): tooling · Tool discovery, parsing, policy, security, schemas, execution, and concrete agent tools. · `src/tool_execution.py`
- [Background jobs](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/bg_jobs.py): async jobs · Schedulers, monitors, and long-running asynchronous work outside request traffic. · `src/bg_jobs.py`
- [Model stack](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/llm_core.py): llm/provider · LLM core, discovery, endpoint resolution, provider management, and model selection plumbing. · `src/llm_core.py`
- [Memory/RAG](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/rag_manager.py): retrieval · Memory extraction, vectorization, recall, and RAG management. · `src/rag_manager.py`
- [Search/Research](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/services/search/service.py): external query · Search providers, ranking, caching, web extraction, and multi-step research synthesis. · `services/search/service.py`
- [Docs/Uploads](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/document_processor.py): content handling · Document processing, upload handling, office/PDF runtimes, and personal document flows. · `src/document_processor.py`
- [Sync/Automation](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/src/caldav_sync.py): domain sync · Email, calendar, contacts, shell, voice, webhooks, and related sync/automation surfaces. · `src/caldav_sync.py`

### Frontend

Browser application and static client-side feature modules.

- [Static UI](https://github.com/pewdiepie-archdaemon/odysseus/blob/dev/static/app.js): browser app · The browser-side workspace application and feature modules rendered from static assets. · `static/app.js`
- [UI modules](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/static/js): feature modules · Client modules for chat, documents, email, calendar, compare, gallery, notes, tasks, settings, search, models, and editor tooling. · `static/js`

### Domain services

Heavier feature logic and external-domain adapters.

- [Services](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/services): domain services · Search, research, memory, docs, shell, STT/TTS, HW fit, and media ingestion services. · `services`

### Integrations

Companion apps, MCP servers, and external tool shims.

- [Adapters](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/integrations): integration boundary · Companion app, Claude/Codex skills, and MCP server adapter layer. · `integrations`
- [MCP servers](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/mcp_servers): integration servers · Standalone MCP servers for email, image generation, memory, and RAG. · `mcp_servers`

### Ops

Packaging, deployment, automation, and delivery support.

- [Deployment](https://github.com/pewdiepie-archdaemon/odysseus/tree/dev/Dockerfile): ops packaging · Docker, compose files, service install scripts, build scripts, and packaged app spec. · `Dockerfile`

## Connections

- App entry → Init: starts · App bootstraps the application initializer.
- Launcher → App entry: launches · Launcher hands off to the main app entrypoint.
- Init → Routes: registers · Initial setup wires HTTP and page routes.
- Init → Core infra: configures · Initializer configures core auth, DB, session, and middleware plumbing.
- Routes → Chat pipeline: dispatches chat · Chat routes enter the chat handling pipeline.
- Routes → Docs/Uploads: dispatches docs · Document and upload routes hand off to document services.
- Routes → Search/Research: dispatches search · Search and research routes invoke query/research services.
- Routes → Sync/Automation: dispatches sync · Email, calendar, contacts, shell, and webhook routes reach sync/automation code.
- Routes → Model stack: dispatches models · Model/provider routes manage endpoint and model selection.
- Routes → Background jobs: queues jobs · Some routes schedule background or deferred work.
- Chat pipeline → Agent loop: uses · Chat processing drives the agent loop.
- Agent loop → Tools: invokes tools · Agent execution can call tools and sub-actions.
- Agent loop → Model stack: calls models · Agent loop streams requests to model backends.
- Tools → Services: executes via · Tools delegate heavy work to domain services when needed.
- Memory/RAG → Services: uses · Memory and RAG rely on service implementations for extraction and vectors.
- Search/Research → Services: uses · Search and research orchestration depend on service modules.
- Docs/Uploads → Services: uses · Document and upload handling relies on processing services.
- Sync/Automation → Services: uses · Automation and sync features call into service layers.
- Static UI → Routes: calls API · Browser UI interacts with feature routes.
- UI modules → Static UI: implements · Feature modules compose the main workspace UI.
- UI modules → Chat pipeline: streams chat · Client chat modules render live assistant updates.
- UI modules → Docs/Uploads: manages docs · Document and editor modules interact with upload and processing flows.
- UI modules → Search/Research: drives search · Search/research UI modules trigger backend query flows.
- Adapters → MCP servers: hosts · Adapter layer connects to bundled MCP servers and companion integrations.
- Routes → Adapters: exposes adapters · Routes surface MCP, skills, Claude, and Codex integration boundaries.
- Deployment → App entry: packages · Deployment artifacts build and run the Python app.
- Deployment → Static UI: ships · Packaging includes the browser UI assets.
- Deployment → Adapters: bundles · Operational packaging includes companion and adapter tooling.
- Background jobs → Core infra: persists state · Background work relies on shared persistence and session infrastructure.
- Core infra → Model stack: supports · Shared configuration and safety boundaries support model access and provider selection.
