# ieasybooks/tahweel architecture

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

- Interactive diagram: https://gitdiagram.com/ieasybooks/tahweel
- Repository: https://github.com/ieasybooks/tahweel

## Overview

##### Main Components Identification

a. Input Layer:
- CLI Interface (tahweel/cli.py)
- Argument Parser (tahweel/tahweel_argument_parser.py)

b. Core Processing Layer:
- File Managers (tahweel/managers/)
- OCR Processors (tahweel/processors/)
- Writers (tahweel/writers/)

c. External Services:
- Google Drive OCR Service
- Google Cloud Platform (Service Account Authentication)

**[Input Sources] → [Core Processing] → [Output Generation]**
- ↓                   ↕                    ↓
**[File System]    [Google Services]    [Generated Files]**

##### Component Details

a. Input Processing:
- PDF File/Directory Input
- Command Line Arguments
- Service Account Credentials

b. File Management:
- PDF File Manager
- Image File Manager
- File Manager Factory

c. Processing Pipeline:
- PDF to Image Conversion
- OCR Processing
- Text Extraction

d. Output Generation:
- TXT Writer
- DOCX Writer

##### Key Relationships to Highlight

- Parallel processing capability with thread pools
- Transformation pipeline: PDF → Images → OCR → Text → Output
- Demonstrate the interaction with Google Drive OCR services
- Factory pattern used in file management

##### Technical Details

Annotations for:
- Thread pool configurations
- Supported output formats
- File system interactions
- Google API integration points

**[PDF Input] → [Argument Parser] → [File Manager Factory]**
- ↓
**[Service Account] → [Google Drive OCR] ← [Image Conversion]**
- ↓
- [OCR Processing]
- ↓
- [Output Generation] → [TXT/DOCX Files]

##### The integration with external services

Remember to maintain a balance between detail and clarity, focusing on the key architectural decisions that make Tahweel efficient and scalable.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        CLI["CLI Interface"]
        AP["Argument Parser"]
        PDF["PDF Input"]
        SA["Service Account"]
    end

    subgraph "File Management"
        FMF["File Manager Factory"]
        PFM["PDF File Manager"]
        IFM["Image File Manager"]
    end

    subgraph "Processing Layer"
        BOCR["Base OCR Processor"]
        GDOCR["Google Drive OCR"]
        GDCOCR["Google Drive Colab OCR"]
        TM["Transformation Model"]
        IU["Image Utilities"]
    end

    subgraph "Output Layer"
        TXTW["TXT Writer"]
        DOCXW["DOCX Writer"]
        OFT["Output Format Types"]
        TT["Transformation Types"]
    end

    subgraph "External Services"
        GDS[("Google Drive Services")]
        GCP[("Google Cloud Platform")]
    end

    %% Connections
    CLI --> AP
    AP --> FMF
    PDF --> FMF
    SA --> GCP

    FMF --> PFM
    FMF --> IFM
    
    PFM --> BOCR
    IFM --> BOCR
    
    BOCR --> GDOCR
    BOCR --> GDCOCR
    
    GDOCR --> GDS
    GDCOCR --> GDS
    
    GDS --> TM
    TM --> OFT
    TM --> TT
    
    OFT --> TXTW
    OFT --> DOCXW
    
    IU --> BOCR

    %% Click Events
    click CLI "https://github.com/ieasybooks/tahweel/blob/main/tahweel/cli.py"
    click AP "https://github.com/ieasybooks/tahweel/blob/main/tahweel/tahweel_argument_parser.py"
    click FMF "https://github.com/ieasybooks/tahweel/blob/main/tahweel/managers/file_managers_factory.py"
    click PFM "https://github.com/ieasybooks/tahweel/blob/main/tahweel/managers/pdf_file_manager.py"
    click IFM "https://github.com/ieasybooks/tahweel/blob/main/tahweel/managers/image_file_manager.py"
    click BOCR "https://github.com/ieasybooks/tahweel/blob/main/tahweel/processors/base_ocr_processor.py"
    click GDOCR "https://github.com/ieasybooks/tahweel/blob/main/tahweel/processors/google_drive_ocr_processor.py"
    click GDCOCR "https://github.com/ieasybooks/tahweel/blob/main/tahweel/processors/google_drive_on_colab_ocr_processor.py"
    click TXTW "https://github.com/ieasybooks/tahweel/blob/main/tahweel/writers/txt_writer.py"
    click DOCXW "https://github.com/ieasybooks/tahweel/blob/main/tahweel/writers/docx_writer.py"
    click TM "https://github.com/ieasybooks/tahweel/blob/main/tahweel/models/transformation.py"
    click OFT "https://github.com/ieasybooks/tahweel/blob/main/tahweel/enums/output_format_type.py"
    click TT "https://github.com/ieasybooks/tahweel/blob/main/tahweel/enums/transformation_type.py"
    click IU "https://github.com/ieasybooks/tahweel/blob/main/tahweel/utils/image_utils.py"

    %% Styling
    classDef input fill:#a8d1ff
    classDef processing fill:#90EE90
    classDef output fill:#FFB6C1
    classDef external fill:#FFE4B5
    classDef fileManagement fill:#DDA0DD

    class CLI,AP,PDF,SA input
    class BOCR,GDOCR,GDCOCR,TM,IU processing
    class TXTW,DOCXW,OFT,TT output
    class GDS,GCP external
    class FMF,PFM,IFM fileManagement
```
