# hrishikeshrt/chanda architecture

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

- Interactive diagram: https://gitdiagram.com/hrishikeshrt/chanda
- Repository: https://github.com/hrishikeshrt/chanda

## Overview

##### Project type and purpose
- This is a full-stack web application (Flask) that identifies Sanskrit meters from text or images (via OCR), displays scan­sions in a friendly UI, and supports batch processing & evaluation.

##### File structure
- webapp.py (Flask entry point / controller)
- chanda.py + data/*.csv + data/examples.json (core “model” – meter rules and examples)
- templates/*.html (views – Jinja2 templates)
- static/ (frontend assets: Bootstrap, FontAwesome, custom CSS/JS)
- experiments/ (evaluation scripts & output – optional analytics module)
- settings.sample.py / settings.py (configuration)
- requirements.txt (dependencies)

##### README for additional insights
- Confirms Flask-based web UI, OCR support (Google Cloud OCR or Tesseract), fuzzy matching, batch processing.
- No external database – uses CSV files and JSON for meter definitions.
- Two OCR subsystems: an external Google OCR service and a local Tesseract binary.

##### Main components & their relationships
A. Client / Browser (frontend)
– Loads HTML/CSS/JS from static/ and templates/
– Sends HTTP requests to Flask routes in webapp.py

B. Web Server / Application Layer (Flask)
– webapp.py defines routes for:
- Single-line or file uploads (text, image)
- Selecting output scheme
- Feedback, examples, help pages
– Acts as Controller in MVC

C. Core Meter Engine (chanda.py + data/)
– Implements scansion logic, fuzzy matching, CSV-driven meter definitions
– Provides an API to webapp.py to identify meter patterns

D. OCR Subsystem
– Google Cloud OCR (external REST API)
– Tesseract OCR (local process invocation)
– Called by webapp.py when image input is provided

E. Templates & Static Assets
– Jinja2 templates for rendering views
– CSS/JS assets (Bootstrap, FontAwesome, custom) to drive UI behaviors

F. Experiments & Evaluation (optional module)
– scripts under experiments/evaluation/ for batch evaluation against gold standards
– Not in request path; used offline for metrics

##### Architectural patterns & design principles
- MVC (Flask webapp.py = Controller, chanda.py = Model, templates = View)
- Layered design: presentation layer (templates/static), application logic (Flask), domain logic (meter engine), external services (OCR)
- Configuration-driven: settings.py toggles OCR backends, logging, etc.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Layer"
        Browser["Client Browser"]:::frontend
    end

    subgraph "Presentation Layer"
        Templates["templates/"]:::frontend
        Static["static/"]:::frontend
    end

    Browser -->|HTTP Requests| Flask
    Browser -->|Loads assets| Templates
    Browser -->|Loads assets| Static

    subgraph "Application Layer"
        Flask["Flask (webapp.py)"]:::pythonApp
        Settings["Configuration (settings.sample.py)"]:::config
    end

    Templates -->|Rendered by| Flask
    Static -->|Served by| Flask
    Settings -->|Configures| Flask

    Flask -->|calls| Engine

    subgraph "Domain Layer"
        Engine["Meter Engine (chanda.py)"]:::engine
        subgraph DataStore
            CSV1["chanda_ardhasama.csv"]:::data
            CSV2["chanda_jaati.csv"]:::data
            CSV3["chanda_matra.csv"]:::data
            CSV4["chanda_sama.csv"]:::data
            CSV5["chanda_vishama.csv"]:::data
            JSON["examples.json"]:::data
        end
    end

    Engine --> DataStore

    Flask -->|OCR Image Input| OCRGOOGLE
    Flask -->|OCR Image Input| OCRTESS

    subgraph "OCR Subsystem"
        OCRGOOGLE["Google Cloud OCR"]:::external
        OCRTESS["Tesseract CLI"]:::external
    end

    OCRGOOGLE -->|Text Output| Engine
    OCRTESS -->|Text Output| Engine

    subgraph "Offline Analytics Module"
        ExperimentsDir["experiments/evaluation/"]:::offline
        Test1["test_chandojnanam.py"]:::offline
        Test2["test_functions.py"]:::offline
        Test3["test_shreevatsa.py"]:::offline
        Test4["test_skrutable.py"]:::offline
        ExperimentsDir --> Test1
        ExperimentsDir --> Test2
        ExperimentsDir --> Test3
        ExperimentsDir --> Test4
    end

    subgraph "Dependencies"
        Reqs["requirements.txt"]:::deps
    end

    classDef frontend fill:#dfefff,stroke:#333,stroke-width:1px
    classDef pythonApp fill:#d4f0d4,stroke:#333,stroke-width:1px
    classDef engine fill:#b8e6b8,stroke:#333,stroke-width:1px
    classDef data fill:#fce6b8,stroke:#333,stroke-width:1px
    classDef external fill:#b8d4fc,stroke:#333,stroke-width:1px
    classDef config fill:#fcf3b8,stroke:#333,stroke-width:1px
    classDef offline fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef deps fill:#dddddd,stroke:#333,stroke-width:1px

    click Templates "https://github.com/hrishikeshrt/chanda/tree/master/templates/"
    click Static "https://github.com/hrishikeshrt/chanda/tree/master/static/"
    click Flask "https://github.com/hrishikeshrt/chanda/blob/master/webapp.py"
    click Settings "https://github.com/hrishikeshrt/chanda/blob/master/settings.sample.py"
    click Engine "https://github.com/hrishikeshrt/chanda/blob/master/chanda.py"
    click CSV1 "https://github.com/hrishikeshrt/chanda/blob/master/data/chanda_ardhasama.csv"
    click CSV2 "https://github.com/hrishikeshrt/chanda/blob/master/data/chanda_jaati.csv"
    click CSV3 "https://github.com/hrishikeshrt/chanda/blob/master/data/chanda_matra.csv"
    click CSV4 "https://github.com/hrishikeshrt/chanda/blob/master/data/chanda_sama.csv"
    click CSV5 "https://github.com/hrishikeshrt/chanda/blob/master/data/chanda_vishama.csv"
    click JSON "https://github.com/hrishikeshrt/chanda/blob/master/data/examples.json"
    click ExperimentsDir "https://github.com/hrishikeshrt/chanda/tree/master/experiments/evaluation/"
    click Test1 "https://github.com/hrishikeshrt/chanda/blob/master/experiments/evaluation/test_chandojnanam.py"
    click Test2 "https://github.com/hrishikeshrt/chanda/blob/master/experiments/evaluation/test_functions.py"
    click Test3 "https://github.com/hrishikeshrt/chanda/blob/master/experiments/evaluation/test_shreevatsa.py"
    click Test4 "https://github.com/hrishikeshrt/chanda/blob/master/experiments/evaluation/test_skrutable.py"
    click Reqs "https://github.com/hrishikeshrt/chanda/blob/master/requirements.txt"
```
