Skip to content

Latest commit

 

History

History
234 lines (180 loc) · 12.2 KB

README.md

File metadata and controls

234 lines (180 loc) · 12.2 KB

🛡️ CLASSGUARD

Smart Attendance & Multi-Layer Classroom Verification Platform

Next.js 14 TypeScript Prisma ORM Tailwind CSS License: MIT

"Attendance, verified."
An enterprise-grade, zero-trust attendance ecosystem that eliminates proxy attendance, screenshot sharing, replay attacks, and academic attendance fraud using dynamic cryptographic QR codes and a 7-layer server-side verification engine.

Live Demo Links • Architecture • 7-Layer Security • Gamification • Quickstart


📌 Problem Statement

Traditional university and college attendance methods suffer from severe vulnerabilities:

  • ❌ Paper Sign-in Sheets: Easily signed by friends ("proxy attendance").
  • ❌ Static QR Codes: Students photograph the QR code and send it over WhatsApp/Telegram to absent peers who scan from home.
  • ❌ RFID / Smart Cards: Students hand their physical ID cards to friends to swipe for them.
  • ❌ Manual Roll Calls: Consume 10–15 minutes of lecture time and are prone to human logging errors.

💡 The ClassGuard Solution

ClassGuard treats attendance verification as a zero-trust cryptographic challenge:

  1. Classroom TV Display Mode: Displays an animated, high-contrast dynamic QR code generated with session-specific HMAC-SHA256 signatures rotating every 12–30 seconds.
  2. Instant Web-Camera Scanning: Students scan the live TV screen from their mobile devices.
  3. 7-Layer Fraud Verification Pipeline: Validates student identity, active enrollment, single-use cryptographic nonces, time window, physical proximity, and detects multi-account device anomalies.
  4. Real-Time Faculty Command Center: Instructors watch their live attendance roster stream updates in real-time via Server-Sent Events (SSE).
  5. Competitive Gamified Leaderboard: Boosts student punctuality with ClassGuard Scores, consecutive streaks, and automatic 75% minimum semester threshold alerts.

🏗️ Architecture & Data Flow

                               ┌────────────────────────────────────────┐
                               │       Classroom TV Display (/classroom)│
                               │  - Dynamic Rotating QR (HMAC-SHA256)   │
                               │  - Live Verified Counter (Privacy-safe)│
                               └──────────────────┬─────────────────────┘
                                                  │ Realtime SSE Stream
                                                  ▼
┌───────────────────────┐             ┌────────────────────────────────┐
│ Student Mobile PWA    │             │ ClassGuard Core Backend Engine  │
│ - Instant Camera Scan │────────────▶│ - Route Handlers / REST API    │
│ - Device Fingerprint  │ Attendance  │ - 7-Layer Fraud & Risk Engine  │
│ - Campus Proximity    │ Verification│ - Cryptographic HMAC Validator │
└───────────────────────┘ Request     │ - Prisma Relational ORM        │
                                      └────────────────┬───────────────┘
┌───────────────────────┐                              │
│ Teacher Live Command  │◀─────────────────────────────┘ Realtime Updates
│ - Live Student Roster │ (SSE Broadcast: Verified, Late, Suspicious)
│ - Manual Override/Log │
│ - CSV / Excel Export  │
└───────────────────────┘

🛡️ The 7-Layer Anti-Proxy Verification Engine

When a student scans the classroom display QR, the backend evaluates 7 independent layers to compute an authoritative Risk Score (0–100):

Layer Verification Signal Mechanism & Defense
Layer 1 Authentication & Enrollment Validates signed JWT session and queries course enrollments to ensure the student is actively registered for the subject.
Layer 2 Session State & Classroom Match Verifies the session is currently ACTIVE (not paused or ended) and matches the physical classroom.
Layer 3 Dynamic HMAC QR & Replay Prevention Verifies HMAC-SHA256 signature generated with the session's secret seed. Enforces short expiration windows and burns nonces in database transactions to prevent replay attacks.
Layer 4 Temporal Attendance Window Validates server timestamp against teacher-configured attendance window (e.g. first 15 mins). Marks late if submitted during grace period.
Layer 5 Classroom BLE Proximity (Configurable) Evaluates classroom Bluetooth beacon UUID or cryptographic proximity signal to ensure in-room presence.
Layer 6 Institutional Campus Network Checks client IP against authorized classroom Wi-Fi subnets (e.g. 10.142.254.x).
Layer 7 Device Anomaly & Multi-Account Detection Detects when 2+ student accounts submit attendance from the same physical device within 15 minutes (friend proxying) or rapid device switching (+50 penalty).

🏆 Gamification & 75% Semester Threshold Tracker

ClassGuard transforms mundane attendance into a motivating, competitive experience:

1. 📊 75% Mandatory Attendance Safeguard

  • Automatic Requirement Calculator: Under each subject, students receive real-time notifications:
    • 🔴 ⚠ Need 3 more classes to reach 75% threshold (Prevents exam debarment)
    • 🟢 ✓ Safe — can miss 2 classes
  • Configurable institutional thresholds (e.g., 75% warning, 85% healthy standing).

2. 🥇 ClassGuard Score & Leaderboard

  • Score Formula: ClassGuard Score = (Attendance % × 70%) + (Streak Bonus × 30% max)
  • Achievement Badges:
    • 🔥 On Fire: 3+ consecutive sessions attended
    • ⭐ Perfect Attendance: 100% attendance rate
    • ⚡ Punctual: 90%+ on-time arrival rate
    • 📚 Scholar: 85%+ semester attendance
  • Real-time podium ranking (🥇🥈🥉) viewable across the college.

🌐 Live Platform Modules & URLs

Role / View Route Description
🏠 Home Portal / Central launchpad directory with quick access to all modules
🔑 Persona Login /login 1-click persona switcher (Abel, Adnan, Savan, Dr. Alan Turing, Admin)
📱 Mobile Scanner /student/scan Instant camera scanner with automatic token auto-detection
🎓 Student Dashboard /student Subject-wise breakdown, 75% attendance calculator & timetable
🏆 Class Leaderboard /leaderboard Real-time semester rankings, podium cards & achievement badges
📜 Attendance History /student/history Immutable log of all past attendance records & verification methods
📅 Timetable /student/timetable Weekly timetable schedule
📺 Classroom Display TV /classroom/lab-2-demo Fullscreen dynamic QR code (auto-rotates) + live counter
👨‍🏫 Teacher Live Tracker /teacher/session/[id] Real-time SSE command center with live roster & manual overrides
📋 Teacher Dashboard /teacher Start new attendance sessions, schedule classes & view past logs
⚙️ Admin Control Panel /admin College-wide analytics, audit trail logs, CSV imports & policies

🗄️ Relational Database Schema (Prisma)

The application uses a normalized relational schema with full foreign keys, cascade safety, and optimized indexes:

  • User: Identity model (id, email, passwordHash, role, firstName, lastName, phone, isActive)
  • StudentProfile: Student details (rollNumber, admissionYear, departmentId, currentSemester)
  • TeacherProfile: Faculty details (employeeCode, departmentId, designation)
  • Department: Academic departments (name, code, description)
  • Subject: Courses (name, code, semester, credits, departmentId)
  • Classroom: Physical rooms (name, building, roomNumber, capacity, beaconUuid, wifiSubnet)
  • Enrollment: Student-course mappings (studentId, subjectId, academicYear, semester, status)
  • AttendanceSession: Active/past class sessions (subjectId, teacherId, classroomId, status, secretSeed)
  • AttendanceRecord: Attendance logs (sessionId, studentId, status, markedAt, riskScore, deviceFingerprint)
  • QrToken: Single-use nonces burned upon scan for replay protection (sessionId, nonce, expiresAt)
  • VerificationEvent: Diagnostic log storing passed rules, failed rules, and risk factors
  • ManualOverrideAudit: Immutable audit log of faculty corrections (recordId, actorId, reason, timestamp)
  • Device: Device fingerprint registry and trusted hardware association
  • SystemSetting: Configurable thresholds (HEALTHY_THRESHOLD, WARNING_THRESHOLD)

🚀 Quickstart Guide

Prerequisites

  • Node.js v18+ (tested on v20 and v24)
  • npm or yarn

1. Clone & Install

git clone https://github.com/your-username/classguard.git
cd classguard
npm install

2. Environment Setup

cp .env.example .env

3. Initialize Database & Seed Pilot Data

# Push schema to SQLite database
npx prisma db push

# Seed demo students (Abel Bosco, Adnan Samwr, Savan Santhosh) & active Lab 2 session
node scripts/seed.js

4. Run the Application

Option A: Standard Development Mode

npm run dev
# Open http://localhost:3000

Option B: Mobile Camera HTTPS Mode (Local Wi-Fi Testing)

node server.js
# Access from mobile phones on same Wi-Fi via https://<YOUR-LOCAL-IP>:3000

5. Default Credentials

|team no: 19| | Name | | Abel Bosco | | Adnan Sameer | | Savan Santhosh |

(You can also use the 1-click persona switcher on the /login page).


🧪 Automated Testing

Run the automated cryptographic and fraud engine test suites:

npm run test

Includes tests for:

  • ✅ HMAC-SHA256 dynamic token creation & signature validation
  • ✅ Nonce expiration & single-use replay protection
  • ✅ 7-layer verification risk scoring
  • ✅ Multi-account proxy anomaly detection

📦 Tech Stack

  • Framework: Next.js 14 (App Router, Server Actions, API Route Handlers)
  • Language: TypeScript
  • Database ORM: Prisma (SQLite default, ready for PostgreSQL / MySQL)
  • Real-Time Engine: Server-Sent Events (SSE) via EventEmitter bus
  • Styling: Tailwind CSS + Lucide Icons
  • Cryptography: node:crypto HMAC-SHA256, jose JWTs, scrypt hashing
  • QR Engine: qrcode, html5-qrcode, BarcodeDetector API
  • Testing: Vitest

📄 License

This project is licensed under the MIT License — see the LICENSE file for details.


Built for Hackathons & Higher Education Innovation
ClassGuard © 2024–2026. All rights reserved.