# pierrebouvet/ai_pdf_viewer architecture

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

- Interactive diagram: https://gitdiagram.com/pierrebouvet/ai_pdf_viewer
- Repository: https://github.com/pierrebouvet/ai_pdf_viewer

## Overview

AI PDF Viewer is a local desktop application for reading and annotating PDFs, then asking questions or running reusable analysis prompts against selected document pages. The main workflow is to open a PDF, index its text, submit a prompt through the chat panel, and render the response in the chat UI. Separate branches handle PDF navigation and annotations, prompt-library and provider configuration, themes, and local-model timing estimates. The README also documents optional structured extraction; its implementation is not confirmed by the sampled source.

Main entry points: [`ui/main_window.py`](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/main_window.py) (Main Window), [`backend/ai_assistant.py`](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/ai_assistant.py) (AI Assistant), [`ui/ai_chat_panel.py`](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/ai_chat_panel.py) (AI Chat Panel), [`main.py`](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/main.py) (Application Startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop UI"]
  node_main["Application Startup<br/>[main.py]"]
  node_window["Main Window<br/>[main_window.py]"]
  node_chat["AI Chat Panel<br/>[ai_chat_panel.py]"]
  node_editor["Response Editor"]
end

subgraph group_documents["PDF Workflow"]
  node_pdfview["PDF Viewer<br/>[pdf_view.py]"]
  node_thumbnails["Page Thumbnails<br/>[thumbnail_panel.py]"]
  node_annotations["Annotation Toolbar"]
  node_pdfdoc["PDF Document<br/>[pdf_document.py]"]
end

subgraph group_intelligence["AI Services"]
  node_assistant["AI Assistant<br/>[ai_assistant.py]"]
  node_benchmark["Response Estimator<br/>[model_benchmark.py]"]
  node_gemini{{"Google Gemini"}}
  node_ollama{{"Local Ollama"}}
  node_extractor["Structured Extractor<br/>[pdf_document.py]"]
end

subgraph group_preferences["Settings and Prompts"]
  node_configdialog["AI Configuration<br/>[config_dialog.py]"]
  node_config[("App Configuration<br/>[config_manager.py]")]
  node_promptsdialog["Prompt Manager UI<br/>[prompts_dialog.py]"]
  node_prompts[("Prompt Library<br/>[prompts_manager.py]")]
end

subgraph group_shared["Shared UI Support"]
  node_theme["Theme Manager<br/>[theme_manager.py]"]
  node_markdown["Markdown Renderer"]
  node_assets["Offline Asset Loader<br/>[asset_loader.py]"]
  node_logger["Application Logger<br/>[logger.py]"]
end

node_reader(("Researcher"))

node_reader -->|"starts"| node_main
node_main -->|"launches"| node_window
node_main -->|"initializes"| node_config
node_main -->|"configures"| node_theme
node_main -->|"initializes"| node_assistant
node_window -->|"hosts"| node_pdfview
node_window -->|"hosts"| node_chat
node_window -->|"hosts"| node_thumbnails
node_window -->|"opens"| node_configdialog
node_window -->|"opens"| node_promptsdialog
node_window -->|"manages"| node_pdfdoc
node_window -->|"requests answers"| node_assistant
node_window -->|"loads prompts"| node_prompts
node_window -->|"applies theme"| node_theme
node_pdfview -->|"renders and edits"| node_pdfdoc
node_pdfview -->|"uses tools"| node_annotations
node_thumbnails -->|"reads pages"| node_pdfdoc
node_chat -->|"submits prompts"| node_assistant
node_chat -->|"renders responses"| node_markdown
node_chat -->|"styles interface"| node_theme
node_chat -->|"opens editor"| node_editor
node_chat -.->|"estimates duration"| node_benchmark
node_assistant -->|"reads settings"| node_config
node_assistant -->|"records throughput"| node_benchmark
node_assistant -.->|"requests inference"| node_gemini
node_assistant -.->|"requests inference"| node_ollama
node_configdialog -->|"updates settings"| node_config
node_configdialog -->|"configures provider"| node_assistant
node_promptsdialog -->|"edits library"| node_prompts
node_theme -->|"loads icons"| node_assets
node_pdfdoc -.->|"optionally extracts"| node_extractor

click node_main "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/main.py"
click node_window "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/main_window.py"
click node_chat "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/ai_chat_panel.py"
click node_editor "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/edit_message_dialog.py"
click node_pdfview "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/pdf_view.py"
click node_thumbnails "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/thumbnail_panel.py"
click node_annotations "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/annotation_toolbar.py"
click node_pdfdoc "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/pdf_document.py"
click node_assistant "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/ai_assistant.py"
click node_benchmark "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/model_benchmark.py"
click node_extractor "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/pdf_document.py"
click node_configdialog "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/config_dialog.py"
click node_config "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/config_manager.py"
click node_promptsdialog "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/prompts_dialog.py"
click node_prompts "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/prompts_manager.py"
click node_theme "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/theme_manager.py"
click node_markdown "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/markdown_renderer.py"
click node_assets "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/asset_loader.py"
click node_logger "https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/logger.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_main,node_window,node_chat,node_editor toneBlue
class node_pdfview,node_thumbnails,node_annotations,node_pdfdoc toneAmber
class node_assistant,node_benchmark,node_gemini,node_ollama,node_extractor toneMint
class node_configdialog,node_config,node_promptsdialog,node_prompts toneRose
class node_theme,node_markdown,node_assets,node_logger,node_reader toneIndigo
```

## Components

### Desktop UI

- [Application Startup](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/main.py): `main.py`
- [Main Window](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/main_window.py): `ui/main_window.py`
- [AI Chat Panel](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/ai_chat_panel.py): `ui/ai_chat_panel.py`
- [Response Editor](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/edit_message_dialog.py): `ui/edit_message_dialog.py`

### PDF Workflow

- [PDF Viewer](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/pdf_view.py): `ui/pdf_view.py`
- [Page Thumbnails](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/thumbnail_panel.py): `ui/thumbnail_panel.py`
- [Annotation Toolbar](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/annotation_toolbar.py): `ui/annotation_toolbar.py`
- [PDF Document](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/pdf_document.py): `backend/pdf_document.py`

### AI Services

- [AI Assistant](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/ai_assistant.py): `backend/ai_assistant.py`
- [Response Estimator](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/model_benchmark.py): `backend/model_benchmark.py`
- **Google Gemini**
- **Local Ollama**
- [Structured Extractor](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/pdf_document.py): `backend/pdf_document.py`

### Settings and Prompts

- [AI Configuration](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/config_dialog.py): `ui/config_dialog.py`
- [App Configuration](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/config_manager.py): `backend/config_manager.py`
- [Prompt Manager UI](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/prompts_dialog.py): `ui/prompts_dialog.py`
- [Prompt Library](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/prompts_manager.py): `backend/prompts_manager.py`

### Shared UI Support

- [Theme Manager](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/theme_manager.py): `ui/theme_manager.py`
- [Markdown Renderer](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/markdown_renderer.py): `backend/markdown_renderer.py`
- [Offline Asset Loader](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/ui/asset_loader.py): `ui/asset_loader.py`
- [Application Logger](https://github.com/pierrebouvet/ai_pdf_viewer/blob/main/backend/logger.py): `backend/logger.py`

### Other components

- **Researcher**

## Connections

- Researcher → Application Startup: starts (evidence: `README.md`)
- Application Startup → Main Window: launches (evidence: `main.py`)
- Application Startup → App Configuration: initializes (evidence: `main.py`)
- Application Startup → Theme Manager: configures (evidence: `main.py`)
- Application Startup → AI Assistant: initializes (evidence: `main.py`)
- Main Window → PDF Viewer: hosts (evidence: `ui/main_window.py`)
- Main Window → AI Chat Panel: hosts (evidence: `ui/main_window.py`)
- Main Window → Page Thumbnails: hosts (evidence: `ui/main_window.py`)
- Main Window → AI Configuration: opens (evidence: `ui/main_window.py`)
- Main Window → Prompt Manager UI: opens (evidence: `ui/main_window.py`)
- Main Window → PDF Document: manages (evidence: `ui/main_window.py`)
- Main Window → AI Assistant: requests answers (evidence: `ui/main_window.py`)
- Main Window → Prompt Library: loads prompts (evidence: `ui/main_window.py`)
- Main Window → Theme Manager: applies theme (evidence: `ui/main_window.py`)
- PDF Viewer → PDF Document: renders and edits (evidence: `ui/pdf_view.py`)
- PDF Viewer → Annotation Toolbar: uses tools (evidence: `ui/pdf_view.py`)
- Page Thumbnails → PDF Document: reads pages (evidence: `ui/thumbnail_panel.py`)
- AI Chat Panel → AI Assistant: submits prompts (evidence: `ui/ai_chat_panel.py`)
- AI Chat Panel → Markdown Renderer: renders responses (evidence: `ui/ai_chat_panel.py`)
- AI Chat Panel → Theme Manager: styles interface (evidence: `ui/ai_chat_panel.py`)
- AI Chat Panel → Response Editor: opens editor (evidence: `ui/ai_chat_panel.py`)
- AI Chat Panel → Response Estimator: estimates duration
- AI Assistant → App Configuration: reads settings (evidence: `backend/ai_assistant.py`)
- AI Assistant → Response Estimator: records throughput (evidence: `backend/ai_assistant.py`)
- AI Assistant → Google Gemini: requests inference (evidence: `README.md`)
- AI Assistant → Local Ollama: requests inference (evidence: `README.md`)
- AI Configuration → App Configuration: updates settings (evidence: `ui/config_dialog.py`)
- AI Configuration → AI Assistant: configures provider (evidence: `ui/config_dialog.py`)
- Prompt Manager UI → Prompt Library: edits library (evidence: `ui/prompts_dialog.py`)
- Theme Manager → Offline Asset Loader: loads icons (evidence: `ui/theme_manager.py`)
- PDF Document → Structured Extractor: optionally extracts (evidence: `README.md`)
