# moinshariff26/ocr-and-multilingual-translator architecture

> Architecture diagram of the GitHub repository moinshariff26/ocr-and-multilingual-translator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moinshariff26/ocr-and-multilingual-translator
- Repository: https://github.com/moinshariff26/ocr-and-multilingual-translator

## Overview

1. **Overall shape**
   - This repository is a single-process Flask web application with three user-facing pages: a landing page, the main OCR/translation tool, and a records page.
   - The core runtime boundary is: browser UI → Flask backend → OCR/translation libraries → SQLite storage.

2. **Frontend presentation layer**
   - `templates/landing.html`, `templates/index.html`, and `templates/records.html` define the three routes’ HTML structure.
   - `static/landing.css`, `static/styles.css`, `static/landing.js`, and `static/script.js` provide page-specific styling and client-side behavior such as upload interactions, drag-and-drop, previews, and UI actions like copying results.

3. **Landing page as entry surface**
   - The landing page is a separate presentation surface, not just a reused section of the main tool.
   - It likely acts as a marketing/overview page that routes users into the OCR workflow, with supporting imagery stored under `static/images`.

4. **Main OCR workflow**
   - The main page is the application’s primary data-processing surface: users upload an image, optionally enable handwriting mode, and receive extracted text, detected language, and translated output.
   - This page is where the app’s central pipeline is exposed end to end.

5. **Backend orchestration in `app.py`**
   - `app.py` is the control plane of the system: it likely defines the Flask routes, accepts file uploads, invokes OCR, runs language detection, calls translation, and persists results.
   - In architecture terms, it is both the HTTP gateway and the workflow coordinator.

6. **OCR subsystem**
   - The OCR layer combines multiple engines: EasyOCR and PyTesseract, with PyOCR mentioned in the README as part of the stack.
   - This suggests a layered recognition strategy rather than a single engine dependency, with handwriting mode and fallback behavior forming an important internal boundary.

7. **Language detection and translation subsystem**
   - After OCR, extracted text flows into `langdetect` for language identification.
   - Translation is handled through `googletrans` / Google Translate API, enabling output into multiple target languages, including Indian and common global languages.
   - This is a distinct processing stage after text extraction, not part of the OCR engine itself.

8. **Persistence and records**
   - The app stores OCR and translation results in SQLite, which is a key architectural boundary because it turns the tool from a stateless processor into a history-bearing system.
   - `templates/records.html` is the readout surface for this storage layer, showing past OCR records and associated images.
   - `query.sql` likely contains the SQL used for schema creation or record retrieval, reinforcing that the database logic is separated from the Flask route code.

9. **Data flow**
   - Typical flow: user uploads image in browser → Flask receives the file → OCR engine extracts text → language detection identifies source language → translation service produces target text → record is written to SQLite → UI displays results and the records page can later read them back.
   - The database read path is separate from the live OCR path, which matters for diagramming request/response vs. historical retrieval.

10. **Operational dependencies**
   - The runtime depends on Python, Flask, EasyOCR, PyTesseract, PyTorch, OpenCV, langdetect, and googletrans.
   - The README also notes system-level Tesseract installation, which is important because OCR is not self-contained in the Python package layer.

11. **Repo artifacts vs runtime**
   - `SNAPSHOTS/` contains PDFs that document the UI and stored records; these are reference artifacts, not application components.
   - They are useful for understanding expected screens and outputs, but they do not participate in execution.

12. **Architecture summary for diagramming**
   - Draw the browser as the presentation boundary with three routes.
   - Place Flask/app.py as the central orchestrator.
   - Attach OCR engines, language detection, and translation as downstream processing services.
   - Show SQLite as the persistent store feeding the records page.
   - Treat static assets and templates as the UI layer, and `query.sql` as the database-query/schema companion to the backend.

Main entry points: [`app.py`](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/app.py) (Flask App), [`templates/landing.html`](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/landing.html) (Landing Page), [`templates/index.html`](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/index.html) (Main Page), [`templates/records.html`](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/records.html) (Records Page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Presentation"]
  node_browser(("Browser<br/>client"))
  node_landing_html["Landing Page<br/>template<br/>[landing.html]"]
  node_index_html["Main Page<br/>template<br/>[index.html]"]
  node_records_html["Records Page<br/>template<br/>[records.html]"]
  node_landing_assets["Landing Assets<br/>static asset<br/>[landing.css]"]
  node_landing_js["Landing JS<br/>client script<br/>[landing.js]"]
  node_main_js["Main JS<br/>client script<br/>[script.js]"]
  node_styles_css["App Styles<br/>stylesheet<br/>[styles.css]"]
end

subgraph group_backend["App Core"]
  node_app_py["Flask App<br/>controller<br/>[app.py]"]
end

subgraph group_processing["Text Pipeline"]
  node_ocr_pipeline{{"OCR Pipeline"}}
  node_easyocr["EasyOCR<br/>ocr engine"]
  node_pytesseract["PyTesseract<br/>ocr engine"]
  node_langdetect["Lang Detect<br/>language detection"]
  node_translator["Translator<br/>translation service"]
end

subgraph group_data["Storage"]
  node_query_sql["SQL Companion<br/>[query.sql]"]
  node_sqlite_db[("SQLite<br/>database")]
end

subgraph group_external["External"]
  node_flask["Flask<br/>web framework"]
  node_python_runtime["Python<br/>runtime"]
  node_opencv["OpenCV<br/>image processing"]
  node_tesseract_sys["Tesseract<br/>system dependency"]
end

node_browser -->|"opens"| node_landing_html
node_browser -->|"uses"| node_index_html
node_browser -->|"views"| node_records_html
node_landing_html -->|"uses"| node_landing_js
node_landing_html -->|"styles"| node_landing_assets
node_index_html -->|"uses"| node_main_js
node_index_html -->|"styles"| node_styles_css
node_records_html -->|"styles"| node_styles_css
node_browser -->|"requests"| node_app_py
node_app_py -->|"orchestrates"| node_ocr_pipeline
node_ocr_pipeline -->|"uses"| node_easyocr
node_ocr_pipeline -->|"uses"| node_pytesseract
node_ocr_pipeline -->|"preprocesses"| node_opencv
node_pytesseract -->|"depends on"| node_tesseract_sys
node_app_py -->|"detects"| node_langdetect
node_app_py -->|"translates"| node_translator
node_app_py -->|"stores"| node_sqlite_db
node_query_sql -->|"defines"| node_sqlite_db
node_records_html -->|"reads"| node_sqlite_db
node_app_py -->|"built on"| node_flask
node_app_py -->|"runs on"| node_python_runtime

click node_landing_html "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/landing.html"
click node_index_html "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/index.html"
click node_records_html "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/records.html"
click node_landing_assets "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/landing.css"
click node_app_py "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/app.py"
click node_query_sql "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/query.sql"
click node_landing_js "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/landing.js"
click node_main_js "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/script.js"
click node_styles_css "https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/styles.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser,node_landing_html,node_index_html,node_records_html,node_landing_assets,node_landing_js,node_main_js,node_styles_css toneBlue
class node_app_py toneAmber
class node_ocr_pipeline,node_easyocr,node_pytesseract,node_langdetect,node_translator toneMint
class node_query_sql,node_sqlite_db toneRose
class node_flask,node_python_runtime,node_opencv,node_tesseract_sys toneIndigo
```

## Components

### Presentation

Browser-facing pages, templates, and static assets.

- **Browser**: client · User entry point for landing, OCR, and records pages.
- [Landing Page](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/landing.html): template · HTML for the marketing/entry page. · `templates/landing.html`
- [Main Page](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/index.html): template · HTML for image upload, OCR, and translation workflow. · `templates/index.html`
- [Records Page](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/templates/records.html): template · HTML for browsing stored OCR history. · `templates/records.html`
- [Landing Assets](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/landing.css): static asset · CSS, JS, and images for the landing surface. · `static/landing.css`
- [Landing JS](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/landing.js): client script · Client-side interactions for the landing page. · `static/landing.js`
- [Main JS](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/script.js): client script · Upload, preview, copy, and other tool interactions. · `static/script.js`
- [App Styles](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/static/styles.css): stylesheet · Shared styling for the main application pages. · `static/styles.css`

### App Core

Flask control plane and request workflow.

- [Flask App](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/app.py): controller · HTTP routes, upload handling, workflow orchestration, and page rendering. · `app.py`

### Text Pipeline

OCR, language detection, and translation stages.

- **OCR Pipeline**: service · Extracts text from uploaded images, including handwriting support and engine fallback.
- **EasyOCR**: ocr engine · Primary OCR engine used by the text extraction pipeline.
- **PyTesseract**: ocr engine · Secondary OCR engine backed by system Tesseract.
- **Lang Detect**: language detection · Identifies the source language of extracted text.
- **Translator**: translation service · Produces translated output for the selected target language.

### Storage

Persistent record layer and SQL companion.

- [SQL Companion](https://github.com/moinshariff26/ocr-and-multilingual-translator/blob/main/query.sql): sql · Schema or query definitions used with record storage. · `query.sql`
- **SQLite**: database · Persistent store for OCR and translation history.

### External

Runtime and library dependencies outside the repo.

- **Flask**: web framework · Web server and routing framework for the application.
- **Python**: runtime · Execution runtime for the application and libraries.
- **OpenCV**: image processing · Image handling and preprocessing support for OCR.
- **Tesseract**: system dependency · System-level OCR binary required by PyTesseract.

## Connections

- Browser → Landing Page: opens · Loads the landing page.
- Browser → Main Page: uses · Accesses the main OCR workflow.
- Browser → Records Page: views · Opens stored OCR records.
- Landing Page → Landing JS: uses · Landing page behavior.
- Landing Page → Landing Assets: styles · Landing page styling and assets.
- Main Page → Main JS: uses · Upload and result interactions.
- Main Page → App Styles: styles · Shared application styling.
- Records Page → App Styles: styles · Shared application styling.
- Browser → Flask App: requests · Browser requests are handled by Flask routes.
- Flask App → OCR Pipeline: orchestrates · Coordinates image processing and text extraction.
- OCR Pipeline → EasyOCR: uses · Primary OCR engine.
- OCR Pipeline → PyTesseract: uses · Fallback or alternate OCR engine.
- OCR Pipeline → OpenCV: preprocesses · Image preparation before recognition.
- PyTesseract → Tesseract: depends on · Requires system Tesseract installation.
- Flask App → Lang Detect: detects · Identifies source language after OCR.
- Flask App → Translator: translates · Produces translated text output.
- Flask App → SQLite: stores · Persists OCR and translation records.
- SQL Companion → SQLite: defines · SQL companion for schema or queries.
- Records Page → SQLite: reads · Displays stored historical records.
- Flask App → Flask: built on · Application control plane uses Flask.
- Flask App → Python: runs on · Python execution environment.
