# dohabenhabbach/auto-correct-nlp-flask architecture

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

- Interactive diagram: https://gitdiagram.com/dohabenhabbach/auto-correct-nlp-flask
- Repository: https://github.com/dohabenhabbach/auto-correct-nlp-flask

## Overview

##### Project Type and Purpose
- This is a lightweight full-stack web application (Python + Flask) whose sole feature is suggesting word corrections based on a text corpus (shakespeare.txt).
- Frontend: HTML templates (Jinja2) served by Flask.
- Backend: Flask application (app.py) orchestrating HTTP routes, invoking NLP logic (main.py), and rendering templates.
- Data store: static text corpus loaded from shakespeare.txt (no external database).

##### Main Components
a. Client (Browser/User) – submits words via HTML form
b. Flask Web Server – processes HTTP requests
- Routing Layer (app.py)
- Business Logic Module (main.py)
- Corpus Loader (reads shakespeare.txt)
c. Templates/UI Layer – home.html (input), correction.html (output)
d. Data Source – flat text file (shakespeare.txt)
e. Python Runtime Environment – system dependency
f. Optional: Jupyter Notebook (Auto-Correct.ipynb) for experimentation (can be shown as a side artifact)

##### Relationships & Data Flows
- User → (HTTP POST) → Flask Route ("/correct")
- Flask Route → Business Logic (main.py functions) → Corpus Loader → computes suggestions
- Business Logic → passes suggestion list → Template Renderer
- Template Renderer → (HTTP Response) → Client

##### Key Architectural Patterns and Principles
- MVC-like separation: Templates = View, app.py = Controller, main.py + corpus = Model
- Single-process synchronous flow (no background workers/microservices)
- Stateless per‐request handling (reload corpus at startup or cache in memory)

##### Technologies & Frameworks
- Python 3.x
- Flask (micro web framework)
- Jinja2 (templating engine, implicit in Flask)
- Standard libraries: collections, re for NLP
- No external databases or message queues

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Browser["Browser / User"]:::client

    %% Backend Container
    subgraph "Backend"
        direction TB
        RoutingLayer["Flask Route (app.py)"]:::own
        BusinessLogic["Business Logic (main.py)"]:::own
        TemplateRenderer["Template Renderer (Jinja2)"]:::own

        subgraph "Templates / UI Layer"
            direction TB
            Home["home.html"]:::own
            Correction["correction.html"]:::own
        end
    end

    %% Data Source
    DataSource["Corpus (shakespeare.txt)"]:::data

    %% Dev / Experiment
    DevNotebook["Dev Notebook (Auto-Correct.ipynb)"]:::dev
    Readme["Documentation (README.md)"]:::dev

    %% Flows
    Browser -->|"POST /correct?word=…"| RoutingLayer
    RoutingLayer -->|"invoke correction()"| BusinessLogic
    BusinessLogic -->|"load corpus"| DataSource
    BusinessLogic -->|"return suggestions"| TemplateRenderer
    TemplateRenderer -->|"render HTML"| Browser

    %% Template Usage
    TemplateRenderer --> Home
    TemplateRenderer --> Correction

    %% Click Events
    click Browser "https://github.com/dohabenhabbach/auto-correct-nlp-flask/tree/main/n/a"
    click RoutingLayer "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/app.py"
    click BusinessLogic "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/main.py"
    click DataSource "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/shakespeare.txt"
    click Home "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/templates/home.html"
    click Correction "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/templates/correction.html"
    click Templates "https://github.com/dohabenhabbach/auto-correct-nlp-flask/tree/main/templates/"
    click DevNotebook "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/Auto-Correct.ipynb"
    click Readme "https://github.com/dohabenhabbach/auto-correct-nlp-flask/blob/main/README.md"

    %% Styles
    classDef own fill:#a2faa3,stroke:#333,stroke-width:1px
    classDef data fill:#87ceeb,stroke:#333,stroke-width:1px
    classDef client fill:#f9d5a7,stroke:#333,stroke-width:1px
    classDef dev fill:#d3d3d3,stroke:#333,stroke-width:1px
```
