# regnrok/autograder architecture

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

- Interactive diagram: https://gitdiagram.com/regnrok/autograder
- Repository: https://github.com/regnrok/autograder

## Overview

##### Project type and purpose
- This is a full‑stack web application (“Automatic Paper Checker”) whose goal is to let instructors upload scanned or photographed handwritten student papers alongside teacher answer sheets, run OCR + NLP + CV pipelines on the backend, then return text, sentiment, and similarity scores back to a React web UI.
- Key indicators: you have a React “frontend” directory with public + src, and a Python “backend” folder plus Jupyter notebooks for development. The README calls out Flask REST API, PyTesseract, OpenCV, spaCy, and NLTK.

##### File structure
- Top‑level Jupyter notebooks (Character_Recognition_Model.ipynb, Complete_Model.ipynb, etc.) capture your model development and testing stages.
- The “backend” folder holds the Flask app (App.py), OCR modules (recog.py), answer‑checker (checkanswer.py), and helper scripts.
- The “frontend” directory is a standard create‑react‑app scaffold: public/ holds index.html, manifest, static assets; src/ contains components, pages, assets, and main App.js, index.js.
- requirements.txt at the root defines Python dependencies; package.json under frontend lists Node deps.

##### README for additional insights
- The README spells out the four major processing stages: Image Preprocessing → OCR Extraction → NLP Analysis (sentiment + semantic similarity) → Result Generation.
- It confirms tech stack: React UI calls Flask REST endpoints; Flask code invokes PyTesseract, OpenCV, spaCy, and NLTK.

a. Main components:
- User’s Web Browser (UI)
- React Frontend
- Flask Backend (REST API)
- Image Preprocessing Module (OpenCV)
- OCR Module (PyTesseract)
- NLP Module (spaCy + NLTK)
- Jupyter Notebooks (dev environment—not part of runtime but can be shown as “development”)
- External Dependencies (Tesseract‑OCR engine, spaCy language model, NLTK lexicons)
b. Relationships & interactions:
1. User uploads files via React → HTTP POST multipart/form-data to Flask endpoint (/upload).
2. Backend receives images → passes to Preprocessing → outputs cleaned images.
3. Preprocessed images → OCR module → raw text output.
4. Raw text → NLP module:
- spaCy for tokenization + semantic similarity
- NLTK VADER for sentiment
5. Backend aggregates: extracted text, sentiment scores, similarity metrics → JSON response.
6. Frontend receives JSON → updates UI components (result panels, charts).
c. Architectural patterns/design principles:
- Three‑tier architecture: Presentation (React), Application (Flask), Data/Compute (CV + OCR + NLP modules).
- Single monolithic backend service (Flask) orchestrating sequential pipelines.
- Separation of concerns: React handles UI; Flask handles routing + business logic; dedicated Python modules encapsulate CV/OCR/NLP.
d. Technologies & libraries:
- Frontend: React, npm, create‑react‑app structure (public/, src/Components, src/Pages).
- Backend: Python 3.8+, Flask, modules in backend/*.py.
- OCR: PyTesseract + Tesseract‑OCR external binary.
- CV: OpenCV‑Python.
- NLP: spaCy (en_core_web_sm), NLTK (VADER).
- Dev/Testing: Jupyter notebooks for rapid prototyping.

##### Capturing essential architectural elements
- Keep it detailed enough so any new engineer can understand where image data enters, how it’s transformed, and where outputs appear.
- Avoid over‑simplification: separate OCR vs. NLP vs. CV even if they run in the same process.
- Future enhancement points (e.g., “add LMS integration here”).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["Web Browser"]:::ui
        subgraph "React Frontend"
            AppJs["App.js"]:::ui
            IndexJs["index.js"]:::ui
            Components["Components/"]:::ui
            Pages["Pages/"]:::ui
            Public["public/"]:::ui
        end
    end

    %% Server Layer
    subgraph "Server Layer"
        FlaskApp["App.py"]:::app
        ReqTxt["requirements.txt"]:::app
        subgraph "Node Config"
            PackageJSON["package.json"]:::app
        end
    end

    %% Compute Modules
    subgraph "Compute Modules"
        Preprocess["Image Preprocessing<br/>(OpenCV)"]:::pipeline
        OCR["OCR Module<br/>(PyTesseract)"]:::pipeline
        NLP["NLP Module<br/>(spaCy + NLTK)"]:::pipeline
    end

    %% Development
    subgraph "Jupyter Notebooks (Dev)" 
        CR["Character_Recognition_Model.ipynb"]:::dev
        CM["Complete_Model.ipynb"]:::dev
        PM["Prediction_Model.ipynb"]:::dev
        WM["Working_Model.ipynb"]:::dev
    end

    %% External Dependencies
    subgraph "External Dependencies"
        TESS["Tesseract-OCR Engine"]:::external
        SPACY["spaCy Model"]:::external
        NLTK["NLTK Lexicons"]:::external
    end

    %% Flow
    Browser --> ReactFront["React Frontend"]:::ui
    ReactFront -->|HTTP POST /upload| FlaskApp
    FlaskApp --> Preprocess
    Preprocess --> OCR
    OCR --> NLP
    NLP --> FlaskApp
    FlaskApp -->|JSON response| ReactFront
    ReactFront --> Browser

    %% External integrations
    OCR --> TESS
    NLP --> SPACY
    NLP --> NLTK

    %% Dev prototypes feed modules
    CR --> Preprocess
    CM --> OCR
    PM --> NLP
    WM --> NLP

    %% Click events
    click AppJs "https://github.com/regnrok/autograder/blob/main/frontend/src/App.js"
    click IndexJs "https://github.com/regnrok/autograder/blob/main/frontend/src/index.js"
    click Components "https://github.com/regnrok/autograder/tree/main/frontend/src/Components/"
    click Pages "https://github.com/regnrok/autograder/tree/main/frontend/src/Pages/"
    click Public "https://github.com/regnrok/autograder/tree/main/frontend/public/"
    click FlaskApp "https://github.com/regnrok/autograder/blob/main/backend/App.py"
    click ReqTxt "https://github.com/regnrok/autograder/blob/main/requirements.txt"
    click PackageJSON "https://github.com/regnrok/autograder/blob/main/frontend/package.json"
    click Preprocess "https://github.com/regnrok/autograder/blob/main/backend/recog.py"
    click OCR "https://github.com/regnrok/autograder/blob/main/backend/recog.py"
    click NLP "https://github.com/regnrok/autograder/blob/main/backend/checkanswer.py"
    click CR "https://github.com/regnrok/autograder/blob/main/Character_Recognition_Model.ipynb"
    click CM "https://github.com/regnrok/autograder/blob/main/Complete_Model.ipynb"
    click PM "https://github.com/regnrok/autograder/blob/main/Prediction_Model.ipynb"
    click WM "https://github.com/regnrok/autograder/blob/main/Working_Model.ipynb"

    %% Styles
    classDef ui fill:#CCE5FF,stroke:#004085
    classDef app fill:#D4EDDA,stroke:#155724
    classDef pipeline fill:#FFF3CD,stroke:#856404
    classDef external fill:#E2E3E5,stroke:#41464B
    classDef dev fill:#F8D7DA,stroke:#721C24
```
