Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Plagiarism Detection Tool

A comprehensive full-stack plagiarism detection tool for large codebases that uses AST analysis, token-based similarity, and semantic embeddings to detect code plagiarism.

Features

Backend (FastAPI)

  • Multiple Input Sources: GitHub repository URLs, file uploads, and ZIP file uploads
  • Advanced Code Analysis: AST parsing and code normalization for multiple languages
  • Similarity Detection:
    • Jaccard similarity for token-based comparison
    • Semantic similarity using HuggingFace all-MiniLM-L6-v2 embeddings
    • FAISS vector storage for efficient similarity search
  • Comprehensive Results: File-to-file and function-to-function similarity analysis
  • RESTful API: Clean API endpoints for all operations

Frontend (Next.js + NextUI)

  • Modern UI: Beautiful, responsive interface with NextUI components
  • Multiple Analysis Methods: GitHub repo analysis and file upload
  • Interactive Results: Sortable table with similarity scores and visual indicators
  • Detailed Comparison: Diff viewer with highlighted similar lines and functions
  • Filtering & Sorting: Advanced filtering by similarity threshold and sorting options
  • PDF Export: Generate comprehensive PDF reports
  • Real-time Updates: Live progress tracking during analysis

Supported Languages

  • Python (.py)
  • JavaScript (.js)
  • TypeScript (.ts)
  • Java (.java)
  • C/C++ (.c, .cpp, .h, .hpp)
  • C# (.cs)
  • Go (.go)
  • Rust (.rs)
  • PHP (.php)
  • Ruby (.rb)
  • Swift (.swift)
  • Kotlin (.kt)
  • And more...

Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 18+
  • Git

Local Development Flow

The current workflow is to run the backend and frontend directly from their own folders in separate terminals.

Backend

  1. Open a terminal in the backend folder:
cd backend
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Start the API server:
uvicorn main:app --reload

The API will be available at http://localhost:8000.

Frontend

  1. Open a second terminal in the frontend folder:
cd frontend
  1. Install dependencies:
npm install
  1. Start the Next.js dev server:
npm run dev

The frontend will be available at http://localhost:3000

Usage

1. GitHub Repository Analysis

  1. Open the web interface at http://localhost:3000
  2. Select the "GitHub Repo" tab
  3. Enter a GitHub repository URL
  4. Click "Analyze Repository"
  5. Wait for the analysis to complete
  6. View results in the interactive table

2. File Upload Analysis

  1. Select the "Upload Files" tab
  2. Drag and drop code files or click to select
  3. Alternatively, upload a ZIP file containing code
  4. Click "Upload & Analyze Files"
  5. View results and export PDF reports

3. Understanding Results

  • Overall Similarity: Combined score from token and semantic similarity
  • Token Similarity: Jaccard similarity based on code tokens
  • Semantic Similarity: AI-powered similarity using embeddings
  • Similar Functions: Matching functions between files
  • Similar Code Blocks: Identical or near-identical code sections

4. Exporting Reports

Click the "Export PDF" button to generate a comprehensive report including:

  • Summary statistics
  • Detailed similarity analysis
  • Similar functions and code blocks
  • Visual similarity indicators

API Endpoints

Analysis Endpoints

  • POST /analyze/github - Analyze GitHub repository
  • POST /analyze/upload - Analyze uploaded files
  • POST /analyze/zip - Analyze ZIP file

Results Endpoints

  • GET /analysis/{analysis_id} - Get analysis status and results
  • GET /analysis/{analysis_id}/similarities - Get filtered similarity results
  • DELETE /analysis/{analysis_id} - Delete analysis results

Architecture

Backend Architecture

backend/
├── main.py                 # FastAPI application
├── models/
│   └── similarity_result.py # Data models
├── services/
│   ├── code_analyzer.py    # AST parsing and code analysis
│   ├── embedding_service.py # Semantic similarity using embeddings
│   └── similarity_engine.py # Similarity computation engine
├── utils/
│   └── file_utils.py       # File handling utilities
└── requirements.txt        # Python dependencies

Frontend Architecture

frontend/
├── app/
│   ├── layout.tsx          # Root layout
│   ├── page.tsx            # Main page
│   ├── providers.tsx       # NextUI providers
│   └── globals.css         # Global styles
├── components/
│   ├── FileUpload.tsx      # File upload component
│   ├── ResultsTable.tsx    # Results display table
│   └── DiffViewer.tsx      # Detailed comparison viewer
├── utils/
│   └── pdfGenerator.ts     # PDF report generation
└── package.json            # Node.js dependencies

Technical Details

Similarity Algorithms

  1. Jaccard Similarity: Token-based similarity using set intersection
  2. Semantic Similarity: HuggingFace sentence transformers for code understanding
  3. Combined Score: Weighted average (30% Jaccard + 70% Semantic)

Performance Optimizations

  • FAISS Index: Efficient vector similarity search
  • Background Processing: Non-blocking analysis for large codebases
  • Caching: Embedding caching to avoid recomputation
  • Parallel Processing: Concurrent file analysis

Security Features

  • CORS Protection: Configured for local development
  • File Validation: Type checking for uploaded files
  • Error Handling: Comprehensive error handling and user feedback

Development

Building for Production

# Backend
cd backend
pip install -r requirements.txt
uvicorn main:app --host 0.0.0.0 --port 8000

# Frontend
cd frontend
npm run build
npm start

Troubleshooting

Common Issues

  1. Port Already in Use: Change ports in the respective configuration files
  2. Memory Issues: Reduce batch sizes for large repositories
  3. Model Download: First run may take time to download the embedding model

Performance Tips

  • Use smaller repositories for initial testing
  • Monitor memory usage during analysis
  • Consider using GPU acceleration for large-scale analysis

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License. See LICENSE for the full text.

Note: This tool is designed for educational and legitimate plagiarism detection purposes. Always respect intellectual property rights and use responsibly.

About

Robust similarity detection combining AST normalization, token comparison, and embedding search to find similar files and functions across repos or uploaded code. Easy local dev (uvicorn + Next.js) and exportable reports.

Resources

Stars

Watchers

Forks

Packages

Contributors

Languages