# billstark/receipt-scanner architecture

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

- Interactive diagram: https://gitdiagram.com/billstark/receipt-scanner
- Repository: https://github.com/billstark/receipt-scanner

## Overview

This repository is a receipt-scanning OCR application with a parallel synthetic-receipt and training-data workflow. The principal user path starts with an image, segments it into lines, recognizes text with the CRNN, and formats the result. The tree also contains a CNN classifier and receipt-generation utilities. Several connections below rely on SOURCE INDEX references or README documentation rather than fully sampled implementations; unsampled subsystems are represented without guessed call chains.

Main entry points: [`CRNNModel/image_classifier.py`](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/image_classifier.py) (CRNN classifier), [`crnn_processor.py`](https://github.com/billstark/receipt-scanner/blob/master/crnn_processor.py) (Scan CLI), [`CRNNModel/local_utils/data_utils.py`](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/data_utils.py) (Character decoding), [`CRNNModel/train_shadownet.py`](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/train_shadownet.py) (CRNN training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_scan["Receipt scanning"]
  node_cli["Scan CLI<br/>[crnn_processor.py]"]
  node_segment["Line segmentation<br/>[line_seg.py]"]
  node_format["Text output<br/>[output_text.py]"]
end

subgraph group_ocr["CRNN recognition"]
  node_recognizer["CRNN classifier"]
  node_network["CRNN network<br/>[crnn_model.py]"]
  node_cnnbase["CNN base layers<br/>[cnn_basenet.py]"]
  node_imageprep["Image standardization<br/>[image_utils.py]"]
end

subgraph group_training["OCR data and training"]
  node_decode["Character decoding<br/>[data_utils.py]"]
  node_charset["Character dictionary"]
  node_data["Dataset provider<br/>[data_provider.py]"]
  node_datasetbase["Dataset base"]
  node_train["CRNN training<br/>[train_shadownet.py]"]
  node_config["Model configuration<br/>[config.py]"]
  node_featurewriter["Feature generation"]
end

subgraph group_synthetic["Receipt generation"]
  node_receiptdraw["Receipt rendering<br/>[draw_receipt.py]"]
  node_items["Receipt items<br/>[items_creator.py]"]
  node_lettercut["Letter boxes<br/>[letter_cutter.py]"]
  node_boxes["Bounding boxes<br/>[bounding_box.py]"]
end

subgraph group_cnn["CNN classification"]
  node_cnnprocessor["CNN processor<br/>[cnn_processor.py]"]
  node_cnnclassifier["CNN classifier"]
  node_cnnmodel["CNN model<br/>[cnn_model.py]"]
  node_cnnrecords["Image records"]
  node_cnngenerator["Image generation<br/>[image_generator.py]"]
end

node_user(("Image user"))
node_result["Recognized receipt text"]

node_user -->|"provides image"| node_cli
node_cli -->|"segments image"| node_segment
node_cli -->|"recognizes lines"| node_recognizer
node_cli -->|"formats text"| node_format
node_format -->|"produces text"| node_result
node_recognizer -->|"builds network"| node_network
node_recognizer -->|"configures session"| node_config
node_recognizer -->|"standardizes images"| node_imageprep
node_recognizer -->|"decodes predictions"| node_decode
node_network -->|"uses layers"| node_cnnbase
node_decode -->|"loads character map"| node_charset
node_train -->|"trains network"| node_network
node_train -->|"reads settings"| node_config
node_train -->|"uses label utilities"| node_decode
node_data -->|"extends dataset"| node_datasetbase
node_featurewriter -->|"uses provider"| node_data
node_featurewriter -->|"uses feature utilities"| node_decode
node_receiptdraw -->|"creates items"| node_items
node_receiptdraw -->|"cuts letters"| node_lettercut
node_lettercut -->|"uses boxes"| node_boxes
node_cnnprocessor -->|"requests receipt"| node_receiptdraw
node_cnnprocessor -->|"classifies image"| node_cnnclassifier
node_cnnclassifier -->|"uses model"| node_cnnmodel

click node_cli "https://github.com/billstark/receipt-scanner/blob/master/crnn_processor.py"
click node_segment "https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/line_seg.py"
click node_format "https://github.com/billstark/receipt-scanner/blob/master/ReceiptProcessor/output_text.py"
click node_recognizer "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/image_classifier.py"
click node_network "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/crnn_model/crnn_model.py"
click node_cnnbase "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/crnn_model/cnn_basenet.py"
click node_imageprep "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/image_utils.py"
click node_decode "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/data_utils.py"
click node_charset "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/establish_char_dict.py"
click node_data "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/data_provider/data_provider.py"
click node_datasetbase "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/data_provider/base_data_provider.py"
click node_train "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/train_shadownet.py"
click node_config "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/global_configuration/config.py"
click node_featurewriter "https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/write_text_features.py"
click node_receiptdraw "https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/draw_receipt.py"
click node_items "https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/items_creator.py"
click node_lettercut "https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/letter_cutter.py"
click node_boxes "https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/bounding_box.py"
click node_cnnprocessor "https://github.com/billstark/receipt-scanner/blob/master/ReceiptProcessor/cnn_processor.py"
click node_cnnclassifier "https://github.com/billstark/receipt-scanner/blob/master/CNNModel/image_classifier.py"
click node_cnnmodel "https://github.com/billstark/receipt-scanner/blob/master/CNNModel/cnn_model.py"
click node_cnnrecords "https://github.com/billstark/receipt-scanner/blob/master/CNNModel/image_to_records.py"
click node_cnngenerator "https://github.com/billstark/receipt-scanner/blob/master/CNNModel/image_generator.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_cli,node_segment,node_format,node_user toneBlue
class node_recognizer,node_network,node_cnnbase,node_imageprep toneAmber
class node_decode,node_charset,node_data,node_datasetbase,node_train,node_config,node_featurewriter toneMint
class node_receiptdraw,node_items,node_lettercut,node_boxes toneRose
class node_cnnprocessor,node_cnnclassifier,node_cnnmodel,node_cnnrecords,node_cnngenerator,node_result toneIndigo
```

## Components

### Receipt scanning

- [Scan CLI](https://github.com/billstark/receipt-scanner/blob/master/crnn_processor.py): `crnn_processor.py`
- [Line segmentation](https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/line_seg.py): `ReceiptGenerator/line_seg.py`
- [Text output](https://github.com/billstark/receipt-scanner/blob/master/ReceiptProcessor/output_text.py): `ReceiptProcessor/output_text.py`

### CRNN recognition

- [CRNN classifier](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/image_classifier.py): `CRNNModel/image_classifier.py`
- [CRNN network](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/crnn_model/crnn_model.py): `CRNNModel/crnn_model/crnn_model.py`
- [CNN base layers](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/crnn_model/cnn_basenet.py): `CRNNModel/crnn_model/cnn_basenet.py`
- [Image standardization](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/image_utils.py): `CRNNModel/local_utils/image_utils.py`

### OCR data and training

- [Character decoding](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/data_utils.py): `CRNNModel/local_utils/data_utils.py`
- [Character dictionary](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/local_utils/establish_char_dict.py): `CRNNModel/local_utils/establish_char_dict.py`
- [Dataset provider](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/data_provider/data_provider.py): `CRNNModel/data_provider/data_provider.py`
- [Dataset base](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/data_provider/base_data_provider.py): `CRNNModel/data_provider/base_data_provider.py`
- [CRNN training](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/train_shadownet.py): `CRNNModel/train_shadownet.py`
- [Model configuration](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/global_configuration/config.py): `CRNNModel/global_configuration/config.py`
- [Feature generation](https://github.com/billstark/receipt-scanner/blob/master/CRNNModel/write_text_features.py): `CRNNModel/write_text_features.py`

### Receipt generation

- [Receipt rendering](https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/draw_receipt.py): `ReceiptGenerator/draw_receipt.py`
- [Receipt items](https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/items_creator.py): `ReceiptGenerator/items_creator.py`
- [Letter boxes](https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/letter_cutter.py): `ReceiptGenerator/letter_cutter.py`
- [Bounding boxes](https://github.com/billstark/receipt-scanner/blob/master/ReceiptGenerator/bounding_box.py): `ReceiptGenerator/bounding_box.py`

### CNN classification

- [CNN processor](https://github.com/billstark/receipt-scanner/blob/master/ReceiptProcessor/cnn_processor.py): `ReceiptProcessor/cnn_processor.py`
- [CNN classifier](https://github.com/billstark/receipt-scanner/blob/master/CNNModel/image_classifier.py): `CNNModel/image_classifier.py`
- [CNN model](https://github.com/billstark/receipt-scanner/blob/master/CNNModel/cnn_model.py): `CNNModel/cnn_model.py`
- [Image records](https://github.com/billstark/receipt-scanner/blob/master/CNNModel/image_to_records.py): `CNNModel/image_to_records.py`
- [Image generation](https://github.com/billstark/receipt-scanner/blob/master/CNNModel/image_generator.py): `CNNModel/image_generator.py`

### Other components

- **Image user**
- **Recognized receipt text**

## Connections

- Image user → Scan CLI: provides image (evidence: `README.md`)
- Scan CLI → Line segmentation: segments image (evidence: `crnn_processor.py`)
- Scan CLI → CRNN classifier: recognizes lines (evidence: `crnn_processor.py`)
- Scan CLI → Text output: formats text (evidence: `crnn_processor.py`)
- Text output → Recognized receipt text: produces text
- CRNN classifier → CRNN network: builds network (evidence: `CRNNModel/image_classifier.py`)
- CRNN classifier → Model configuration: configures session (evidence: `CRNNModel/image_classifier.py`)
- CRNN classifier → Image standardization: standardizes images (evidence: `CRNNModel/image_classifier.py`)
- CRNN classifier → Character decoding: decodes predictions (evidence: `CRNNModel/image_classifier.py`)
- CRNN network → CNN base layers: uses layers (evidence: `CRNNModel/crnn_model/crnn_model.py`)
- Character decoding → Character dictionary: loads character map (evidence: `CRNNModel/local_utils/data_utils.py`)
- CRNN training → CRNN network: trains network (evidence: `CRNNModel/train_shadownet.py`)
- CRNN training → Model configuration: reads settings (evidence: `CRNNModel/train_shadownet.py`)
- CRNN training → Character decoding: uses label utilities (evidence: `CRNNModel/train_shadownet.py`)
- Dataset provider → Dataset base: extends dataset (evidence: `CRNNModel/data_provider/data_provider.py`)
- Feature generation → Dataset provider: uses provider (evidence: `CRNNModel/write_text_features.py`)
- Feature generation → Character decoding: uses feature utilities (evidence: `CRNNModel/write_text_features.py`)
- Receipt rendering → Receipt items: creates items (evidence: `ReceiptGenerator/draw_receipt.py`)
- Receipt rendering → Letter boxes: cuts letters (evidence: `ReceiptGenerator/draw_receipt.py`)
- Letter boxes → Bounding boxes: uses boxes (evidence: `ReceiptGenerator/letter_cutter.py`)
- CNN processor → Receipt rendering: requests receipt (evidence: `ReceiptProcessor/cnn_processor.py`)
- CNN processor → CNN classifier: classifies image (evidence: `ReceiptProcessor/cnn_processor.py`)
- CNN classifier → CNN model: uses model (evidence: `CNNModel/image_classifier.py`)
