# duyu09/npa-paper-analyzer-and-translator architecture

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

- Interactive diagram: https://gitdiagram.com/duyu09/npa-paper-analyzer-and-translator
- Repository: https://github.com/duyu09/npa-paper-analyzer-and-translator

## Overview

NPA is a local desktop paper analyzer and translator. Users import Markdown directly or send a PDF through MinerU, review the document in the GUI, translate it in streamed chunks with a shared terminology table, then save Markdown or print to PDF. The graph separates the documented UI capabilities from backend responsibilities. Main orchestration and service calls are visible in excerpts; frontend details and some documented features are represented only at the README level.

Main entry points: [`main.py`](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py) (PDF import), [`static/index.html`](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/static/index.html) (Preview interface), [`key_manager.py`](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/key_manager.py) (API key management), [`flask_server.py`](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/flask_server.py) (Local content server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop interface"]
  node_gui["Desktop GUI<br/>[main.py]"]
  node_frontend["Preview interface<br/>[index.html]"]
  node_webview["Webview bridge<br/>[main.py]"]
  node_local_server["Local content server<br/>[flask_server.py]"]
end

subgraph group_documents["Document handling"]
  node_pdf_import["PDF import<br/>[main.py]"]
  node_markdown_import["Markdown import<br/>[main.py]"]
  node_pdf_parser["PDF parsing client<br/>[analysis_pdf.py]"]
  node_mineru{{"MinerU service"}}
  node_temp_files["Temporary documents<br/>[tempdir_manager.py]"]
  node_document_images["Document images<br/>[flask_server.py]"]
  node_markdown_export["Markdown export<br/>[main.py]"]
  node_pdf_export["PDF printing<br/>[index.html]"]
end

subgraph group_translation["Translation"]
  node_translation_flow["Translation orchestration<br/>[main.py]"]
  node_text_chunks["Text chunking<br/>[split_text.py]"]
  node_stream_parser["Stream parsing<br/>[main.py]"]
  node_translation_service["Translation client<br/>[call_api.py]"]
  node_zhipu{{"Zhipu AI"}}
end

subgraph group_settings["Configuration and state"]
  node_key_manager["API key management<br/>[key_manager.py]"]
  node_key_config[("Persistent API keys")]
end

node_user(("Researcher"))

node_user -->|"uses"| node_frontend
node_frontend -->|"invokes"| node_webview
node_webview -->|"dispatches"| node_gui
node_gui -->|"serves through"| node_local_server
node_gui -->|"handles import"| node_pdf_import
node_pdf_import -->|"calls"| node_pdf_parser
node_pdf_import -->|"creates workspace"| node_temp_files
node_pdf_parser -->|"uploads and queries"| node_mineru
node_pdf_import -->|"handles Markdown"| node_markdown_import
node_pdf_import -->|"sets document directory"| node_local_server
node_local_server -->|"serves images"| node_document_images
node_gui -->|"saves translation"| node_markdown_export
node_frontend -->|"prints document"| node_pdf_export
node_frontend -->|"starts translation"| node_translation_flow
node_translation_flow -->|"splits text"| node_text_chunks
node_translation_flow -->|"requests stream"| node_translation_service
node_translation_service -->|"streams completion"| node_zhipu
node_translation_flow -->|"extracts translation"| node_stream_parser
node_stream_parser -->|"updates live"| node_frontend
node_translation_flow -->|"stores API key"| node_key_manager
node_pdf_import -->|"stores MinerU key"| node_key_manager
node_gui -->|"reads and writes keys"| node_key_manager
node_key_manager -->|"persists"| node_key_config

click node_gui "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_frontend "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/static/index.html"
click node_webview "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_local_server "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/flask_server.py"
click node_pdf_import "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_markdown_import "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_pdf_parser "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/analysis_pdf.py"
click node_temp_files "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/tempdir_manager.py"
click node_document_images "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/flask_server.py"
click node_markdown_export "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_pdf_export "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/static/index.html"
click node_translation_flow "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_text_chunks "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/split_text.py"
click node_stream_parser "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py"
click node_translation_service "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/call_api.py"
click node_key_manager "https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/key_manager.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_gui,node_frontend,node_webview,node_local_server toneBlue
class node_pdf_import,node_markdown_import,node_pdf_parser,node_mineru,node_temp_files,node_document_images,node_markdown_export,node_pdf_export toneAmber
class node_translation_flow,node_text_chunks,node_stream_parser,node_translation_service,node_zhipu toneMint
class node_key_manager,node_key_config toneRose
class node_user toneIndigo
```

## Components

### Desktop interface

- [Desktop GUI](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [Preview interface](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/static/index.html): `static/index.html`
- [Webview bridge](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [Local content server](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/flask_server.py): `flask_server.py`

### Document handling

- [PDF import](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [Markdown import](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [PDF parsing client](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/analysis_pdf.py): `analysis_pdf.py`
- **MinerU service**
- [Temporary documents](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/tempdir_manager.py): `tempdir_manager.py`
- [Document images](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/flask_server.py): `flask_server.py`
- [Markdown export](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [PDF printing](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/static/index.html): `static/index.html`

### Translation

- [Translation orchestration](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [Text chunking](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/split_text.py): `split_text.py`
- [Stream parsing](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/main.py): `main.py`
- [Translation client](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/call_api.py): `call_api.py`
- **Zhipu AI**

### Configuration and state

- [API key management](https://github.com/duyu09/npa-paper-analyzer-and-translator/blob/main/key_manager.py): `key_manager.py`
- **Persistent API keys**

### Other components

- **Researcher**

## Connections

- Researcher → Preview interface: uses (evidence: `README.md`)
- Preview interface → Webview bridge: invokes (evidence: `README.md`)
- Webview bridge → Desktop GUI: dispatches (evidence: `main.py`)
- Desktop GUI → Local content server: serves through (evidence: `main.py`)
- Desktop GUI → PDF import: handles import (evidence: `main.py`)
- PDF import → PDF parsing client: calls (evidence: `main.py`)
- PDF import → Temporary documents: creates workspace (evidence: `main.py`)
- PDF parsing client → MinerU service: uploads and queries (evidence: `analysis_pdf.py`)
- PDF import → Markdown import: handles Markdown (evidence: `main.py`)
- PDF import → Local content server: sets document directory (evidence: `main.py`)
- Local content server → Document images: serves images (evidence: `flask_server.py`)
- Desktop GUI → Markdown export: saves translation (evidence: `main.py`)
- Preview interface → PDF printing: prints document (evidence: `README.md`)
- Preview interface → Translation orchestration: starts translation (evidence: `README.md`)
- Translation orchestration → Text chunking: splits text (evidence: `main.py`)
- Translation orchestration → Translation client: requests stream (evidence: `main.py`)
- Translation client → Zhipu AI: streams completion (evidence: `call_api.py`)
- Translation orchestration → Stream parsing: extracts translation (evidence: `main.py`)
- Stream parsing → Preview interface: updates live (evidence: `main.py`)
- Translation orchestration → API key management: stores API key (evidence: `main.py`)
- PDF import → API key management: stores MinerU key (evidence: `main.py`)
- Desktop GUI → API key management: reads and writes keys (evidence: `main.py`)
- API key management → Persistent API keys: persists (evidence: `key_manager.py`)
