# raveendra47/thetos-reader architecture

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

- Interactive diagram: https://gitdiagram.com/raveendra47/thetos-reader
- Repository: https://github.com/raveendra47/thetos-reader

## Overview

#### Purpose and Runtime
Thetos Reader is a privacy-first Windows PDF reader. Its UI runs as a React 18/TypeScript Vite application; Tauri 2 packages and hosts it as a native desktop application with a Rust backend. PDF rendering, search, annotation, and dictionary processing are local.

Entry points:
- Web/UI bootstrap: `src/main.tsx`
- Application composition: `src/App.tsx`
- Tauri executable/library: `src-tauri/src/main.rs`, `src-tauri/src/lib.rs`

#### Application Shell and Navigation
`src/App.tsx` coordinates the desktop reader shell: document tabs, viewer workspace, panels/dialogs, and application-level interactions. `src/pages/Index.tsx` is the primary route-level screen, while `src/pages/NotFound.tsx` handles unmatched routes. The top-level UI is composed from reader-specific controls such as `src/components/TabBar.tsx`, `src/components/ViewerToolbar.tsx`, and `src/components/TitleBar.tsx`.

#### Document Intake and Session Lifecycle
Documents enter through drag/drop and file-oriented UI, then become managed tabs and persisted session state.
- Intake: `src/components/DropZone.tsx`, `src/lib/fileStore.ts`
- Tab lifecycle: `src/hooks/useTabManager.ts`, `src/components/TabBar.tsx`
- Restore/persistence boundary: `src/lib/sessionStore.ts`, `src/lib/pdfDocCache.ts`

This boundary separates document metadata and reader state from active PDF.js document/rendering objects.

#### PDF Viewing and Rendering Pipeline
`src/viewers/PdfViewer.tsx` is the central document-viewing integration point. It consumes PDF state and coordinates page presentation, navigation, zoom/rotation/layout settings, status, and page interactions.
- Viewer: `src/viewers/PdfViewer.tsx`
- PDF state/cache: `src/lib/usePdfStore.ts`, `src/lib/pdfDocCache.ts`
- Rendering hooks/workers: `src/hooks/usePdfRenderer.ts`, `src/workers/renderWorker.ts`, `src/workers/prerender.worker.ts`

Rendering is explicitly offloaded to workers where possible, keeping page rasterization/prerender work outside the interactive React UI thread.

#### Search, Navigation, and PDF Services
Full-text search is a separate asynchronous pipeline with UI feedback and live matches.
- Search UI: `src/components/PdfSearchBar.tsx`
- Search orchestration/worker: `src/hooks/useSearchWorker.ts`, `src/workers/searchWorker.ts`
- PDF navigation services: `src/lib/pdfLinkService.ts`, `src/components/DocumentTocSidebar.tsx`

PDF links and table-of-contents navigation form a viewer-to-document-service boundary rather than being embedded solely in rendering components.

#### Reader State: Annotations, Bookmarks, and Settings
Persistent local reader data is organized into focused stores and surfaced through panels/popovers.
- Annotation history/storage: `src/hooks/useAnnotationHistory.ts`, `src/lib/annotationStore.ts`
- Bookmark UI: `src/components/BookmarkPanel.tsx`
- Preferences and protected documents: `src/lib/appSettings.ts`, `src/lib/passwordStore.ts`, `src/components/PdfSettingsPanel.tsx`

Selection actions originate in `src/components/TextSelectionPopover.tsx`; annotation/bookmark state is retained independently of transient viewer rendering.

#### Dictionary and Native Packaging
Dictionary lookup is local and supports MDX dictionary resources through a dedicated parser subsystem.
- Dictionary UX/core/store: `src/components/DictionaryPopover.tsx`, `src/lib/dictionaryCore.ts`, `src/lib/dictionaryStore.ts`
- MDX parsing: `src/lib/mdict/index.ts`
- Bundled resources: `src-tauri/resources/dictionaries/EnglishDictionary.mdx`, `src-tauri/resources/dictionaries/Merriam-Webster.mdx`

Tauri capability and packaging boundaries are defined in `src-tauri/tauri.conf.json` and `src-tauri/capabilities/default.json`; no remote backend or external service is indicated.

Main entry points: [`src/viewers/PdfViewer.tsx`](https://github.com/raveendra47/thetos-reader/blob/main/src/viewers/PdfViewer.tsx) (PDF viewer), [`src/App.tsx`](https://github.com/raveendra47/thetos-reader/blob/main/src/App.tsx) (Application shell), [`src/hooks/useTabManager.ts`](https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/useTabManager.ts) (Tab lifecycle), [`src/hooks/useSearchWorker.ts`](https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/useSearchWorker.ts) (Search pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["React UI"]
  node_bootstrap["UI bootstrap<br/>Vite entry<br/>[main.tsx]"]
  node_app["Application shell<br/>React composition<br/>[App.tsx]"]
  node_routes["Reader routes<br/>route screens<br/>[Index.tsx]"]
  node_reader_controls["Reader controls<br/>UI controls<br/>[TabBar.tsx]"]
  node_search_ui["Search bar<br/>search UI<br/>[PdfSearchBar.tsx]"]
end

subgraph group_document["Document Lifecycle"]
  node_intake["Document intake<br/>drop/file UI<br/>[DropZone.tsx]"]
  node_tab_manager["Tab lifecycle<br/>React hook<br/>[useTabManager.ts]"]
  node_session_store[("Session store<br/>local persistence<br/>[sessionStore.ts]")]
  node_pdf_cache["PDF document cache<br/>active document cache<br/>[pdfDocCache.ts]"]
  node_pdf_store["PDF state store<br/>viewer state<br/>[usePdfStore.ts]"]
  node_pdf_viewer["PDF viewer<br/>viewer integration<br/>[PdfViewer.tsx]"]
  node_pdf_navigation["PDF navigation<br/>link and TOC service<br/>[pdfLinkService.ts]"]
end

subgraph group_workers["Background Processing"]
  node_render_pipeline["Render pipeline<br/>render hooks and workers<br/>[usePdfRenderer.ts]"]
  node_search_pipeline["Search pipeline<br/>search hook and worker<br/>[useSearchWorker.ts]"]
end

subgraph group_reader_data["Reader Data"]
  node_annotation_data[("Annotations and bookmarks<br/>local reader data<br/>[annotationStore.ts]")]
  node_preferences[("Preferences and passwords<br/>local settings<br/>[appSettings.ts]")]
  node_dictionary["Dictionary subsystem<br/>local dictionary<br/>[dictionaryCore.ts]"]
  node_mdx_parser["MDX parser<br/>dictionary parser<br/>[index.ts]"]
end

subgraph group_native["Native Packaging"]
  node_dictionary_resources["Bundled dictionaries<br/>MDX resources"]
  node_tauri_host{{"Tauri host<br/>Rust desktop host<br/>[main.rs]"}}
  node_tauri_policy["Tauri packaging policy<br/>capabilities and packaging<br/>[tauri.conf.json]"]
end

node_bootstrap -->|"mounts"| node_app
node_app -->|"renders"| node_routes
node_app -->|"composes"| node_reader_controls
node_app -->|"accepts documents"| node_intake
node_intake -->|"opens"| node_tab_manager
node_tab_manager -->|"persists session"| node_session_store
node_tab_manager -->|"manages active documents"| node_pdf_cache
node_app -->|"hosts"| node_pdf_viewer
node_pdf_viewer -->|"reads viewer state"| node_pdf_store
node_pdf_store -->|"uses documents"| node_pdf_cache
node_pdf_viewer -->|"requests rendering"| node_render_pipeline
node_pdf_viewer -->|"navigates links and TOC"| node_pdf_navigation
node_search_ui -->|"submits queries"| node_search_pipeline
node_search_pipeline -->|"searches active document"| node_pdf_cache
node_search_pipeline -->|"returns matches"| node_pdf_viewer
node_pdf_viewer -->|"reads and updates"| node_annotation_data
node_app -->|"loads settings"| node_preferences
node_pdf_viewer -->|"looks up selections"| node_dictionary
node_dictionary -->|"parses MDX"| node_mdx_parser
node_mdx_parser -->|"reads"| node_dictionary_resources
node_tauri_host -->|"hosts web UI"| node_bootstrap
node_tauri_policy -->|"configures"| node_tauri_host

click node_bootstrap "https://github.com/raveendra47/thetos-reader/blob/main/src/main.tsx"
click node_app "https://github.com/raveendra47/thetos-reader/blob/main/src/App.tsx"
click node_routes "https://github.com/raveendra47/thetos-reader/blob/main/src/pages/Index.tsx"
click node_reader_controls "https://github.com/raveendra47/thetos-reader/blob/main/src/components/TabBar.tsx"
click node_intake "https://github.com/raveendra47/thetos-reader/blob/main/src/components/DropZone.tsx"
click node_tab_manager "https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/useTabManager.ts"
click node_session_store "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/sessionStore.ts"
click node_pdf_cache "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/pdfDocCache.ts"
click node_pdf_store "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/usePdfStore.ts"
click node_pdf_viewer "https://github.com/raveendra47/thetos-reader/blob/main/src/viewers/PdfViewer.tsx"
click node_pdf_navigation "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/pdfLinkService.ts"
click node_render_pipeline "https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/usePdfRenderer.ts"
click node_search_pipeline "https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/useSearchWorker.ts"
click node_search_ui "https://github.com/raveendra47/thetos-reader/blob/main/src/components/PdfSearchBar.tsx"
click node_annotation_data "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/annotationStore.ts"
click node_preferences "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/appSettings.ts"
click node_dictionary "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/dictionaryCore.ts"
click node_mdx_parser "https://github.com/raveendra47/thetos-reader/blob/main/src/lib/mdict/index.ts"
click node_dictionary_resources "https://github.com/raveendra47/thetos-reader/blob/main/src-tauri/resources/dictionaries/EnglishDictionary.mdx"
click node_tauri_host "https://github.com/raveendra47/thetos-reader/blob/main/src-tauri/src/main.rs"
click node_tauri_policy "https://github.com/raveendra47/thetos-reader/blob/main/src-tauri/tauri.conf.json"

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_bootstrap,node_app,node_routes,node_reader_controls,node_search_ui toneBlue
class node_intake,node_tab_manager,node_session_store,node_pdf_cache,node_pdf_store,node_pdf_viewer,node_pdf_navigation toneAmber
class node_render_pipeline,node_search_pipeline toneMint
class node_annotation_data,node_preferences,node_dictionary,node_mdx_parser toneRose
class node_dictionary_resources,node_tauri_host,node_tauri_policy toneIndigo
```

## Components

### React UI

Desktop reader interface and route shell.

- [UI bootstrap](https://github.com/raveendra47/thetos-reader/blob/main/src/main.tsx): Vite entry · `src/main.tsx`
- [Application shell](https://github.com/raveendra47/thetos-reader/blob/main/src/App.tsx): React composition · Coordinates tabs, workspace, panels, and dialogs. · `src/App.tsx`
- [Reader routes](https://github.com/raveendra47/thetos-reader/blob/main/src/pages/Index.tsx): route screens · Primary reader screen and unmatched-route fallback. · `src/pages/Index.tsx`
- [Reader controls](https://github.com/raveendra47/thetos-reader/blob/main/src/components/TabBar.tsx): UI controls · Title bar, toolbar, and tab bar. · `src/components/TabBar.tsx`
- [Search bar](https://github.com/raveendra47/thetos-reader/blob/main/src/components/PdfSearchBar.tsx): search UI · `src/components/PdfSearchBar.tsx`

### Document Lifecycle

Local document session, PDF state, and viewer services.

- [Document intake](https://github.com/raveendra47/thetos-reader/blob/main/src/components/DropZone.tsx): drop/file UI · Drag-and-drop document entry. · `src/components/DropZone.tsx`
- [Tab lifecycle](https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/useTabManager.ts): React hook · Manages open document tabs. · `src/hooks/useTabManager.ts`
- [Session store](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/sessionStore.ts): local persistence · Persists document metadata and reader session state. · `src/lib/sessionStore.ts`
- [PDF document cache](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/pdfDocCache.ts): active document cache · Separates live PDF objects from persisted session data. · `src/lib/pdfDocCache.ts`
- [PDF state store](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/usePdfStore.ts): viewer state · `src/lib/usePdfStore.ts`
- [PDF viewer](https://github.com/raveendra47/thetos-reader/blob/main/src/viewers/PdfViewer.tsx): viewer integration · Coordinates pages, layout, navigation, and interactions. · `src/viewers/PdfViewer.tsx`
- [PDF navigation](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/pdfLinkService.ts): link and TOC service · Links and document outline navigation. · `src/lib/pdfLinkService.ts`

### Background Processing

PDF work kept off the interactive UI thread.

- [Render pipeline](https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/usePdfRenderer.ts): render hooks and workers · Rasterization and prerendering run outside the UI thread. · `src/hooks/usePdfRenderer.ts`
- [Search pipeline](https://github.com/raveendra47/thetos-reader/blob/main/src/hooks/useSearchWorker.ts): search hook and worker · Asynchronous full-text search with live matches. · `src/hooks/useSearchWorker.ts`

### Reader Data

Persistent local reader state and dictionary data.

- [Annotations and bookmarks](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/annotationStore.ts): local reader data · Selection-driven annotations, history, and bookmarks. · `src/lib/annotationStore.ts`
- [Preferences and passwords](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/appSettings.ts): local settings · Reader settings and protected-document data. · `src/lib/appSettings.ts`
- [Dictionary subsystem](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/dictionaryCore.ts): local dictionary · Lookup core and persisted dictionary selection/state. · `src/lib/dictionaryCore.ts`
- [MDX parser](https://github.com/raveendra47/thetos-reader/blob/main/src/lib/mdict/index.ts): dictionary parser · `src/lib/mdict/index.ts`

### Native Packaging

Tauri host, capabilities, and bundled resources.

- [Bundled dictionaries](https://github.com/raveendra47/thetos-reader/blob/main/src-tauri/resources/dictionaries/EnglishDictionary.mdx): MDX resources · Local English and Merriam-Webster dictionary files. · `src-tauri/resources/dictionaries/EnglishDictionary.mdx`
- [Tauri host](https://github.com/raveendra47/thetos-reader/blob/main/src-tauri/src/main.rs): Rust desktop host · Packages and hosts the React reader with a Rust backend. · `src-tauri/src/main.rs`
- [Tauri packaging policy](https://github.com/raveendra47/thetos-reader/blob/main/src-tauri/tauri.conf.json): capabilities and packaging · `src-tauri/tauri.conf.json`

## Connections

- UI bootstrap → Application shell: mounts
- Application shell → Reader routes: renders
- Application shell → Reader controls: composes
- Application shell → Document intake: accepts documents
- Document intake → Tab lifecycle: opens
- Tab lifecycle → Session store: persists session
- Tab lifecycle → PDF document cache: manages active documents
- Application shell → PDF viewer: hosts
- PDF viewer → PDF state store: reads viewer state
- PDF state store → PDF document cache: uses documents
- PDF viewer → Render pipeline: requests rendering
- PDF viewer → PDF navigation: navigates links and TOC
- Search bar → Search pipeline: submits queries
- Search pipeline → PDF document cache: searches active document
- Search pipeline → PDF viewer: returns matches
- PDF viewer → Annotations and bookmarks: reads and updates
- Application shell → Preferences and passwords: loads settings
- PDF viewer → Dictionary subsystem: looks up selections
- Dictionary subsystem → MDX parser: parses MDX
- MDX parser → Bundled dictionaries: reads
- Tauri host → UI bootstrap: hosts web UI
- Tauri packaging policy → Tauri host: configures
