# napatjia/document-segmentation architecture

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

- Interactive diagram: https://gitdiagram.com/napatjia/document-segmentation
- Repository: https://github.com/napatjia/document-segmentation

## Overview

This is a Streamlit multi-document scanner: users upload images, the app detects document regions, rectifies and enhances each page, then combines the results into a downloadable PDF. The workflow and image-processing stages are all implemented in one source file; the YOLO model is a separate repository artifact. The README is empty, so capabilities and relationships shown here are limited to the sampled application source.

Main entry points: [`streamlit_app.py`](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py) (Document detection), [`modelv2.pt`](https://github.com/napatjia/document-segmentation/blob/main/modelv2.pt) (YOLO model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["User interaction"]
  node_upload["Image upload<br/>[streamlit_app.py]"]
  node_preview["Preview control<br/>[streamlit_app.py]"]
end

subgraph group_processing["Image processing"]
  node_detector["Document detection<br/>[streamlit_app.py]"]
  node_model["YOLO model<br/>[modelv2.pt]"]
  node_region["Region extraction<br/>[streamlit_app.py]"]
  node_rectify["Page rectification<br/>[streamlit_app.py]"]
  node_enhance["Image enhancement<br/>[streamlit_app.py]"]
end

subgraph group_output["Document output"]
  node_pdf["PDF assembly<br/>[streamlit_app.py]"]
  node_download["PDF download<br/>[streamlit_app.py]"]
end

node_user(("User"))

node_user -->|"uploads images"| node_upload
node_user -->|"sets preview"| node_preview
node_upload -->|"submits images"| node_detector
node_detector -->|"loads model"| node_model
node_detector -->|"returns masks"| node_region
node_region -->|"supplies contours"| node_rectify
node_rectify -->|"supplies page"| node_enhance
node_enhance -->|"renders pages"| node_preview
node_enhance -->|"supplies pages"| node_pdf
node_pdf -->|"provides PDF"| node_download
node_download -->|"offers download"| node_user

click node_upload "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_preview "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_detector "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_model "https://github.com/napatjia/document-segmentation/blob/main/modelv2.pt"
click node_region "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_rectify "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_enhance "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_pdf "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py"
click node_download "https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.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_upload,node_preview,node_user toneBlue
class node_detector,node_model,node_region,node_rectify,node_enhance toneAmber
class node_pdf,node_download toneMint
```

## Components

### User interaction

- [Image upload](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`
- [Preview control](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`

### Image processing

- [Document detection](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`
- [YOLO model](https://github.com/napatjia/document-segmentation/blob/main/modelv2.pt): `modelv2.pt`
- [Region extraction](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`
- [Page rectification](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`
- [Image enhancement](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`

### Document output

- [PDF assembly](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`
- [PDF download](https://github.com/napatjia/document-segmentation/blob/main/streamlit_app.py): `streamlit_app.py`

### Other components

- **User**

## Connections

- User → Image upload: uploads images (evidence: `streamlit_app.py`)
- User → Preview control: sets preview (evidence: `streamlit_app.py`)
- Image upload → Document detection: submits images (evidence: `streamlit_app.py`)
- Document detection → YOLO model: loads model (evidence: `streamlit_app.py`)
- Document detection → Region extraction: returns masks (evidence: `streamlit_app.py`)
- Region extraction → Page rectification: supplies contours (evidence: `streamlit_app.py`)
- Page rectification → Image enhancement: supplies page (evidence: `streamlit_app.py`)
- Image enhancement → Preview control: renders pages (evidence: `streamlit_app.py`)
- Image enhancement → PDF assembly: supplies pages (evidence: `streamlit_app.py`)
- PDF assembly → PDF download: provides PDF (evidence: `streamlit_app.py`)
- PDF download → User: offers download (evidence: `streamlit_app.py`)
