# zayuvalya/ai-text-humanizer architecture

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

- Interactive diagram: https://gitdiagram.com/zayuvalya/ai-text-humanizer
- Repository: https://github.com/zayuvalya/ai-text-humanizer

## Overview

##### Project Type and Purpose
- This is a frontend‐only, single‐page web application that runs entirely in the browser without any server component.
- Its purpose is to take user-supplied text, run a context-aware paraphrasing algorithm on it, and render a “humanized” version with highlighted changes, while also showing word/sentence counts.

##### High‐Level Architecture Overview
Break the system into three logical layers:
a. Presentation Layer (UI)
- index.html: Defines the input area, buttons, and output container.
- styles.css: Implements dark theme and responsive layout.
b. Application Logic Layer (Paraphrasing Engine)
- script.js: Contains modules for tokenization, classification, replacement, highlighting, and counters.
c. Data Layer (Resources)
- eng_synonyms.json: Vocabulary of words → synonyms.
- stop_words.json: List of unchangeable common words.
- fixedterms.json (or inline array): Fixed terms that must remain intact.

##### Main Components and Their Interactions
1. User Interface Component
- "Paraphrase" Button
- Output Display Area with highlighted spans
- Word/Sentence Counter Display
2. Tokenizer Module
- Splits text into tokens: words, whitespace, punctuation.
3. Classifier Module
- isStopWord(token)
- isFixedTerm(token)
- isProperNoun(token)
4. Replacement Module
- replaceWord(token) looks up synonyms in eng_synonyms.json
5. Highlighting Module
- Wraps replaced words in `…`
6. Counter Module
- countWords(text)
- countSentences(text)
7. Data Resources
- JSON loaders for vocabulary and stop words at initialization

Data flow:
User Input → Tokenizer → Classifier → Replacement → Highlighter → Render Output → Counter updates

##### Architectural Patterns and Principles
- Separation of Concerns: UI vs. logic vs. data
- Data-driven design: JSON files drive algorithm behavior
- Modular JavaScript: encapsulate classification, replacement, and counting into distinct functions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer (UI)
    subgraph "Presentation Layer" 
        direction TB
        UI_HTML["index.html"]:::ui
        UI_CSS["styles.css"]:::ui
        UI_HTML -->|"loads UI elements"| UI_CSS
    end

    %% Application Logic Layer (Paraphrasing Engine)
    subgraph "Paraphrasing Engine" 
        direction TB
        Tokenizer["Tokenizer<br/>tokenize()"]:::logic
        Classifier["Classifier<br/>isStopWord(), isFixedTerm(), isProperNoun()"]:::logic
        Replacement["Replacement<br/>replaceWord()"]:::logic
        Highlighter["Highlighter<br/>wrapSpan()"]:::logic
        Counter["Counter<br/>countWords(), countSentences()"]:::logic
    end

    %% Data Layer (Resources)
    subgraph "Data Layer" 
        direction TB
        Synonyms["eng_synonyms.json"]:::data
        StopWords["stop_words.json"]:::data
        FixedTerms["fixedterms.json"]:::data
    end

    %% UI to Engine interactions
    UI_HTML -->|"onClick Paraphrase"| Tokenizer
    Tokenizer -->|"tokens[]"| Classifier
    Classifier -->|"classified tokens"| Replacement
    Replacement -->|"replaced tokens"| Highlighter
    Highlighter -->|"rendered HTML"| UI_HTML
    Highlighter -->|"updates text"| UI_HTML
    Counter -->|"counts"| UI_HTML

    %% Engine to Data interactions
    Tokenizer -->|"initialization load"| Synonyms
    Tokenizer -->|"initialization load"| StopWords
    Tokenizer -->|"initialization load"| FixedTerms
    Replacement -->|"keyword lookup"| Synonyms
    Classifier -->|"stopword lookup"| StopWords
    Classifier -->|"fixedterm lookup"| FixedTerms

    %% Counter triggered after rendering
    Highlighter -->|"final text"| Counter

    %% Click Events
    click UI_HTML "https://github.com/zayuvalya/ai-text-humanizer/blob/main/index.html"
    click UI_CSS "https://github.com/zayuvalya/ai-text-humanizer/blob/main/styles.css"
    click Tokenizer "https://github.com/zayuvalya/ai-text-humanizer/blob/main/script.js"
    click Classifier "https://github.com/zayuvalya/ai-text-humanizer/blob/main/script.js"
    click Replacement "https://github.com/zayuvalya/ai-text-humanizer/blob/main/script.js"
    click Highlighter "https://github.com/zayuvalya/ai-text-humanizer/blob/main/script.js"
    click Counter "https://github.com/zayuvalya/ai-text-humanizer/blob/main/script.js"
    click Synonyms "https://github.com/zayuvalya/ai-text-humanizer/blob/main/eng_synonyms.json"
    click StopWords "https://github.com/zayuvalya/ai-text-humanizer/blob/main/stop_words.json"
    click FixedTerms "https://github.com/zayuvalya/ai-text-humanizer/blob/main/fixedterms.json"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef logic fill:#90EE90,stroke:#333,stroke-width:1px;
    classDef data fill:#FFD580,stroke:#333,stroke-width:1px;
```
