# learningcircuit/local-deep-research architecture

> Architecture diagram of the GitHub repository learningcircuit/local-deep-research, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/learningcircuit/local-deep-research
- Repository: https://github.com/learningcircuit/local-deep-research

## Overview

1. **Overall shape**
   - This is a Python-first monorepo with a browser UI, authenticated server, CLI/API entrypoints, and several domain subsystems around research, library management, news subscriptions, and benchmarking.
   - The core architectural style is service-oriented inside a single process: thin routes/controllers call domain services, which coordinate search engines, LLM providers, storage, and background workers.

2. **Primary runtime surfaces**
   - The main user-facing runtime is the `web` package (`src/local_deep_research/web`), which serves HTML templates, static JS/CSS, REST routes, WebSockets, and auth.
   - There is also a programmatic API package (`src/local_deep_research/api`), a benchmark CLI/API (`src/local_deep_research/benchmarks`), and an MCP server (`src/local_deep_research/mcp`) for external AI assistants.
   - The project ships as both a Docker image and a pip-installable package.

3. **Research orchestration path**
   - User research requests enter through web/API routes and are handled by research services and a central `search_system` / `search_system_factory`.
   - A research strategy is selected from many implementations in `advanced_search_system/strategies`; these strategies determine how queries are decomposed, which engines to call, when to stop, and how to synthesize results.
   - Outputs are assembled into reports with citations via report/citation handlers, then persisted to the database and exposed back through the UI.

4. **Search engine layer**
   - Search is abstracted behind `web_search_engines`, which contains many adapters: academic, general web, news, technical, local-doc, and meta/parallel search engines.
   - The search layer is intentionally pluggable: a registry/factory chooses engines based on configuration, and rate-limiting wrappers protect external services.
   - This is the main outbound network boundary for the app, along with LLM provider calls.

5. **LLM and embedding providers**
   - LLM access is centralized in `llm/` with provider implementations for OpenAI, Anthropic, Google, Ollama, OpenRouter, LM Studio, llama.cpp, and custom OpenAI-compatible endpoints.
   - Embeddings live separately in `embeddings/` with Ollama, OpenAI, and sentence-transformers implementations.
   - These provider abstractions are shared by research, news summarization, retrieval, and some benchmarking/optimization workflows.

6. **Content fetch, extraction, and citation**
   - After search, URLs are processed by `content_fetcher` and by the research library download/extraction pipeline for HTML/PDF/document sources.
   - Text cleaning, URL classification, domain classification, and citation normalization live in utility and processing modules.
   - Citation generation is a distinct layer (`citation_handler`, `citation_handlers`, `text_optimization`) so reports can be rendered consistently across markdown, PDF, LaTeX, RIS, and other export formats.

7. **Encrypted persistence and per-user state**
   - Data persistence is built around SQLCipher-encrypted databases with a clear separation between auth, research history, cache, settings, metrics, queue state, and domain-specific tables.
   - There is explicit migration support (`database/migrations`), backup handling, thread/session management, and a storage abstraction that can target database or file-backed storage.
   - The README’s “per-user encrypted databases” is reflected in the architecture: user/session boundaries are first-class, not incidental.

8. **Library and knowledge-base subsystem**
   - `research_library` is a separate bounded context for ingesting documents, storing PDFs, deleting collections/documents, and building RAG/search over a private knowledge base.
   - Downloaders are specialized per source type: arXiv, bioRxiv, PubMed, OpenAlex, Semantic Scholar, direct PDF, generic HTML, and Playwright-based HTML.
   - The RAG path goes through library services, embedding/indexing support, and search routes so private documents can be queried alongside live web sources.

9. **News and subscription subsystem**
   - `news/` models a distinct workflow: topic/query subscriptions, scheduled searches, card generation, relevance/rating, preferences, and storage.
   - A scheduler/background layer triggers repeated collection and summarization, while notifications and digest rendering deliver updates.
   - This subsystem shares search engines, LLMs, and storage, but it has its own domain models and lifecycle separate from one-off research runs.

10. **Background processing and queues**
    - Long-running work is isolated through queue management, background scheduling, and WebSocket/SSE progress reporting.
    - The web package has queue managers and processors for research execution, and services like socket service and progress endpoints push live status back to the browser.
    - This keeps the request/response boundary thin while research, downloads, exports, and indexing continue asynchronously.

11. **Security boundary**
    - Security is a cross-cutting subsystem, not a single module: CSRF, auth/session cleanup, rate limiting, SSRF protection, URL/path/file validators, log sanitization, and security headers are all explicit.
    - The repo also hardens supply-chain and code quality through extensive GitHub Actions, pre-commit hooks, and scanners like CodeQL, Semgrep, Gitleaks, ZAP, and dependency/container checks.
    - For an architecture diagram, security should sit around the web/API edges and outbound network calls, not inside a single service box.

12. **Frontend composition**
    - The browser UI is server-rendered templates plus a significant amount of modular JavaScript under `web/static/js`.
    - Frontend modules are organized by feature area: research, history, library, news, settings, metrics, deletion, auth, and security.
    - The frontend consumes API/SSE/WebSocket endpoints and is not just presentation; it also orchestrates form validation, progress updates, and client-side feature interactions.

13. **Analytics, metrics, and benchmarking**
    - `metrics/` tracks token usage, search activity, pricing, and cost calculations, feeding the analytics dashboard.
    - `benchmarks/` is a separate subsystem for datasets, evaluators, graders, optimization, reporting, and web routes for running comparisons.
    - This is useful to show as a parallel observability/performance lane: it measures the research system rather than driving user-facing research directly.

14. **External dependencies and deployment**
    - Important external services include configured search engines, LLM APIs, optional notification providers (Apprise), and local/self-hosted components like Ollama, SearXNG, Elasticsearch, or a vector store retriever.
    - Docker Compose, a Dockerfile, Unraid templates, and CI workflows indicate the repo is designed to run locally or self-hosted, with several optional integrations enabled by configuration.
    - The architecture is therefore modular and capability-driven: users can run fully local, hybrid, or cloud-backed setups without changing the core app structure.

Main entry points: [`src/local_deep_research/search_system.py`](https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/search_system.py) (Search system), [`src/local_deep_research/web`](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/web) (Web app), [`src/local_deep_research/news`](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/news) (News subsystem), [`src/local_deep_research/web_search_engines`](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/web_search_engines) (Search engines)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime Surfaces"]
  node_web["Web app<br/>server UI"]
  node_api["Programmatic API<br/>library API"]
  node_benchmarks["Benchmarks<br/>cli + api"]
  node_mcp["MCP server<br/>assistant bridge"]
end

subgraph group_research["Research Core"]
  node_search_system{{"Search system<br/>orchestrator<br/>[search_system.py]"}}
  node_search_system_factory["Search factory"]
  node_strategies["Strategies"]
  node_engines["Search engines<br/>adapters"]
  node_fetcher["Content fetcher<br/>extraction"]
  node_citation["Citations<br/>citation layer"]
end

subgraph group_data["Data & State"]
  node_storage["Storage layer<br/>persistence abstraction"]
  node_database[("Encrypted DB<br/>sqlcipher persistence")]
end

subgraph group_content["Library & News"]
  node_library["Research library<br/>private KB"]
  node_news["News subsystem<br/>subscriptions"]
end

subgraph group_platform["Platform Services"]
  node_scheduler["Background jobs<br/>scheduler"]
  node_security{{"Security<br/>hardening"}}
  node_llm["LLM providers<br/>model adapters"]
  node_embeddings["Embeddings<br/>vector adapters"]
  node_metrics["Metrics<br/>usage analytics"]
end

node_web -->|"start research"| node_search_system
node_web -->|"library UI"| node_library
node_web -->|"news UI"| node_news
node_web -->|"persist state"| node_storage
node_web -->|"protect endpoints"| node_security
node_api -->|"programmatic runs"| node_search_system
node_benchmarks -->|"evaluate runs"| node_search_system
node_mcp -->|"assistant access"| node_search_system
node_search_system -->|"builds from factory"| node_search_system_factory
node_search_system -->|"select strategy"| node_strategies
node_search_system -->|"query engines"| node_engines
node_search_system -->|"fetch sources"| node_fetcher
node_search_system -->|"format citations"| node_citation
node_search_system -->|"synthesize"| node_llm
node_search_system -->|"embed content"| node_embeddings
node_search_system -->|"track usage"| node_metrics
node_engines -->|"safe outbound"| node_security
node_engines -->|"meta search"| node_llm
node_library -->|"store docs"| node_database
node_library -->|"library search"| node_engines
node_library -->|"index docs"| node_embeddings
node_news -->|"collect news"| node_engines
node_news -->|"summarize cards"| node_llm
node_news -->|"store subscriptions"| node_database
node_scheduler -->|"queue progress"| node_web
node_scheduler -->|"scheduled digests"| node_news
node_storage -->|"db backend"| node_database
node_storage -->|"file guardrails"| node_security
node_database -->|"session/auth hardening"| node_security

click node_web "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/web"
click node_api "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/api"
click node_benchmarks "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/benchmarks"
click node_mcp "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/mcp"
click node_search_system "https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/search_system.py"
click node_search_system_factory "https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/search_system_factory.py"
click node_strategies "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/advanced_search_system/strategies"
click node_engines "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/web_search_engines"
click node_fetcher "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/content_fetcher"
click node_citation "https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/citation_handler.py"
click node_storage "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/storage"
click node_database "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/database"
click node_library "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/research_library"
click node_news "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/news"
click node_scheduler "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/scheduler"
click node_security "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/security"
click node_llm "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/llm"
click node_embeddings "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/embeddings"
click node_metrics "https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/metrics"

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_benchmarks,node_mcp toneBlue
class node_search_system,node_search_system_factory,node_strategies,node_engines,node_fetcher,node_citation toneAmber
class node_storage,node_database toneMint
class node_library,node_news toneRose
class node_scheduler,node_security,node_llm,node_embeddings,node_metrics toneIndigo
```

## Components

### Runtime Surfaces

User-facing and external entrypoints for research, API, CLI, and assistant integrations.

- [Web app](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/web): server UI · Main browser runtime serving templates, static assets, auth, REST, and realtime progress. · `src/local_deep_research/web`
- [Programmatic API](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/api): library API · Direct Python API surface for research and benchmark operations. · `src/local_deep_research/api`
- [Benchmarks](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/benchmarks): cli + api · Benchmark datasets, runners, evaluators, optimization, and web routes. · `src/local_deep_research/benchmarks`
- [MCP server](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/mcp): assistant bridge · Model Context Protocol server and client for external AI tools. · `src/local_deep_research/mcp`

### Research Core

Orchestration, strategy selection, search, fetching, citations, and report assembly.

- [Search system](https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/search_system.py): orchestrator · Central research orchestrator that selects strategies and coordinates end-to-end runs. · `src/local_deep_research/search_system.py`
- [Search factory](https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/search_system_factory.py): factory · Builds configured search system instances for different runtimes and modes. · `src/local_deep_research/search_system_factory.py`
- [Strategies](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/advanced_search_system/strategies): search strategies · Pluggable research strategies for decomposition, parallelism, constraints, and synthesis. · `src/local_deep_research/advanced_search_system/strategies`
- [Search engines](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/web_search_engines): adapters · Outbound search adapters spanning academic, web, local-doc, and meta/parallel engines. · `src/local_deep_research/web_search_engines`
- [Content fetcher](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/content_fetcher): extraction · Fetches URLs and supports content retrieval, classification, and cleanup. · `src/local_deep_research/content_fetcher`
- [Citations](https://github.com/learningcircuit/local-deep-research/blob/main/src/local_deep_research/citation_handler.py): citation layer · Normalizes and formats citations for report generation and export formats. · `src/local_deep_research/citation_handler.py`

### Data & State

Encrypted persistence, storage abstractions, migrations, and per-user state.

- [Storage layer](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/storage): persistence abstraction · Database/file-backed storage abstraction used across the app. · `src/local_deep_research/storage`
- [Encrypted DB](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/database): sqlcipher persistence · Encrypted database models, sessions, migrations, backups, and queue/auth state. · `src/local_deep_research/database`

### Library & News

Bounded contexts for private library RAG and subscription-based news workflows.

- [Research library](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/research_library): private KB · Document ingestion, downloaders, extraction, search, and RAG over private collections. · `src/local_deep_research/research_library`
- [News subsystem](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/news): subscriptions · Topic subscriptions, card generation, relevance scoring, and scheduled digests. · `src/local_deep_research/news`

### Platform Services

Shared LLM/embedding providers, metrics, security, and background processing.

- [Background jobs](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/scheduler): scheduler · Async/background work for queued research, indexing, and repeated collection tasks. · `src/local_deep_research/scheduler`
- [Security](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/security): hardening · Cross-cutting validation, rate limiting, SSRF protection, sanitization, and headers. · `src/local_deep_research/security`
- [LLM providers](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/llm): model adapters · Central provider registry for hosted and local LLM backends. · `src/local_deep_research/llm`
- [Embeddings](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/embeddings): vector adapters · Embedding provider registry and text splitter support. · `src/local_deep_research/embeddings`
- [Metrics](https://github.com/learningcircuit/local-deep-research/tree/main/src/local_deep_research/metrics): usage analytics · Token, search, pricing, and cost tracking for analytics and dashboards. · `src/local_deep_research/metrics`

## Connections

- Web app → Search system: start research · Browser actions initiate research runs through the orchestrator.
- Web app → Research library: library UI · Web UI exposes private collection and RAG workflows.
- Web app → News subsystem: news UI · Web UI renders subscriptions, digests, and news workflows.
- Web app → Storage layer: persist state · Web services read and write application state through storage.
- Web app → Security: protect endpoints · Auth, CSRF, rate limiting, and request validation guard the web edge.
- Programmatic API → Search system: programmatic runs · Python API exposes the same core research orchestration.
- Benchmarks → Search system: evaluate runs · Benchmark harness executes the search system for comparison and grading.
- MCP server → Search system: assistant access · MCP tools invoke research workflows for external AI assistants.
- Search system → Search factory: builds from factory · The orchestrator is assembled from configured factories and settings.
- Search system → Strategies: select strategy · Research execution branches into strategy implementations.
- Search system → Search engines: query engines · Strategies call outbound search adapters to gather evidence.
- Search system → Content fetcher: fetch sources · Search results are retrieved and cleaned before synthesis.
- Search system → Citations: format citations · Final reports are normalized with citation handlers.
- Search system → LLM providers: synthesize · LLMs are used for query planning, summarization, and synthesis.
- Search system → Embeddings: embed content · Embedding providers support retrieval and private knowledge workflows.
- Search system → Metrics: track usage · Token and search metrics are recorded during research runs.
- Search engines → Security: safe outbound · Search adapters are constrained by SSRF, rate limits, and URL validation.
- Search engines → LLM providers: meta search · Some search/relevance paths consult LLMs for ranking or filtering.
- Research library → Encrypted DB: store docs · Library collections, documents, and indexes persist in encrypted tables.
- Research library → Search engines: library search · Private library search can be combined with live search engines.
- Research library → Embeddings: index docs · RAG workflows depend on embeddings and splitters for indexing.
- News subsystem → Search engines: collect news · Subscriptions trigger repeated searches against configured engines.
- News subsystem → LLM providers: summarize cards · News analysis and card generation use LLM providers.
- News subsystem → Encrypted DB: store subscriptions · Subscriptions, ratings, preferences, and history are persisted.
- Background jobs → Web app: queue progress · Background processors feed live status back to the browser.
- Background jobs → News subsystem: scheduled digests · Background jobs run recurring news collection and notification cycles.
- Storage layer → Encrypted DB: db backend · Primary persistence is SQLCipher-encrypted database storage.
- Storage layer → Security: file guardrails · Storage actions are checked for path and write safety.
- Encrypted DB → Security: session/auth hardening · Encrypted persistence is coupled with session, auth, and integrity controls.
