How learningcircuit/local-deep-research works
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: search_system.py Search system · web Web app · news News subsystem · web_search_engines Search engines
Components 19
Runtime Surfaces
User-facing and external entrypoints for research, API, CLI, and assistant integrations.
- Web app · Main browser runtime serving templates, static assets, auth, REST, and realtime progress.
src/local_deep_research/web - Programmatic API · Direct Python API surface for research and benchmark operations.
src/local_deep_research/api - Benchmarks · Benchmark datasets, runners, evaluators, optimization, and web routes.
src/local_deep_research/benchmarks - MCP server · 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 · Central research orchestrator that selects strategies and coordinates end-to-end runs.
src/local_deep_research/search_system.py - Search factory · Builds configured search system instances for different runtimes and modes.
src/local_deep_research/search_system_factory.py - Strategies · Pluggable research strategies for decomposition, parallelism, constraints, and synthesis.
src/local_deep_research/advanced_search_system/strategies - Search engines · Outbound search adapters spanning academic, web, local-doc, and meta/parallel engines.
src/local_deep_research/web_search_engines - Content fetcher · Fetches URLs and supports content retrieval, classification, and cleanup.
src/local_deep_research/content_fetcher - Citations · 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 · Database/file-backed storage abstraction used across the app.
src/local_deep_research/storage - Encrypted DB · 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 · Document ingestion, downloaders, extraction, search, and RAG over private collections.
src/local_deep_research/research_library - News subsystem · 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 · Async/background work for queued research, indexing, and repeated collection tasks.
src/local_deep_research/scheduler - Security · Cross-cutting validation, rate limiting, SSRF protection, sanitization, and headers.
src/local_deep_research/security - LLM providers · Central provider registry for hosted and local LLM backends.
src/local_deep_research/llm - Embeddings · Embedding provider registry and text splitter support.
src/local_deep_research/embeddings - Metrics · Token, search, pricing, and cost tracking for analytics and dashboards.
src/local_deep_research/metrics
Connections 29
- 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.