# coderreaper69/hindi_to_hinglish_convert architecture

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

- Interactive diagram: https://gitdiagram.com/coderreaper69/hindi_to_hinglish_convert
- Repository: https://github.com/coderreaper69/hindi_to_hinglish_convert

## Overview

##### Project type and purpose
- This is a single‐page, full-stack web application built with Streamlit.
- Purpose: take Hindi text in images or PDF files, send it to Google Gemini’s AI model for transliteration into Hinglish, and present/download the results.

##### File structure
- Top level:
- .devcontainer/devcontainer.json – dev container config
- main_enhanced.py – Streamlit entry point (UI/controller)
- ai_processing.py – image-based transliteration logic
- doc_file_processing.py – PDF page extraction + orchestration logic
- hindi_to_hinglish_all_code_at_once.py – monolithic earlier version
- requirements.txt – Python dependencies
- __init__.py – package marker
- image/ – static demo screenshots, templates
- No separate services or databases—everything runs in one process, hosted on Streamlit Cloud.

##### README for additional insights
- Components listed: Streamlit interface, Gemini API integration, PyMuPDF for PDF, BytesIO for memory-efficient file I/O, PDF generation for downloads, rate limiting.
- No persistent storage; files live in memory during session.

a. Main components
1. User’s Web Browser (Client)
2. Streamlit App (main_enhanced.py) – handles routing, UI, file uploads
3. File Handler / Orchestrator (doc_file_processing.py) – extracts PDF pages as images
4. Image Processing Module (ai_processing.py) – sends each image to Google Gemini
5. Google Gemini 2.0 Flash API (External Service)
6. PDF Generator – collects transliterated text and builds downloadable PDF
b. Relationships & data flow
- Browser → Streamlit App: upload image/PDF, UI events
- Streamlit App → File Handler: if PDF, extract pages (via PyMuPDF + BytesIO)
- Streamlit App / File Handler → Image Processing Module: pass image bytes
- Image Processing → Google Gemini API: send image, receive Hinglish text
- Image Processing → Streamlit App: return text snippets
- Streamlit App → PDF Generator: assemble pages/text into PDF stream
- Streamlit App → Browser: render text and provide download link
c. Architectural patterns
- Layered flow: UI layer → orchestration layer → processing layer → external API
- Modular code separation: single-responsibility modules for AI calls vs. PDF extraction vs. UI
- No persistent data layer
d. Key technologies
- Python/Streamlit for UI and server
- PyMuPDF (fitz) for PDF page extraction
- BytesIO for in-memory file operations
- Google Gemini 2.0 Flash AI model for transliteration
- ReportLab or similar for PDF generation (if used)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    Browser["User's Web Browser"]:::external

    %% UI Layer
    Streamlit["Streamlit App\n(main_enhanced.py)"]:::ui

    %% Processing Layer
    Decision{"File Type?"}:::processing
    FileHandler["PDF Handler\n(doc_file_processing.py)"]:::processing
    ImgProcessor["Image Processor\n(ai_processing.py)"]:::processing
    MonoVersion["Monolithic V1\n(hindi_to_hinglish_all_code_at_once.py)"]:::processing
    PDFGen["PDF Generator"]:::processing

    %% External Services
    Gemini["Google Gemini 2.0 Flash API"]:::external

    %% Project Files
    Dev[".devcontainer"]:::files
    Req["requirements.txt"]:::files
    Init["__init__.py"]:::files
    ImageDir["image/"]:::files

    %% Connections
    Browser -->|"upload image or PDF"| Streamlit
    Streamlit -->|"if PDF upload"| Decision
    Decision -->|"PDF"| FileHandler
    Decision -->|"Image"| ImgProcessor
    FileHandler -->|"extract pages via PyMuPDF & BytesIO"| ImgProcessor
    Streamlit -->|"(optional) use monolithic logic"| MonoVersion
    ImgProcessor -->|"HTTP JSON (rate-limited)"| Gemini
    Gemini -->|"Hinglish text response"| ImgProcessor
    ImgProcessor -->|"text snippets"| Streamlit
    Streamlit -->|"assemble pages"| PDFGen
    PDFGen -->|"PDF stream"| Streamlit
    Streamlit -->|"render text & download link"| Browser

    %% Click Events
    click Streamlit "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/main_enhanced.py"
    click FileHandler "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/doc_file_processing.py"
    click ImgProcessor "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/ai_processing.py"
    click MonoVersion "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/hindi_to_hinglish_all_code_at_once.py"
    click ImageDir "https://github.com/coderreaper69/hindi_to_hinglish_convert/tree/main/image/"
    click Dev "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/.devcontainer/devcontainer.json"
    click Req "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/requirements.txt"
    click Init "https://github.com/coderreaper69/hindi_to_hinglish_convert/blob/main/__init__.py"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#333,stroke-width:1px
    classDef processing fill:#DFFFD0,stroke:#333,stroke-width:1px
    classDef external fill:#FFD8A8,stroke:#333,stroke-width:1px
    classDef files fill:#EFEFEF,stroke:#666,stroke-dasharray: 2 2,stroke-width:1px
```
