Skip to content

Repository files navigation

version java spring boot license status

{CodeSniff} Logo
CodeSniff | Hybrid Code Similarity Analyzer
Detect Java source code clones and structural plagiarism instantly. By leveraging AST-aware hybrid scoring, LCS alignment, and tokenized K-gram Winnowing, CodeSniff uncovers Type 1–4 clones even when logic is heavily disguised.

Live Demo · Report Bug · Request Feature


About

"In a world where code is copied, CodeSniff sees what eyes can't."

CodeSniff is a token-based code similarity analyzer designed to detect plagiarism in Java source files. It uses the K-gram fingerprinting technique combined with the Winnowing algorithm the same approach used by Stanford's MOSS system to identify copied code even when variable names are changed, comments are removed, or statements are reordered.

Currently supporting Java with plans to expand to Python, C++, JavaScript and more in future releases through AI-powered semantic analysis.


🚀 Features

⚠️ Current Version (v2.0): Supports Java source files only. Multi-language support planned for future releases.

  • 🔍 Token-based similarity detection using K-gram algorithm
  • 🪟 Winnowing algorithm for efficient fingerprint selection
  • 🌳 AST Structural Comparison via compiler-level parsing (JavaParser)
  • 📜 LCS Statement Alignment for flow-level similarity checks
  • Java source file upload and pairwise comparison
  • 💻 Direct code paste for quick Java code analysis
  • 📊 Similarity percentage results table and detailed visual report
  • ⚙️ Configurable options — K-gram size, window size, ignore comments
  • ☁️ Cloud Persistence & History tracking for authenticated users
  • 🌐 Fully deployed on cloud infrastructure

🛠️ Tech Stack

Frontend

Technology Purpose
HTML5 / CSS3 UI structure and styling
Vanilla JavaScript SPA routing and API calls
Vercel Hosting and deployment

Backend

Technology Purpose
Java 17 Core language
Spring Boot 3.3.5 REST API framework
Maven Build and dependency management
Azure App Service F1 Cloud hosting (24/7)

Database & Infrastructure

Technology Purpose
In-Memory Cache Temporary report storage
GitHub Actions CI/CD pipeline
Nginx Reverse proxy

🏗️ System Architecture

User Browser
     │
     ▼
┌─────────────────┐
│  Vercel          │  codesniff.tech
│  (Frontend)      │  HTML + CSS + JS
└────────┬────────┘
         │ API calls
         ▼
┌─────────────────────────┐
│  Azure App Service F1    │  codesniff-backend.azurewebsites.net
│  Spring Boot Backend     │
│  ┌─────────────────┐    │
│  │AnalyzeController│    │
│  └────────┬────────┘    │
│           │              │
│  ┌────────▼────────┐    │
│  │SimilarityEngine  │    │
│  └────────┬────────┘    │
│           │              │
│  ┌────────▼────────┐    │
│  │Tokenizer         │    │
│  └────────┬────────┘    │
│           │              │
│  ┌────────▼────────┐    │
│  │CodeNormalizer    │    │
│  └─────────────────┘    │
└─────────────────────────┘

🔬 Detection Pipeline

                            Source Code A / B
                             ┌───────┴───────┐
                             ▼               ▼
                        [Raw Code]      [Tokenizer]
                             │               │
                             │               ├──────────────────────┐
                             ▼               ▼                      ▼
                        [ASTBuilder]   [CodeNormalizer]     [StatementGrouper]
                             │               │                      │
                             ▼               ▼                      ▼
                       [ASTComparator]  [Winnowing]            [LcsEngine]
                             │               │                      │
                             ▼               ▼                      ▼
                         AST Score      Jaccard & Coverage      LCS Score
                             │               │                      │
                             └───────────────┼──────────────────────┘
                                             ▼
                                      [Hybrid Score]

📦 Clone Types Detected

Clone Type Description Detected
Type 1 Exact copy
Type 2 Renamed identifiers
Type 3 Added/removed statements
Type 4 Semantic similarity ⚠️ Partial

🚀 Getting Started

Prerequisites

  • Java 17+
  • Maven 3.9+

Installation

# Clone the repository
git clone https://github.com/Kunal-htr/codesniff.git

# Navigate to project
cd codesniff

# Install dependencies
mvn clean install

Configuration

Create src/main/resources/application.properties:

server.port=9090

Run Locally

mvn spring-boot:run

Open http://localhost:9090 in your browser.


🔌 API Reference

Analyze Code Similarity (JSON)

POST /api/analyze
Content-Type: application/json

Request Body:

{
  "submissions": [
    { "name": "A.java", "content": "public class A { int sum(int[] a){int s=0;for(int i=0;i<a.length;i++){s+=a[i];}return s;} }" },
    { "name": "B.java", "content": "public class B { int total(int[] d){int t=0;for(int j=0;j<d.length;j++){t+=d[j];}return t;} }" }
  ],
  "options": {
    "omitComments": true,
    "k": 6,
    "window": 4
  }
}

Response:

{
  "summary": [
    {
      "a": "A.java",
      "b": "B.java",
      "score": 1.0,
      "jaccard": 1.0,
      "coverage": 1.0,
      "reportId": "d741ca12-a16f-40c2-9ee6-4e59f427ee0e"
    }
  ]
}

Get Detailed Pairwise Report

GET /api/report/{id}

Response:

{
  "nameA": "A.java",
  "nameB": "B.java",
  "jaccard": 1.0,
  "coverage": 1.0,
  "lcs": 1.0,
  "ast": 1.0,
  "hybrid": 1.0,
  "verdict": "High",
  "verdictDescription": "High similarity detected. There is a high probability of direct copy/paste or minimal rewriting.",
  "operatorDivergent": false,
  "metadata": {
    "k": 6,
    "window": 4,
    "omitComments": true,
    "fingerprintMatchCount": 15,
    "fingerprintCountA": 15,
    "fingerprintCountB": 15
  }
}

Health Check

GET /api/health
CodeSniff is alive!

🛡️ Input Validation & Error Handling

CodeSniff v2.0 introduces strict input validation and centralized exception handling. Requests are validated using Jakarta Bean Validation before reaching the analysis engine.

Constraints:

  • submissions: Must have between 1 and 200 files per batch.
  • name & content: Must not be blank.
  • k: Must be between 3 and 64.
  • window: Must be between 1 and 128.

Error Response Format (ApiErrorDTO):

When a validation constraint is violated, or a report ID is not found, the API returns a structured error object instead of raw stack traces:

{
  "error": "Bad Request",
  "message": "Validation failed: submissions[0].content: Submission content must not be blank",
  "status": 400,
  "timestamp": 1784260000000
}

📁 Project Structure

codesniff/
├── src/
│   └── main/
│       ├── java/
│       │   └── backend/
│       │       ├── App.java                 # Spring Boot entry point
│       │       ├── common/                  # Global exceptions, DTOs & utilities
│       │       ├── config/                  # Security, CORS & Rate Limiting configs
│       │       └── modules/                 # Domain-driven architecture modules
│       │           ├── report/              # Batch generation, PDF/CSV exports
│       │           ├── similarity/          # Core AST matching & Winnowing engine
│       │           └── user/                # Authentication, JWT & Profile management
│       └── resources/
│           ├── db/migration/                # Flyway SQL migrations
│           └── application.properties       # Spring Boot config
├── frontend/                                # Frontend UI (Vercel deployment)
│   ├── index.html                           # Main UI
│   ├── app.js                               # Frontend logic & routing
│   └── style.css                            # Styling
├── test_samples/                            # Standard plagiarism test samples
├── Dockerfile                               # Container config
└── pom.xml                                  # Maven config

🔄 CI/CD Pipeline

git push to main
      │
      ▼
GitHub Actions triggers
      │
      ▼
Maven build + test
      │
      ▼
Deploy to Azure App Service
      │
      ▼
Live in ~50 seconds ✅

📊 Performance

Metric Value
Average response time ~200ms
Max file size 1MB
Supported languages All text-based
Concurrent comparisons Multiple pairs

📦 Modules

Module Name Status Version
Module 1 Similarity Engine ✅ Complete v0.5
Module 2 Report & Visualization ✅ Complete v1.0
Module 3 Authentication and Security ✅ Complete v1.5
Module 4 Database & Storage Integration ✅ Complete v2.0
Module 5 Future AI Integration 🔄 Planned v2.5

📄 License

This project is licensed under the MIT License.


🙏 Acknowledgements


About

Hybrid code similarity analyzer, detect Java source code clones and structural plagiarism instantly. By leveraging AST-aware hybrid scoring, LCS alignment, and tokenized K-gram Winnowing, CodeSniff uncovers Type 1–4 clones even when logic is heavily disguised.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages