README
ΒΆ
ScholarMaster Engine
Real-time, privacy-preserving intelligent campus monitoring system for educational institutions
Version: 2.1.0 (Event-Driven Architecture)
License: Proprietary
Maintainer: Narendra P (@NarendraaP)
What is ScholarMaster?
ScholarMaster is an edge-based campus monitoring system that combines biometric identification, timetable-driven compliance checking, privacy-preserving behavior analytics, and immutable audit logging into a single integrated platform. It solves the problem of institution-scale intelligence (100k+ identities) while maintaining privacy-first design (no image retention, only spectral audio features, volatile memory processing).
The system runs on edge hardware (M2 Mac, Raspberry Pi) and provides real-time detection of:
- Truancy (students in wrong locations based on timetable)
- Noise violations (context-aware: strict during lectures, relaxed during breaks)
- Safety concerns (prolonged sleep, violence detection)
- Attendance (automated, non-repudiable via blockchain-style audit)
All actions are logged to a tamper-evident Merkle tree, and access is controlled via role-based permissions (7 roles: Super Admin, Admin/HOD, Faculty, Class Teacher, Students, Security, Non-Teaching).
System Architecture
ScholarMaster implements Hybrid Onion Architecture with Event-Driven Orchestration:
βββββββββββββββββββββββββββββββββββββββββββ
β main_event_driven.py (Orchestrator) β β Thin coordinator
βββββββββββββββ¬ββββββββββββββββββββββββββββ
β
ββββ APPLICATION LAYER (Use Cases)
β β’ DetectTruancyUseCase
β β’ MarkAttendanceUseCase
β β’ EventHandlers (pub/sub)
β
ββββ DOMAIN LAYER (Pure Logic)
β β’ ComplianceRules (ST-CSF)
β β’ AlertRules (context-aware)
β β’ ZERO infrastructure deps
β
ββββ INTERFACES (Contracts)
β β’ IFaceRecognizer
β β’ IAudioAnalyzer
β β’ IScheduleRepository
β β’ IAlertService
β
ββββ INFRASTRUCTURE (Adapters)
β’ FaceRecognizer (InsightFace+FAISS)
β’ AudioAnalyzer (Spectral FFT)
β’ Repositories (CSV, JSON)
β’ AuditLog (Merkle chain)
Why This Structure?
- Testability: Domain rules can be unit-tested without database, camera, or microphone
- Safety: Business logic (compliance, alerts) is isolated from hardware failures
- Research Integrity: Each layer maps to specific research papers (see below)
- Extensibility: Swap implementations (e.g., PostgreSQL instead of JSON) without changing logic
- Dependency Inversion: Application depends on interfaces, not concrete implementations
Why There Are THREE Main Files
You'll notice three executable entry points:
1. main.py (formerly main_unified.py) β RECOMMENDED FOR PRODUCTION
- What: The robust, fully integrated system engine
- When: Use for deployment (Paper 11) and defense
- Why: References all correct modules (P1-P11) verified in the audit
- LOC: 400+ lines
- Status: β Freeze-Ready, Audited
2. main_refactored.py β CONSERVATIVE ALTERNATIVE
- What: Onion Architecture without event bus
- When: Use if event-driven feels aggressive or hard to debug
- Why: Explicit Onion layers, but direct method calls (no pub/sub)
- LOC: 467 lines (44% smaller than original)
- Pattern: Dependency injection with use cases
- Status: β Stable, less complex than event-driven
3. main_unified_backup.py β LEGACY / PAPER REPRODUCIBILITY
- What: Original monolithic implementation
- When: Use ONLY for reproducing research paper experiments
- Why: Preserves exact logic from publications (Papers 1-10)
- LOC: 834 lines (original)
- Pattern: Monolithic, embedded business logic
- Status: β Preserved for backward compatibility, NOT for new work
Rule of Thumb: Start with main_event_driven.py. If you need to debug event flow, temporarily switch to main_refactored.py. Never delete main_unified_backup.py (research integrity).
System Roles & Permissions
ScholarMaster implements a 7-layer RBAC (Role-Based Access Control) hierarchy:
Implemented Roles
| Role | Privileges | Data Scope | Typical Actions |
|---|---|---|---|
| Super Admin | System-wide control | All departments | Create users, modify timetables, audit access |
| Admin / HOD | Department management | Own department | Manage faculty, approve leave, department reports |
| Faculty | Teacher functions | Assigned subjects | Mark attendance, override alerts, view class analytics |
| Class Teacher | Class-specific | Own class (year+section) | Student welfare, attendance review, parent communication |
| Students | Self-service | Own records | View attendance, check timetable, appeal violations |
| Security | Safety monitoring | Campus-wide (alerts only) | Respond to safety alerts, view live violations |
| Non-Teaching | Limited ops | Facility-specific | Lab access logs, library monitoring |
RBAC Boundaries (IMPORTANT)
- Department Scoping: Admins can ONLY see their own department's data (e.g., CS HOD cannot see Mech records)
- Year/Section Scoping: Class Teachers limited to specific cohort (e.g., "Year 3, Section A")
- Timetable-Driven: Permissions change dynamically (Faculty can edit attendance ONLY during their scheduled class)
- Audit Trail: All actions logged with role+timestamp (immutable, see
data/audit_log.db)
Why Timetable is Central
The timetable (data/timetable.csv) is NOT just a scheduleβit's the ground truth for:
- Compliance: Determines where students SHOULD be (ST-CSF spatiotemporal logic)
- Context: Lecture mode (strict) vs break mode (relaxed) noise thresholds
- Attendance: Marks are valid ONLY during scheduled class time
- Teacher Absence: Alerts if no Faculty present in a scheduled session
- Authorization: Faculty can modify attendance ONLY for their assigned subject
DO NOT manually edit timetable without understanding cascading effects on compliance, alerts, and attendance.
Key System Features (Mapped to Code)
1. Timetable Auto-Generation
- File:
modules_legacy/scheduler.py(AutoScheduler class) - Logic: Backtracking solver for conflict-free scheduling
- Output:
data/timetable.csv(7-column CSV: dept, program, year, section, day, start, end, subject, teacher, room) - Papers: Not published (infrastructure only)
2. Attendance & Compliance
- Files:
core/application/use_cases/detect_truancy_use_case.py(compliance logic)modules_legacy/attendance_logger.py(logging, RBAC enforcement)
- Logic:
- If
current_location == expected_locationβ Compliant, mark attendance - Else β Truancy violation, trigger alert
- If
- Debounce: 30 frames (~30 seconds) to avoid false positives
- Papers: Paper 4 (ST-CSF), Paper 7 (ST reasoning), Paper 10 (integration)
3. Teacher Absence Alerts
- File:
modules_legacy/context_manager.py(ContextEngine) - Logic: If
timetable[time].teacheris not detected via face recognition β Alert Admin/HOD - Escalation: Security notified if absence >15 minutes
- Papers: Paper 4 (timetable integration)
4. Acoustic Safety Detection
- File:
core/infrastructure/sensing/audio/audio_analyzer.py - Logic:
- Spectral FFT analysis (NO speech recognition)
- Context-aware thresholds: 40 dB lecture, 80 dB break
- Scream detection: >85 dB β Critical alert to Dean
- Privacy: Only dB level, spectral centroid, zero-crossing rate stored (NOT audio samples)
- Papers: Paper 6 (acoustic anomaly), Paper 3 (privacy)
5. Participation Detection
- File:
modules_legacy/master_engine.py(multi-modal fusion) - Logic:
is_hand_raised AND is_loudβ Confirmed participation event - Sensors: Pose keypoints (MediaPipe) + Audio dB
- Papers: Paper 2 (multi-modal fusion), Paper 3 (privacy pose)
6. Immutable Audit Trail
- File:
main_event_driven.py(SimplifiedAuditLog class) - Logic:
- Merkle tree: Each event hashes previous event
- SHA-256 chaining prevents tampering
- Stored in SQLite (
data/audit_log.db)
- Verification:
verify_integrity()recomputes root hash - Papers: Paper 8 (blockchain audit)
What NOT to Change Casually
π Domain Rules (core/domain/rules/)
DO NOT modify without understanding paper claims:
ComplianceRules.is_in_expected_location()β Paper 4 (ST-CSF)AlertRules.get_noise_alert_severity()β Paper 6 (context-aware thresholds)
These are pure functions with ZERO dependencies. Changing them invalidates research papers.
π Event Semantics (core/infrastructure/events/event_bus.py)
DO NOT rename event types without updating all subscribers:
EventType.FACE_DETECTEDβ Subscribed by DetectTruancyUseCaseEventType.VIOLATION_DETECTEDβ Subscribed by EventHandlersEventType.ALERT_TRIGGEREDβ Subscribed by AuditLog
Breaking event flow breaks the entire system.
π Privacy Barriers
DO NOT add logging that exposes:
- Raw image frames (only 512-dim embeddings allowed)
- Audio samples (only spectral features: dB, centroid, ZCR)
- Real student IDs in public logs (use privacy_hash)
Violations compromise GDPR compliance (Paper 3).
π Adaptive Thresholds (core/infrastructure/sensing/vision/face_recognizer.py)
DO NOT hardcode face recognition threshold:
- Current:
Ο(N) = 0.75 + 0.00001 Γ log(N)(adaptive to gallery size) - Changing breaks Paper 1 (open-set identification claims)
β Safe to Change
- UI/UX (dashboard colors, terminal formatting)
- File paths (via environment variables)
- Database schema (if you maintain interface contracts)
- Logging verbosity
How This Supports the Research Papers
The system came first, papers were extracted second (not vice versa).
Each research paper focuses on ONE subsystem of ScholarMaster:
- Paper 1: Face recognition subsystem (FAISS indexing, adaptive thresholds)
- Paper 4: Compliance subsystem (timetable logic, ST-CSF)
- Paper 6: Audio subsystem (spectral analysis, context-aware alerts)
- Paper 8: Audit subsystem (Merkle tree, tamper detection)
- Paper 10: System integration (validates cross-subsystem interactions)
This is why:
- Logic is preserved: Papers depend on implementation being correct
- Architecture is explicit: Makes subsystem boundaries visible for publication
- Three versions exist:
main_unified_backup.pyreproduces paper experiments exactly
For reviewers: If a paper claims "adaptive threshold Ο(N)", you can grep the codebase and find it implemented in face_recognizer.py:L78. This is reproducible research.
Quick Start (New Developers)
1. Install Dependencies
pip3 install -r requirements.txt
2. Initialize Data
# Create students database
python3 utils/create_student_db.py
# Generate timetable (or use existing data/timetable.csv)
python3 modules_legacy/scheduler.py
3. Run the System
# Recommended: Event-driven version
python3 main_event_driven.py
# Alternative: Refactored version
python3 main_refactored.py
# Legacy: Original implementation
python3 main_unified_backup.py
Press q in the video window to quit.
4. Validate Architecture
# Run validation tests (ensures papers are intact)
python3 test_papers.py
# Expected: 8/8 tests passed (100%)
Project Structure
ScholarMasterEngine/
βββ core/ # Refactored Onion Architecture
β βββ domain/ # Pure business logic
β β βββ entities/ # Student, Alert
β β βββ rules/ # ComplianceRules, AlertRules
β β βββ events/ # Domain events
β βββ application/ # Use cases
β β βββ use_cases/ # DetectTruancy, MarkAttendance
β β βββ services/ # EventHandlers
β βββ infrastructure/ # External systems
β β βββ sensing/ # Vision, audio, pose
β β βββ persistence/ # Repositories
β β βββ notifications/ # Alert service
β β βββ events/ # Event bus
β βββ interfaces/ # Dependency inversion ports
β
βββ modules_legacy/ # Original implementations (backward compat)
β βββ face_registry.py # Paper 1
β βββ context_manager.py # Paper 4, 7
β βββ audio_sentinel.py # Paper 6
β βββ ... (11 more modules)
β
βββ data/ # Runtime data (DO NOT commit to git)
β βββ timetable.csv # Schedule ground truth
β βββ students.json # Student database
β βββ alerts.json # Alert log
β βββ audit_log.db # Merkle chain (SQLite)
β βββ faiss_index.bin # Face gallery (FAISS)
β
βββ docs/ # Documentation
β βββ SYSTEM_ARCHITECTURE_DIAGRAM.md # IEEE-grade architecture
β βββ PAPER_SAFETY_MATRIX.md # Paper validation matrix
β βββ REFACTORING_COMPLETE.md # Refactoring summary
β βββ ... (8 more docs)
β
βββ main_event_driven.py # Production entry point (RECOMMENDED)
βββ main_refactored.py # Conservative entry point
βββ main_unified_backup.py # Legacy entry point
βββ test_papers.py # Validation suite
βββ README.md # This file
Common Tasks
Add a New Student
python3 utils/create_superuser.py
# Then use admin panel to enroll face
Modify Timetable
# Edit data/timetable.csv (7 columns: dept, program, year, section, day, start, end, subject, teacher, room)
# Restart system to reload
Debug Event Flow
# Switch to refactored version (no event bus)
python3 main_refactored.py
# Or add debug logging to event bus
# In core/infrastructure/events/event_bus.py:
# print(f"Event published: {event.type}")
Export Attendance Report
python3 utils/export_attendance.py --format csv --month 2026-01
Testing
Unit Tests (Domain Rules)
pytest tests/test_compliance_rules.py
pytest tests/test_alert_rules.py
Integration Tests (Use Cases)
pytest tests/test_detect_truancy.py
System Validation (All Papers)
python3 test_papers.py
# Expected: 8/8 tests passed
Troubleshooting
"FAISS index not found"
- Run
python3 utils/create_student_db.pyto initialize face gallery - Or create empty index:
touch data/faiss_index.bin
"Timetable CSV corrupted"
- Check columns:
dept,program,year,section,day,start,end,subject,teacher,room - Validate with:
python3 utils/validate_timetable.py
"Event handler not receiving events"
- Ensure event type is subscribed:
event_bus.subscribe(EventType.X, handler) - Check event bus imports in
main_event_driven.py
"Paper validation fails"
- DO NOT proceed with deployment
- Revert changes to domain rules or interfaces
- Check
test_papers.pyoutput for exact failure
Contributing
Rules
- DO NOT modify domain rules without paper author approval
- DO write tests for new features (unit + integration)
- DO update documentation (this README, architecture diagrams)
- DO run validation before committing:
python3 test_papers.py
Workflow
- Create feature branch:
git checkout -b feature/your-feature - Make changes (prefer infrastructure/application layers)
- Run tests:
pytest tests/ - Validate papers:
python3 test_papers.py - Update docs if architecture changed
- Submit PR with clear justification
Support & Contact
- Primary Maintainer: Narendra P (@NarendraaP)
- Research Papers: See
docs/PAPER_SAFETY_MATRIX.mdfor full list - Architecture Questions: See
docs/SYSTEM_ARCHITECTURE_DIAGRAM.md - Onboarding: This README (15-minute read)
Last Updated: January 27, 2026
Version: 2.1.0
Status: β
Production-Ready