# ashishcherian15/pdf-refactor architecture

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

- Interactive diagram: https://gitdiagram.com/ashishcherian15/pdf-refactor
- Repository: https://github.com/ashishcherian15/pdf-refactor

## Overview

PDF-Refactor is a FastAPI application for inspecting PDFs, previewing configured edits, and processing batches into ZIP downloads. The main workflow accepts PDFs and edit settings, applies removal, theme, and watermark operations, then returns processed files. The README is empty and the UI source was not sampled, so the graph reflects the API and engine code shown; preview rendering and PDF inspection are also included.

Main entry points: [`main.py`](https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py) (FastAPI endpoints), [`watermark_engine.py`](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py) (Single PDF processor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and input"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_config["Config builder<br/>[main.py]"]
  node_inspect["PDF inspection<br/>[main.py]"]
end

subgraph group_processing["PDF processing"]
  node_batch["Batch processor"]
  node_single["Single PDF processor"]
  node_remove_text["Text removal"]
  node_remove_vectors["Vector removal"]
  node_eraser["Eraser boxes"]
  node_theme["Page theming"]
  node_watermark["Watermarking"]
end

subgraph group_results["Previews and results"]
  node_preview["Preview rendering<br/>[main.py]"]
  node_archive["ZIP archive"]
end

node_user(("User"))
node_client(("HTTP client"))
node_pymupdf["PyMuPDF"]
node_download["Processed download"]
node_image["PNG preview"]
node_page_count["Page count"]

node_client -->|"submits PDFs"| node_api
node_api -->|"builds settings"| node_config
node_api -->|"dispatches inspection"| node_inspect
node_inspect -->|"opens PDF"| node_pymupdf
node_inspect -->|"returns count"| node_page_count
node_api -->|"dispatches batch"| node_batch
node_batch -->|"processes each PDF"| node_single
node_single -->|"strips strings"| node_remove_text
node_single -->|"strips vectors"| node_remove_vectors
node_single -->|"applies boxes"| node_eraser
node_single -->|"applies theme"| node_theme
node_single -->|"adds watermark"| node_watermark
node_remove_text -->|"redacts text"| node_pymupdf
node_remove_vectors -->|"redacts drawings"| node_pymupdf
node_eraser -->|"redacts regions"| node_pymupdf
node_theme -->|"draws page"| node_pymupdf
node_watermark -->|"inserts marks"| node_pymupdf
node_single -->|"saves PDF"| node_pymupdf
node_batch -->|"writes PDFs"| node_archive
node_archive -->|"returns ZIP bytes"| node_api
node_api -->|"streams ZIP"| node_download
node_client -->|"requests preview"| node_api
node_api -->|"processes preview PDF"| node_single
node_api -->|"renders processed page"| node_preview
node_preview -->|"renders page"| node_pymupdf
node_preview -->|"returns PNG"| node_image

click node_api "https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py"
click node_config "https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py"
click node_inspect "https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py"
click node_batch "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_single "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_remove_text "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_remove_vectors "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_eraser "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_theme "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_watermark "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py"
click node_preview "https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py"
click node_archive "https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.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_api,node_config,node_inspect,node_user,node_client,node_image toneBlue
class node_batch,node_single,node_remove_text,node_remove_vectors,node_eraser,node_theme,node_watermark toneAmber
class node_preview,node_archive toneMint
class node_pymupdf,node_download,node_page_count toneIndigo
```

## Components

### API and input

- [FastAPI endpoints](https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py): `main.py`
- [Config builder](https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py): `main.py`
- [PDF inspection](https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py): `main.py`

### PDF processing

- [Batch processor](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`
- [Single PDF processor](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`
- [Text removal](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`
- [Vector removal](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`
- [Eraser boxes](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`
- [Page theming](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`
- [Watermarking](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`

### Previews and results

- [Preview rendering](https://github.com/ashishcherian15/pdf-refactor/blob/main/main.py): `main.py`
- [ZIP archive](https://github.com/ashishcherian15/pdf-refactor/blob/main/watermark_engine.py): `watermark_engine.py`

### Other components

- **User**
- **HTTP client**
- **PyMuPDF**
- **Processed download**
- **PNG preview**
- **Page count**

## Connections

- HTTP client → FastAPI endpoints: submits PDFs
- FastAPI endpoints → Config builder: builds settings
- FastAPI endpoints → PDF inspection: dispatches inspection
- PDF inspection → PyMuPDF: opens PDF
- PDF inspection → Page count: returns count
- FastAPI endpoints → Batch processor: dispatches batch
- Batch processor → Single PDF processor: processes each PDF
- Single PDF processor → Text removal: strips strings
- Single PDF processor → Vector removal: strips vectors
- Single PDF processor → Eraser boxes: applies boxes
- Single PDF processor → Page theming: applies theme
- Single PDF processor → Watermarking: adds watermark
- Text removal → PyMuPDF: redacts text
- Vector removal → PyMuPDF: redacts drawings
- Eraser boxes → PyMuPDF: redacts regions
- Page theming → PyMuPDF: draws page
- Watermarking → PyMuPDF: inserts marks
- Single PDF processor → PyMuPDF: saves PDF
- Batch processor → ZIP archive: writes PDFs
- ZIP archive → FastAPI endpoints: returns ZIP bytes
- FastAPI endpoints → Processed download: streams ZIP
- HTTP client → FastAPI endpoints: requests preview
- FastAPI endpoints → Single PDF processor: processes preview PDF
- FastAPI endpoints → Preview rendering: renders processed page
- Preview rendering → PyMuPDF: renders page
- Preview rendering → PNG preview: returns PNG
