# naivehobo/invoicenet architecture

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

- Interactive diagram: https://gitdiagram.com/naivehobo/invoicenet
- Repository: https://github.com/naivehobo/invoicenet

## Overview

##### Main Components

a) User Interface Layer:
- GUI Module (invoicenet/gui/)
- Two main interfaces: Trainer GUI and Extractor GUI
- Custom widgets for user interaction

b) Core Processing Layer:
- ACP (Attend, Copy, Parse) Module (invoicenet/acp/)
- Parsing Module (invoicenet/parsing/)
- Common Utilities (invoicenet/common/)

c) Data Layer:
- Model Storage (models/ directory)
- Training Data Interface
- Prediction Data Interface

##### Component Relationships

**[User Interface Layer]**
- ↕
**[Core Processing Layer]**
- ↕
**[Data Layer]**

##### Specific Elements

a) Input Processing:
- PDF/JPG/PNG document input
- OCR Engine integration
- Data preparation pipeline

b) Training Flow:
- Data preparation component
- Model training pipeline
- Model storage system

c) Extraction Flow:
- Document input handling
- Field extraction process
- Results output system

##### Key Architectural Patterns to Highlight

- Modular architecture with clear separation of concerns
- Pipeline pattern for data processing
- MVC pattern in the GUI implementation

##### Detailed Component Breakdown

GUI Layer:
**[Trainer GUI] ←→ [Extractor GUI]**
- ↓              ↓
**[Custom Widgets] [Viewer]**
- ↓              ↓
**[Help System]    [Field Extraction]**

Core Processing:
**[ACP Module]**
- ↓
**[Parser Module] → [Amount Parser]**
- → [Date Parser]
- ↓
**[Common Utilities]**

Data Flow:
**[Input Documents] → [Data Preparation] → [Training Pipeline]**
- → [Prediction Pipeline]

##### Technical Stack Elements

- TensorFlow framework
- CUDA/cuDNN integration
- External dependencies (Tesseract, ImageMagick, Ghostscript)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        GUI["GUI Module"]:::ui
        TG["Trainer GUI"]:::ui
        EG["Extractor GUI"]:::ui
        CW["Custom Widgets"]:::ui
        HS["Help System"]:::ui
        VW["Viewer"]:::ui
        FE["Field Extraction"]:::ui

        GUI --> TG
        GUI --> EG
        TG & EG --> CW
        TG & EG --> HS
        EG --> VW
        VW --> FE
    end

    subgraph Core["Core Processing Layer"]
        ACP["ACP Module"]:::core
        PM["Parsing Module"]:::core
        CU["Common Utilities"]:::core
        AP["Amount Parser"]:::core
        DP["Date Parser"]:::core

        ACP --> PM
        PM --> AP
        PM --> DP
        CU --> ACP
        CU --> PM
    end

    subgraph Data["Data Layer"]
        MS["Model Storage"]:::data
        APM["Amount Parser Models"]:::data
        DPM["Date Parser Models"]:::data
        DPP["Data Preparation Pipeline"]:::data
        TP["Training Pipeline"]:::data
        PP["Prediction Pipeline"]:::data

        MS --> APM
        MS --> DPM
        DPP --> TP
        DPP --> PP
    end

    subgraph External["External Dependencies"]
        OCR["OCR Engine"]:::external
        PDF["PDF Processing"]:::external
        TF["TensorFlow"]:::external
        CUDA["CUDA/cuDNN"]:::external
    end

    UI --> Core
    Core --> Data
    External --> Core

    %% Click events for component mapping
    click GUI "https://github.com/naiveHobo/InvoiceNet/tree/main/invoicenet/gui/"
    click TG "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/gui/trainer.py"
    click EG "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/gui/extractor.py"
    click CW "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/gui/custom_widgets.py"
    click HS "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/gui/help_box.py"
    click VW "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/gui/viewer.py"
    click ACP "https://github.com/naiveHobo/InvoiceNet/tree/main/invoicenet/acp/"
    click PM "https://github.com/naiveHobo/InvoiceNet/tree/main/invoicenet/parsing/"
    click CU "https://github.com/naiveHobo/InvoiceNet/tree/main/invoicenet/common/"
    click AP "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/parsing/amount_generator.py"
    click DP "https://github.com/naiveHobo/InvoiceNet/blob/main/invoicenet/parsing/date_generator.py"
    click MS "https://github.com/naiveHobo/InvoiceNet/tree/main/models/"
    click APM "https://github.com/naiveHobo/InvoiceNet/tree/main/models/parsers/amount/"
    click DPM "https://github.com/naiveHobo/InvoiceNet/tree/main/models/parsers/date/"
    click DPP "https://github.com/naiveHobo/InvoiceNet/blob/main/prepare_data.py"
    click TP "https://github.com/naiveHobo/InvoiceNet/blob/main/train.py"
    click PP "https://github.com/naiveHobo/InvoiceNet/blob/main/predict.py"

    %% Styling
    classDef ui fill:#3498db,stroke:#2980b9,color:#fff
    classDef core fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef data fill:#95a5a6,stroke:#7f8c8d,color:#fff
    classDef external fill:#e74c3c,stroke:#c0392b,color:#fff

    %% Legend
    subgraph Legend
        L1["UI Components"]:::ui
        L2["Core Components"]:::core
        L3["Data Components"]:::data
        L4["External Dependencies"]:::external
    end
```
