
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.
"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.
⚠️ 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
| Technology | Purpose |
|---|---|
| HTML5 / CSS3 | UI structure and styling |
| Vanilla JavaScript | SPA routing and API calls |
| Vercel | Hosting and deployment |
| 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) |
| Technology | Purpose |
|---|---|
| In-Memory Cache | Temporary report storage |
| GitHub Actions | CI/CD pipeline |
| Nginx | Reverse proxy |
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 │ │
│ └─────────────────┘ │
└─────────────────────────┘
Source Code A / B
┌───────┴───────┐
▼ ▼
[Raw Code] [Tokenizer]
│ │
│ ├──────────────────────┐
▼ ▼ ▼
[ASTBuilder] [CodeNormalizer] [StatementGrouper]
│ │ │
▼ ▼ ▼
[ASTComparator] [Winnowing] [LcsEngine]
│ │ │
▼ ▼ ▼
AST Score Jaccard & Coverage LCS Score
│ │ │
└───────────────┼──────────────────────┘
▼
[Hybrid Score]
| Clone Type | Description | Detected |
|---|---|---|
| Type 1 | Exact copy | ✅ |
| Type 2 | Renamed identifiers | ✅ |
| Type 3 | Added/removed statements | ✅ |
| Type 4 | Semantic similarity |
- Java 17+
- Maven 3.9+
# Clone the repository
git clone https://github.com/Kunal-htr/codesniff.git
# Navigate to project
cd codesniff
# Install dependencies
mvn clean installCreate src/main/resources/application.properties:
server.port=9090mvn spring-boot:runOpen http://localhost:9090 in your browser.
POST /api/analyze
Content-Type: application/jsonRequest 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 /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
}
}GET /api/healthCodeSniff is alive!
CodeSniff v2.0 introduces strict input validation and centralized exception handling. Requests are validated using Jakarta Bean Validation before reaching the analysis engine.
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.
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
}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
git push to main
│
▼
GitHub Actions triggers
│
▼
Maven build + test
│
▼
Deploy to Azure App Service
│
▼
Live in ~50 seconds ✅
| Metric | Value |
|---|---|
| Average response time | ~200ms |
| Max file size | 1MB |
| Supported languages | All text-based |
| Concurrent comparisons | Multiple pairs |
| 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 |
This project is licensed under the MIT License.
- Spring Boot
- Vercel
- Azure
- Winnowing Algorithm — Schleimer, Wilkerson, Aiken (2003)