# advaitkj123/plagiarism_project_iai architecture

> Architecture diagram of the GitHub repository advaitkj123/plagiarism_project_iai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/advaitkj123/plagiarism_project_iai
- Repository: https://github.com/advaitkj123/plagiarism_project_iai

## Overview

#### Purpose and entry points
This is a local full-stack plagiarism-analysis tool for comparing submitted technical text against a small indexed library of `.txt` and `.pdf` documents. The Python service starts from `backend/app.py` (also supported by `run_server.bat`); the browser dashboard starts through Vite at `frontend/src/main.jsx`, rendering `frontend/src/App.jsx`.

#### Client dashboard
The React application provides the user workflow: submit or select manuscript content, manage library documents, invoke analysis, display sentence-level attribution and aggregate metrics, and print/export results. The UI is concentrated in:
- `frontend/src/main.jsx`
- `frontend/src/App.jsx`
- `frontend/src/App.css`

It communicates with the Flask API rather than performing similarity analysis locally.

#### HTTP/API boundary
Flask routes in `backend/app.py` form the application boundary between the browser and the analysis engine. This layer handles request parsing, CORS-enabled frontend access, file-oriented CRUD operations, and serializes analysis/report results. It also owns filesystem-facing interactions with the local corpus under `data/`.

#### Analysis engine
`backend/engine.py` is the core decision component. It extracts text from PDF or plain-text corpus entries, applies math/LaTeX-aware regular-expression cleanup, tokenizes content into sentences, and compares candidate sentences to library content using TF-IDF vectors and cosine similarity:
- `backend/engine.py`
- `backend/utils.py`

The output drives both per-sentence flags/source attribution and summary signals such as similarity averages and counts.

#### Corpus and document boundary
`data/` is the persistent, filesystem-backed research library; it is not a database or remote search service. Mixed source formats are supported, with PDFs requiring PyMuPDF extraction and text files read directly:
- `data/Assignment.pdf`
- `data/ieee_notes.txt`
- `data/test1.txt`

Uploads/additions and deletions pass through the API before becoming part of the corpus used by later analysis.

#### Primary flow
1. React collects submitted text or a file and requests analysis through Flask.
2. Flask delegates document loading and comparison to the engine.
3. The engine normalizes mathematical notation, sentence-splits the submission, builds/uses TF-IDF similarity comparisons against corpus text, and identifies threshold-exceeding overlaps.
4. Flask returns structured flags, source references, and aggregate metrics.
5. React renders results and relies on print CSS for browser-based PDF report export.

#### Runtime and dependencies
The backend runs on Python 3.11 with Flask, Flask-CORS, scikit-learn, NLTK, and PyMuPDF; dependency intent is represented by `requirements.txt`. The frontend runs on Node.js with React 18 and Vite, defined by `frontend/package.json`. There are no indicated cloud services, databases, authentication providers, or asynchronous job infrastructure; analysis is synchronous and local.

Main entry points: [`backend/app.py`](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/app.py) (Flask API), [`backend/engine.py`](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/engine.py) (Similarity engine), [`frontend/src/App.jsx`](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/App.jsx) (Analysis dashboard), [`requirements.txt`](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/requirements.txt) (Backend dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser dashboard"]
  node_vite["Vite client runtime<br/>Node.js / Vite<br/>[package.json]"]
  node_main["React entry point<br/>React bootstrap<br/>[main.jsx]"]
  node_app_ui["Analysis dashboard<br/>React UI<br/>[App.jsx]"]
  node_print_css["Print styling<br/>CSS<br/>[App.css]"]
end

subgraph group_backend["Python service"]
  node_flask_app{{"Flask API<br/>HTTP boundary<br/>[app.py]"}}
  node_analysis_engine["Similarity engine<br/>analysis core<br/>[engine.py]"]
  node_text_processing["Text normalization<br/>processing utilities<br/>[utils.py]"]
  node_pdf_extraction["PDF text extraction<br/>PyMuPDF"]
  node_tfidf["TF-IDF comparison<br/>scikit-learn"]
  node_python_deps["Backend dependencies<br/>Python 3.11 dependencies<br/>[requirements.txt]"]
end

subgraph group_corpus["Local corpus"]
  node_library[("Research library<br/>filesystem corpus")]
  node_assignment_pdf["Assignment PDF<br/>corpus document<br/>[Assignment.pdf]"]
  node_ieee_notes["IEEE notes<br/>corpus document<br/>[ieee_notes.txt]"]
  node_test_text["Test text<br/>corpus document<br/>[test1.txt]"]
end

node_vite -->|"starts"| node_main
node_main -->|"renders"| node_app_ui
node_app_ui -->|"uses"| node_print_css
node_app_ui -->|"analysis and library HTTP requests"| node_flask_app
node_flask_app -->|"delegates analysis"| node_analysis_engine
node_flask_app -->|"uploads, lists, and deletes files"| node_library
node_analysis_engine -->|"normalizes and splits text"| node_text_processing
node_analysis_engine -->|"builds vectors and scores similarity"| node_tfidf
node_analysis_engine -->|"loads comparison sources"| node_library
node_library -->|"contains"| node_assignment_pdf
node_library -->|"contains"| node_ieee_notes
node_library -->|"contains"| node_test_text
node_assignment_pdf -->|"text extracted by"| node_pdf_extraction
node_python_deps -.->|"provides runtime packages"| node_flask_app
node_python_deps -.->|"provides analysis packages"| node_analysis_engine
node_flask_app -->|"flags, sources, and metrics response"| node_app_ui

click node_vite "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/package.json"
click node_main "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/main.jsx"
click node_app_ui "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/App.jsx"
click node_print_css "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/App.css"
click node_flask_app "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/app.py"
click node_analysis_engine "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/engine.py"
click node_text_processing "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/utils.py"
click node_python_deps "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/requirements.txt"
click node_assignment_pdf "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/data/Assignment.pdf"
click node_ieee_notes "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/data/ieee_notes.txt"
click node_test_text "https://github.com/advaitkj123/plagiarism_project_iai/blob/main/data/test1.txt"

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_vite,node_main,node_app_ui,node_print_css toneBlue
class node_flask_app,node_analysis_engine,node_text_processing,node_pdf_extraction,node_tfidf,node_python_deps toneAmber
class node_library,node_assignment_pdf,node_ieee_notes,node_test_text toneMint
```

## Components

### Browser dashboard

- [Vite client runtime](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/package.json): Node.js / Vite · `frontend/package.json`
- [React entry point](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/main.jsx): React bootstrap · `frontend/src/main.jsx`
- [Analysis dashboard](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/App.jsx): React UI · Submission, library management, results, and report export. · `frontend/src/App.jsx`
- [Print styling](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/frontend/src/App.css): CSS · Supports browser print/PDF report export. · `frontend/src/App.css`

### Python service

- [Flask API](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/app.py): HTTP boundary · Parses requests, enables CORS, manages corpus files, and serializes results. · `backend/app.py`
- [Similarity engine](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/engine.py): analysis core · Produces sentence attribution, flags, and aggregate similarity metrics. · `backend/engine.py`
- [Text normalization](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/backend/utils.py): processing utilities · Math/LaTex-aware cleanup and sentence tokenization. · `backend/utils.py`
- **PDF text extraction**: PyMuPDF
- **TF-IDF comparison**: scikit-learn · Cosine similarity identifies threshold-exceeding overlaps.
- [Backend dependencies](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/requirements.txt): Python 3.11 dependencies · Flask, Flask-CORS, scikit-learn, NLTK, and PyMuPDF. · `requirements.txt`

### Local corpus

- **Research library**: filesystem corpus · Persistent mixed PDF and text source documents.
- [Assignment PDF](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/data/Assignment.pdf): corpus document · `data/Assignment.pdf`
- [IEEE notes](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/data/ieee_notes.txt): corpus document · `data/ieee_notes.txt`
- [Test text](https://github.com/advaitkj123/plagiarism_project_iai/blob/main/data/test1.txt): corpus document · `data/test1.txt`

## Connections

- Vite client runtime → React entry point: starts
- React entry point → Analysis dashboard: renders
- Analysis dashboard → Print styling: uses
- Analysis dashboard → Flask API: analysis and library HTTP requests
- Flask API → Similarity engine: delegates analysis
- Flask API → Research library: uploads, lists, and deletes files
- Similarity engine → Text normalization: normalizes and splits text
- Similarity engine → TF-IDF comparison: builds vectors and scores similarity
- Similarity engine → Research library: loads comparison sources
- Research library → Assignment PDF: contains
- Research library → IEEE notes: contains
- Research library → Test text: contains
- Assignment PDF → PDF text extraction: text extracted by
- Backend dependencies → Flask API: provides runtime packages
- Backend dependencies → Similarity engine: provides analysis packages
- Flask API → Analysis dashboard: flags, sources, and metrics response
