# mindee/doctr architecture

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

- Interactive diagram: https://gitdiagram.com/mindee/doctr
- Repository: https://github.com/mindee/doctr

## Overview

##### Main Components Structure

a) Core Components:
- Document Processing Layer
- Model Layer
- I/O Layer
- Transforms Layer
- Datasets Layer
- API Layer

b) Framework Support:
- PyTorch Implementation
- TensorFlow Implementation

##### Detailed Component Breakdown

Document Processing Layer:
- To DocumentFile class with support for:
- PDF processing
- Image processing
- URL/webpage processing

Model Layer (Central Component):
- Detection Models (DBNet, LinkNet, FAST)
- Recognition Models (CRNN, SAR, MASTER, ViTSTR, PARSeq)
- KIE Predictor
- Model Factory/Hub
- Preprocessor
- Framework-specific implementations

I/O Layer:
- Document readers
- Image processors
- HTML generators
- PDF processors

##### Data Flow Representation

- Input flow: Document → Preprocessor → Detection → Recognition → Output
- Training flow: Datasets → Transforms → Models → Evaluation
- API flow: Request → Processing → Model Inference → Response

##### Component Relationships

- Model inheritance relationships
- Data transformation flow
- Framework-specific implementations
- API integration points

##### Integration Points

Highlight:
- API endpoints
- Docker container integration
- Framework interoperability
- External service connections

##### Specific Implementation Details

- Configuration options
- Model architectures
- Dataset handlers
- Transform operations

**[Input Sources] → [Document Processor]**
- ↓
**[Preprocessor] → [Detection Models] → [Recognition Models]**
- ↑               ↑                    ↑
**[Transforms] ←→ [Framework Layer: PyTorch/TensorFlow]**
- ↑               ↑                    ↑
**[Datasets] ←→   [Model Factory/Hub]    [Evaluation]**
- ↓
- [API Layer]
- ↓
- [Output Formats]

Key Considerations:

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        IS[Input Sources]
        PDF[PDF Files]
        IMG[Images]
        URL[URLs/Webpages]
    end

    subgraph DocProcess[Document Processing & I/O Layer]
        DP[Document Processor]:::core
        DR[Document Reader]:::io
        IP[Image Processor]:::io
        PP[PDF Processor]:::io
    end

    subgraph ML[Model Layer]
        PRE[Preprocessor]:::model
        
        subgraph DET[Detection Models]
            DB[DBNet]:::model
            LN[LinkNet]:::model
            FT[FAST]:::model
        end
        
        subgraph REC[Recognition Models]
            CR[CRNN]:::model
            SR[SAR]:::model
            MS[MASTER]:::model
            VT[ViTSTR]:::model
            PS[PARSeq]:::model
        end
        
        KIE[KIE Predictor]:::model
        MF[Model Factory/Hub]:::model
    end

    subgraph FW[Framework Layer]
        PT[PyTorch Implementation]:::framework
        TF[TensorFlow Implementation]:::framework
    end

    subgraph Support
        TR[Transforms]:::util
        DS[Datasets]:::util
        EV[Evaluation]:::util
    end

    subgraph API[API Layer]
        AP[API Endpoints]:::api
        DC[Docker Container]:::api
    end

    subgraph Output
        OF[Output Formats]
        HG[HTML Generator]:::output
        PO[PDF Output]:::output
        TO[Text Output]:::output
    end

    %% Connections
    IS --> DP
    PDF --> DP
    IMG --> DP
    URL --> DP
    
    DP --> PRE
    PRE --> DET
    DET --> REC
    REC --> KIE
    
    TR <--> PT
    TR <--> TF
    DS <--> PT
    DS <--> TF
    
    PT --> DET
    TF --> DET
    PT --> REC
    TF --> REC
    
    MF --> DET
    MF --> REC
    
    KIE --> AP
    AP --> OF
    
    %% Styling
    classDef core fill:#2374ab
    classDef io fill:#57a773
    classDef model fill:#ff8c42
    classDef framework fill:#9b5de5
    classDef util fill:#808080
    classDef api fill:#00b4d8
    classDef output fill:#57a773

    %% Click events
    click DP "https://github.com/mindee/doctr/tree/main/doctr/io/"
    click DR "https://github.com/mindee/doctr/blob/main/doctr/io/reader.py"
    click PP "https://github.com/mindee/doctr/blob/main/doctr/io/pdf.py"
    click IP "https://github.com/mindee/doctr/tree/main/doctr/io/image/"
    click PRE "https://github.com/mindee/doctr/tree/main/doctr/models/preprocessor/"
    click DET "https://github.com/mindee/doctr/tree/main/doctr/models/detection/"
    click REC "https://github.com/mindee/doctr/tree/main/doctr/models/recognition/"
    click KIE "https://github.com/mindee/doctr/tree/main/doctr/models/kie_predictor/"
    click MF "https://github.com/mindee/doctr/tree/main/doctr/models/factory/"
    click TR "https://github.com/mindee/doctr/tree/main/doctr/transforms/"
    click DS "https://github.com/mindee/doctr/tree/main/doctr/datasets/"
    click AP "https://github.com/mindee/doctr/tree/main/api/"
    click PT "https://github.com/mindee/doctr/blob/main/doctr/models/detection/predictor/pytorch.py"
    click TF "https://github.com/mindee/doctr/blob/main/doctr/models/detection/predictor/tensorflow.py"
    click CR "https://github.com/mindee/doctr/tree/main/doctr/models/recognition/crnn/"
    click SR "https://github.com/mindee/doctr/tree/main/doctr/models/recognition/sar/"
    click MS "https://github.com/mindee/doctr/tree/main/doctr/models/recognition/master/"
    click VT "https://github.com/mindee/doctr/tree/main/doctr/models/recognition/vitstr/"
    click PS "https://github.com/mindee/doctr/tree/main/doctr/models/recognition/parseq/"
    click DB "https://github.com/mindee/doctr/tree/main/doctr/models/detection/differentiable_binarization/"
    click FT "https://github.com/mindee/doctr/tree/main/doctr/models/detection/fast/"
```
