# vikasprajapati-01/plagiarism_check_tool architecture

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

- Interactive diagram: https://gitdiagram.com/vikasprajapati-01/plagiarism_check_tool
- Repository: https://github.com/vikasprajapati-01/plagiarism_check_tool

## Overview

#### Purpose and Entry Points
This is a dataset-quality system for Excel/CSV files: it identifies duplicate, semantically similar, AI-generated, web-plagiarized, and license-restricted content, then produces JSON and Excel outputs. The backend FastAPI application starts at `backend/app/main.py`; versioned REST routes are assembled in `backend/app/api/v1/router.py`. The primary user interface is the Next.js analyzer at `frontend/app/analyze/page.tsx`.

#### API and Client Boundary
The frontend uploads files and selected detection methods to the Python API, using `NEXT_PUBLIC_API_BASE`. It can first request column discovery, then run the unified pipeline, preview its result, and request downloadable reports/cleaned workbooks. Primary API surfaces are:
- `backend/app/api/v1/pipeline.py` — column discovery and pipeline execution.
- `backend/app/api/v1/reports.py` — combined and cleaned Excel exports.
- `backend/app/api/v1/compare.py` — standalone cross-workbook comparison/export.

#### Ingestion and Provenance
The preprocessing stage reads CSV/XLSX files, selects a requested or auto-detected target column, normalizes content, and emits per-cell entries retaining file, sheet, row, and column provenance. That traceability is the boundary between raw workbooks and detector services, and enables later row deletion/report highlighting.
- `backend/app/services/preprocessor.py`
- `backend/app/core/models.py`

#### Unified Detection Orchestration
`pipeline_runner` coordinates only the methods requested by the API, executes detectors in memory, aggregates findings into a `PipelineRunResult`, and separates row/cell duplicate findings from web/AI findings. Cross-file comparison is conditional on XLSX inputs.
- `backend/app/services/pipeline_runner.py`
- `backend/app/api/v1/pipeline.py`
- `backend/app/services/cross_compare.py`

#### Similarity Detection Stages
Duplicate detection is layered: SHA-256 catches identical content; fuzzy matching evaluates lexical near-matches; semantic matching embeds text and compares cosine similarity. Thresholds and model names are environment-backed application settings rather than frontend-controlled implementation details.
- `backend/app/services/exact_match.py`
- `backend/app/services/fuzzy_match.py`
- `backend/app/services/semantic_match.py`
- `backend/app/core/config.py`

#### ML, Web, and Compliance Boundaries
Semantic matching uses SBERT and AI scoring uses GPT-2 perplexity. Both models are loaded once through a startup-oriented singleton cache, avoiding repeated model initialization per request. Web scanning is an external-network boundary: DuckDuckGo discovers candidate sources, then HTTP/BeautifulSoup retrieves and compares page text under timeout/retry limits. License analysis recognizes SPDX/copyright signals.
- `backend/app/core/model_cache.py`
- `backend/app/services/ai_detector.py`
- `backend/app/services/web_scanner.py`
- `backend/app/services/license_detector.py`

#### Reporting and Remediation
Report endpoints convert pipeline results into a three-sheet, optionally color-coded Excel workbook. The cleaned-workbook flow receives original XLSX uploads plus result JSON, removes flagged duplicate/plagiarized rows while preserving headers, and returns one workbook or a ZIP for multiple files. This is a post-processing boundary: original files are needed again because pipeline results are structured findings, not persisted workbook mutations.
- `backend/app/api/v1/reports.py`
- `frontend/app/components/PreviewPanel.tsx`

#### Runtime and Infrastructure
Backend runtime is Python/FastAPI with pandas/openpyxl for workbook I/O, sentence-transformers/transformers for local ML inference, and DuckDuckGo plus remote HTTP sites for web checks. Frontend runtime is Next.js 16/React 19 TypeScript using the App Router. Models may be pre-fetched with `backend/scripts/download_models.py`; no database, queue, or cloud deployment infrastructure is represented in this repository.

Main entry points: [`backend/app/services/pipeline_runner.py`](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/pipeline_runner.py) (Pipeline runner), [`backend/app/api/v1/router.py`](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/router.py) (v1 route assembly), [`backend/app/api/v1/pipeline.py`](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/pipeline.py) (Pipeline API), [`backend/app/api/v1/reports.py`](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/reports.py) (Reports API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js client"]
  node_analyzer_ui["Analyzer UI<br/>Next.js page<br/>[page.tsx]"]
  node_preview_ui["Results preview<br/>React component<br/>[PreviewPanel.tsx]"]
end

subgraph group_api["FastAPI API"]
  node_app["FastAPI app<br/>application entry<br/>[main.py]"]
  node_v1_router["v1 route assembly<br/>API router<br/>[router.py]"]
  node_pipeline_api["Pipeline API<br/>REST routes<br/>[pipeline.py]"]
  node_reports_api["Reports API<br/>REST routes<br/>[reports.py]"]
  node_compare_api["Comparison API<br/>REST routes<br/>[compare.py]"]
end

subgraph group_pipeline["Detection pipeline"]
  node_preprocessor["Workbook preprocessing<br/>ingestion service<br/>[preprocessor.py]"]
  node_models["Provenance models<br/>domain models<br/>[models.py]"]
  node_runner["Pipeline runner<br/>orchestrator<br/>[pipeline_runner.py]"]
  node_exact["Exact matching<br/>SHA-256 detector<br/>[exact_match.py]"]
  node_fuzzy["Fuzzy matching<br/>lexical detector<br/>[fuzzy_match.py]"]
  node_semantic["Semantic matching<br/>SBERT detector<br/>[semantic_match.py]"]
  node_cross_compare["Cross-workbook comparison<br/>XLSX comparison service<br/>[cross_compare.py]"]
  node_ai_detector["AI content scoring<br/>GPT-2 detector<br/>[ai_detector.py]"]
  node_web_scanner["Web plagiarism scan<br/>network detector<br/>[web_scanner.py]"]
  node_license["License analysis<br/>compliance detector"]
  node_model_cache["Model cache<br/>startup singleton<br/>[model_cache.py]"]
  node_settings["Detection settings<br/>application settings<br/>[config.py]"]
end

subgraph group_external["External services"]
  node_web{{"Search and web sources<br/>external network"}}
end

node_analyzer_ui -->|"uploads files and methods"| node_pipeline_api
node_analyzer_ui -->|"requests exports"| node_reports_api
node_analyzer_ui -->|"requests comparison"| node_compare_api
node_pipeline_api -->|"runs pipeline"| node_runner
node_pipeline_api -->|"discovers columns"| node_preprocessor
node_runner -->|"ingests cells"| node_preprocessor
node_preprocessor -->|"emits provenance entries"| node_models
node_runner -->|"requested method"| node_exact
node_runner -->|"requested method"| node_fuzzy
node_runner -->|"requested method"| node_semantic
node_runner -->|"requested method"| node_ai_detector
node_runner -->|"requested method"| node_web_scanner
node_runner -->|"requested method"| node_license
node_runner -.->|"XLSX only"| node_cross_compare
node_semantic -->|"uses SBERT"| node_model_cache
node_ai_detector -->|"uses GPT-2"| node_model_cache
node_settings -.->|"thresholds"| node_fuzzy
node_settings -.->|"thresholds and model"| node_semantic
node_web_scanner -->|"searches and fetches"| node_web
node_reports_api -->|"reads result JSON"| node_models
node_reports_api -->|"returns workbooks"| node_preview_ui
node_app -->|"mounts"| node_v1_router
node_v1_router -->|"registers"| node_pipeline_api
node_v1_router -->|"registers"| node_reports_api
node_v1_router -->|"registers"| node_compare_api

click node_analyzer_ui "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/frontend/app/analyze/page.tsx"
click node_preview_ui "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/frontend/app/components/PreviewPanel.tsx"
click node_app "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/main.py"
click node_v1_router "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/router.py"
click node_pipeline_api "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/pipeline.py"
click node_reports_api "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/reports.py"
click node_compare_api "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/compare.py"
click node_preprocessor "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/preprocessor.py"
click node_models "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/core/models.py"
click node_runner "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/pipeline_runner.py"
click node_exact "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/exact_match.py"
click node_fuzzy "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/fuzzy_match.py"
click node_semantic "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/semantic_match.py"
click node_cross_compare "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/cross_compare.py"
click node_ai_detector "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/ai_detector.py"
click node_web_scanner "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/web_scanner.py"
click node_license "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/license_detector.py"
click node_model_cache "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/core/model_cache.py"
click node_settings "https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/core/config.py"

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_analyzer_ui,node_preview_ui toneBlue
class node_app,node_v1_router,node_pipeline_api,node_reports_api,node_compare_api toneAmber
class node_preprocessor,node_models,node_runner,node_exact,node_fuzzy,node_semantic,node_cross_compare,node_ai_detector,node_web_scanner,node_license,node_model_cache,node_settings toneMint
class node_web toneRose
```

## Components

### Next.js client

- [Analyzer UI](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/frontend/app/analyze/page.tsx): Next.js page · Uploads workbooks, selects methods, and requests results. · `frontend/app/analyze/page.tsx`
- [Results preview](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/frontend/app/components/PreviewPanel.tsx): React component · Previews findings and initiates report downloads. · `frontend/app/components/PreviewPanel.tsx`

### FastAPI API

- [FastAPI app](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/main.py): application entry · `backend/app/main.py`
- [v1 route assembly](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/router.py): API router · `backend/app/api/v1/router.py`
- [Pipeline API](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/pipeline.py): REST routes · Discovers columns and runs requested detection methods. · `backend/app/api/v1/pipeline.py`
- [Reports API](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/reports.py): REST routes · Exports result reports and cleaned workbooks. · `backend/app/api/v1/reports.py`
- [Comparison API](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/api/v1/compare.py): REST routes · Runs standalone cross-workbook comparison and export. · `backend/app/api/v1/compare.py`

### Detection pipeline

- [Workbook preprocessing](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/preprocessor.py): ingestion service · Reads CSV/XLSX, selects a column, normalizes cells, and preserves provenance. · `backend/app/services/preprocessor.py`
- [Provenance models](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/core/models.py): domain models · Defines per-cell entries and pipeline result structures. · `backend/app/core/models.py`
- [Pipeline runner](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/pipeline_runner.py): orchestrator · Executes requested detectors in memory and aggregates findings. · `backend/app/services/pipeline_runner.py`
- [Exact matching](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/exact_match.py): SHA-256 detector · `backend/app/services/exact_match.py`
- [Fuzzy matching](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/fuzzy_match.py): lexical detector · `backend/app/services/fuzzy_match.py`
- [Semantic matching](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/semantic_match.py): SBERT detector · `backend/app/services/semantic_match.py`
- [Cross-workbook comparison](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/cross_compare.py): XLSX comparison service · Runs conditionally for XLSX inputs. · `backend/app/services/cross_compare.py`
- [AI content scoring](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/ai_detector.py): GPT-2 detector · `backend/app/services/ai_detector.py`
- [Web plagiarism scan](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/web_scanner.py): network detector · Searches candidate sources and compares retrieved page text. · `backend/app/services/web_scanner.py`
- [License analysis](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/services/license_detector.py): compliance detector · Recognizes SPDX and copyright signals. · `backend/app/services/license_detector.py`
- [Model cache](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/core/model_cache.py): startup singleton · Loads SBERT and GPT-2 once per backend runtime. · `backend/app/core/model_cache.py`
- [Detection settings](https://github.com/vikasprajapati-01/plagiarism_check_tool/blob/main/backend/app/core/config.py): application settings · Supplies environment-backed thresholds and model names. · `backend/app/core/config.py`

### External services

- **Search and web sources**: external network · DuckDuckGo and remote HTTP pages.

## Connections

- Analyzer UI → Pipeline API: uploads files and methods
- Analyzer UI → Reports API: requests exports
- Analyzer UI → Comparison API: requests comparison
- Pipeline API → Pipeline runner: runs pipeline
- Pipeline API → Workbook preprocessing: discovers columns
- Pipeline runner → Workbook preprocessing: ingests cells
- Workbook preprocessing → Provenance models: emits provenance entries
- Pipeline runner → Exact matching: requested method
- Pipeline runner → Fuzzy matching: requested method
- Pipeline runner → Semantic matching: requested method
- Pipeline runner → AI content scoring: requested method
- Pipeline runner → Web plagiarism scan: requested method
- Pipeline runner → License analysis: requested method
- Pipeline runner → Cross-workbook comparison: XLSX only
- Semantic matching → Model cache: uses SBERT
- AI content scoring → Model cache: uses GPT-2
- Detection settings → Fuzzy matching: thresholds
- Detection settings → Semantic matching: thresholds and model
- Web plagiarism scan → Search and web sources: searches and fetches
- Reports API → Provenance models: reads result JSON
- Reports API → Results preview: returns workbooks
- FastAPI app → v1 route assembly: mounts
- v1 route assembly → Pipeline API: registers
- v1 route assembly → Reports API: registers
- v1 route assembly → Comparison API: registers
