# iamtomshaw/receipt-vision architecture

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

- Interactive diagram: https://gitdiagram.com/iamtomshaw/receipt-vision
- Repository: https://github.com/iamtomshaw/receipt-vision

## Overview

Key Components to Include:

##### Input Layer
- Image Input Component (receipt.jpg)
- File System Interface

##### Processing Pipeline
- Image Processing Module (OpenCV)
- OCR Engine (Pytesseract)
- AI Processing (OpenAI API)

##### Output Layer
- JSON Output Component (receipt.json)
- File System Interface

##### Connection Flow
- receipt.jpg → OpenCV → Pytesseract → OpenAI API → JSON Output

##### Specific Elements
a. Input Section:
- Receipt Image File
- File System Reader

b. Processing Section:
- OpenCV Image Processing
- Pytesseract OCR Engine
- OpenAI API Integration

c. Output Section:
- JSON Formatter
- File System Writer

##### Additional Details
- Version/dependency information (Python 3.x)
- Async operations where applicable (OpenAI API calls)

##### Technical Labels
- Method names from main.py
- Configuration points (API key, file paths)

##### Boundaries
- Clearly separate external services
- File I/O boundaries

Remember to include any error handling or retry mechanisms, especially for the external API calls to OpenAI. Also, indicate any configuration requirements like the OpenAI API key setup.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IMG[Receipt Image]
        FSR[File System Reader]
    end

    subgraph Processing
        direction TB
        CV[OpenCV Processing]:::processing
        OCR[Pytesseract OCR]:::processing
        AI[OpenAI API]:::external
    end

    subgraph Output
        JSON[JSON Formatter]
        FSW[File System Writer]
    end

    IMG --> FSR
    FSR --> CV
    CV --> OCR
    OCR --> AI
    AI --> JSON
    JSON --> FSW

    %% Component relationships
    IMG -- ".jpg/.png" --> FSR
    FSR -- "binary data" --> CV
    CV -- "processed image" --> OCR
    OCR -- "extracted text" --> AI
    AI -- "structured data" --> JSON
    JSON -- "receipt.json" --> FSW

    %% Click events for file mapping
    click CV "https://github.com/IAmTomShaw/receipt-vision/blob/main/main.py"
    click OCR "https://github.com/IAmTomShaw/receipt-vision/blob/main/main.py"
    click AI "https://github.com/IAmTomShaw/receipt-vision/blob/main/main.py"
    click JSON "https://github.com/IAmTomShaw/receipt-vision/blob/main/main.py"

    %% Styling
    classDef processing fill:#90EE90,stroke:#333,stroke-width:2px
    classDef external fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef storage fill:#87CEEB,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Processing Component]:::processing
        L2[External Service]:::external
        L3[Storage/IO]:::storage
    end
```
