# lilllee/ocr_app architecture

> Architecture diagram of the GitHub repository lilllee/ocr_app, 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/lilllee/ocr_app
- Repository: https://github.com/lilllee/ocr_app

## Overview

##### Main Components
- Web Frontend Layer: Represented by the assets folder (CSS, JS, vendor) for client-side logic and static files.
- Phoenix Web Server: Represented by the lib/ocr_app_web directory. This includes controllers (e.g., page_controller.ex), the router (router.ex), endpoint configuration (endpoint.ex), and view templates (under templates and views directories).
- Business Logic/Core Application Layer: Found in the lib/ocr_app directory. Key modules include the Application module (starting the supervision tree), the OCR module (ocr.ex) that encapsulates the OCR logic, and the Mailer module, likely used for notifications or processing results.
- Configuration Components: The config directory houses environment-specific configurations (dev, prod, test, runtime) which dictate how the application should behave in different environments.

##### Relationships and Interactions
- The User (via browser) makes requests that hit the Phoenix server.
- The Endpoint receives the HTTP request and routes it to the appropriate controller through the Router.
- The Controllers invoke business logic; for example, they may delegate image and OCR processing to the OCR module.
- Views and templates are used to render responses back to the client.
- Any client-side interactions (managed via JavaScript in the assets folder) can be depicted as interacting with the Phoenix-generated HTML.

##### Architectural Patterns and Technologies
- MVC Pattern: Clearly illustrate the separation between Models (if any business logic/stateful modules are present), Views (in ocr_app_web/views), and Controllers.
- Supervision Tree: The Application module (in lib/ocr_app/application.ex) might be managing various supervised processes. A note indicating a supervision hierarchy could be included.
- Dependency on External Tools: Clearly denote the interactions with Tesseract OCR for text recognition and ImageMagick for image manipulations.
- Technology Stack: Include labels for Elixir, Phoenix framework, and indicate the dependency on Node.js for managing JavaScript assets.

##### Essential Elements
- Main entry points (Phoenix Endpoint, Router)
- Controllers dispatching actions to both views and business logic modules (like OCR and Mailer)
- The OCR processing module, making external calls to Tesseract and ImageMagick – represent these as separate but connected components.
- Representation of static assets and client-side interactions.
- Configurations that empower different environments (depicted as a configuration block or separate layer).
- Testing components (optionally noting that tests exist in the test directory, which ensures proper behavior of controllers and views) to hint at the robustness of the architecture.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    A["User Browser"]:::user
    FE["Static Assets"]:::frontend

    subgraph "Phoenix Web Server"
        EP["Phoenix Endpoint"]:::backend
        RT["Router"]:::backend
        CT["Controller"]:::backend
        VT["Views & Templates"]:::backend
    end

    subgraph "Core Application Layer"
        AP["Application Module"]:::core
        OCR["OCR Module"]:::core
        ML["Mailer Module"]:::core
    end

    subgraph "Configuration"
        CFG["Configuration Files"]:::config
    end

    subgraph "External Services"
        TEX["Tesseract OCR"]:::external
        IMG["ImageMagick"]:::external
        EMS["Email Service"]:::external
    end

    %% Flow Connections
    A -->|"HTTP_Request"| EP
    A -->|"Load_Assets"| FE
    EP -->|"Route_Request"| RT
    RT -->|"Dispatch_Action"| CT
    CT -->|"Render_View"| VT
    CT -->|"Process_Uploaded_Image"| OCR
    CT -->|"Send_Notification"| ML
    OCR -->|"OCR_Processing"| TEX
    OCR -->|"Image_Manipulation"| IMG
    ML -->|"Send_Email"| EMS
    AP -->|"Supervises"| OCR
    AP -->|"Supervises"| ML
    CFG -->|"Configures"| EP
    CFG -->|"Configures"| CT
    CFG -->|"Configures"| OCR
    CFG -->|"Configures"| ML

    %% Click Events
    click FE "https://github.com/lilllee/ocr_app/tree/main/assets/"
    click EP "https://github.com/lilllee/ocr_app/tree/main/lib/ocr_app_web/"
    click AP "https://github.com/lilllee/ocr_app/blob/main/lib/ocr_app/application.ex"
    click OCR "https://github.com/lilllee/ocr_app/blob/main/lib/ocr_app/ocr.ex"
    click ML "https://github.com/lilllee/ocr_app/blob/main/lib/ocr_app/mailer.ex"
    click CFG "https://github.com/lilllee/ocr_app/tree/main/config/"

    %% Class Definitions for Colors
    classDef user stroke:#1f77b4,fill:#aec7e8,stroke-width:2px;
    classDef frontend stroke:#ff7f0e,fill:#ffbb78,stroke-width:2px;
    classDef backend stroke:#2ca02c,fill:#98df8a,stroke-width:2px;
    classDef core stroke:#d62728,fill:#ff9896,stroke-width:2px;
    classDef config stroke:#9467bd,fill:#c5b0d5,stroke-width:2px;
    classDef external stroke:#8c564b,fill:#c49c94,stroke-width:2px;
```
