# stonesteel27/comiq architecture

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

- Interactive diagram: https://gitdiagram.com/stonesteel27/comiq
- Repository: https://github.com/stonesteel27/comiq

## Overview

##### Main Components
- Core Library (comiq package): The central part of the system with files like comiq.py, ai_processing.py, ocr.py, preprocessing.py, prompts.py, and utils.py.
- External OCR Engines: Represent the two external OCR engines (EasyOCR and PaddleOCR) that the library interacts with.
- Google's Gemini Flash Model: Denote this as an external AI service used to enhance or process OCR results.
- API Key Management: A component responsible for managing and validating API keys (via set_api_key) for accessing Gemini features.
- Client Interface: The user-facing Python module call, where developers import ComiQ and call high-level functions like extract().

##### Out the Data Flow and Relationships
- EasyOCR Module (external service/engine)
- PaddleOCR Module (external service/engine)
- From these OCR modules, combine the results via an “Aggregation/Merging Component” (often orchestrated by logic in ocr.py or even comiq.py).
- Next, indicate a connection from the aggregated OCR results to the “AI Processing Component” (ai_processing.py) which represents the integration with the Gemini Flash 1.5 model. Also, note the role of prompts (handled by prompts.py) that may assist in querying or processing the OCR outputs.

##### Important Architectural Patterns
- Modular Design: Each file in the comiq package represents a distinct functional module. Highlight how these modules interact through well-defined functions and layers.
- Abstraction of External Services: Separate blocks for each OCR engine and external AI model, indicating that they are “pluggable” parts of the architecture.

##### Relevant Technologies and Design Principles
- Python-based library with file modules for utility functions and orchestration.
- Leveraging external libraries and models (EasyOCR, PaddleOCR, OpenCV – for image handling, and the Gemini Flash API).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    Client["Client (User Code)"]:::internal

    %% ComiQ Core Library Subgraph
    subgraph "ComiQ Core Library"
        CI["Client Interface (comiq.py)\n(set_api_key & extract())"]:::internal
        PP["Preprocessing (preprocessing.py)"]:::internal
        OCR["OCR Aggregation (ocr.py)"]:::internal
        AIP["AI Processing (ai_processing.py)"]:::internal
        PM["Prompt Management (prompts.py)"]:::internal
    end

    %% External OCR Engines and AI Service
    EO["OCR Engine - EasyOCR"]:::external
    PO["OCR Engine - PaddleOCR"]:::external
    Gemini["Google Gemini Flash Model"]:::external

    %% Flow Connections
    Client -->|"calls"| CI
    CI -->|"prepares image"| PP

    %% Parallel paths from Preprocessing to OCR Engines
    PP -->|"OCR processing"| EO
    PP -->|"OCR processing"| PO

    %% Aggregation of OCR outputs
    EO --> OCR
    PO --> OCR

    %% AI Processing and Prompt usage
    OCR -->|"aggregates OCR results"| AIP
    AIP -->|"queries"| Gemini
    AIP -->|"uses-prompts"| PM

    %% Return processed data back to Client
    AIP -->|"returns data"| Client

    %% Styles
    classDef internal fill:#b3d9ff,stroke:#333,stroke-width:2px;
    classDef external fill:#ffe6b3,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mapping
    click CI "https://github.com/stonesteel27/comiq/blob/main/src/comiq/comiq.py"
    click PP "https://github.com/stonesteel27/comiq/blob/main/src/comiq/preprocessing.py"
    click OCR "https://github.com/stonesteel27/comiq/blob/main/src/comiq/ocr.py"
    click AIP "https://github.com/stonesteel27/comiq/blob/main/src/comiq/ai_processing.py"
    click PM "https://github.com/stonesteel27/comiq/blob/main/src/comiq/prompts.py"
    click CI "https://github.com/stonesteel27/comiq/tree/main/src/comiq/"
```
