Spaces:
Configuration error
Smart Attendance System
An asynchronous, AI-powered multi-layered attendance verification system designed to eliminate buddy punching, proxy check-ins, and attendance fraud. The project consists of a FastAPI backend using TensorFlow/DeepFace, a Next.js web application for administration/teachers, and a Flutter mobile application for students.
π Key Features
1. Multi-Layered AI Verification
To mark attendance, the student uploads a live selfie which undergoes three independent stages of verification:
- Facial Recognition: Matches the student's live face embedding against their registered template using the FaceNet model (via DeepFace) with 128-dimensional vector embeddings stored in PostgreSQL using
pgvector. - Liveness Detection: Employs a custom-trained MobileNetV2 model to check if the submission is a real person, preventing spoofing attempts using photos, videos, or masks.
- Background Validation: Utilizes a custom MobileNetV1 model to verify that the background of the image matches the expected classroom environment.
2. Location & Geofencing
- Verifies student's physical location against active class coordinates.
- Teachers define geofenced regions (latitude, longitude, and radius in meters).
- Submissions outside the geofence boundary are automatically flagged or rejected.
3. Device Binding (Anti-Proxy)
- Restricts each student account to a single mobile device.
- Generates and binds a unique hardware UUID (
device_uuid) on first login. - Students must submit a Device Change Request to be approved by administrators/teachers before they can log in on a new device.
4. Real-time Communication & Notifications
- Websocket-based live connection to push real-time attendance updates to teachers' dashboards.
- Firebase Cloud Messaging (FCM) integration to dispatch push notifications for new sessions, reminders, and leave status updates.
5. Gamification Suite
- Encourages student attendance through engagement features including current/highest streaks, levels, leaderboards, and point systems.
π οΈ Technology Stack & Versions
| Layer | Technology | Version / Specification | Key Libraries |
|---|---|---|---|
| Backend | Python 3.11 / FastAPI | 0.115.6 |
Prisma ORM, TensorFlow 2.15.0, DeepFace 0.0.93, OpenCV 4.10.0, Redis 5.2.1 |
| Frontend | Next.js (React 19) | 16.2.6 |
Tailwind CSS 4.x, Recharts 3.8.1, Zustand 5.0.13, Leaflet Map 1.9.4 |
| Mobile | Flutter SDK | ^3.8.0 |
Riverpod ^2.6.1, Dio ^5.7.0, Geolocator ^13.0.2, Hive ^2.2.3 |
| Database | PostgreSQL | 15+ | pgvector extension enabled for biometric representations |
π Project Structure
.
βββ backend/ # FastAPI python application, database migrations, and AI models
β βββ app/ # Application source code (api, core, db, middleware, services, etc.)
β βββ models/ # Local folder for downloading/caching TF models
β βββ prisma/ # Prisma schema and seeding configurations
β βββ main.py # App entrypoint
βββ frontend/ # Next.js web application for admins and teachers
β βββ src/ # Next.js pages/components
β βββ package.json # Frontend dependency definitions
βββ mobile/ # Flutter student companion app
βββ lib/ # Flutter implementation source code
βββ pubspec.yaml # Flutter dependency configuration
βοΈ Getting Started
Prerequisites
- Python 3.11 installed on the host system.
- Node.js 20+ and npm installed.
- Flutter SDK (v3.8.x+) and target development environment (Android/iOS simulator or physical device).
- PostgreSQL database with
pgvectorextension enabled. - Redis Server running locally or accessible via network.
- A HuggingFace token (
HF_TOKEN) to download pre-trained liveness & background models.
1. Backend Setup
Navigate to the directory:
cd backendConfigure environment variables: Create a
.envfile by copying the template:cp .env.example .envFill in the required fields (database connection strings, Redis URL, JWT Secret, and HF token if required).
Install dependencies:
pip install -r requirements.txtPrepare the database (Prisma): Ensure your PostgreSQL service is running and has the
pgvectorextension enabled, then run:python -m prisma db push python -m prisma generateSeed the database (Optional):
python prisma/seed.pyStart the server:
uvicorn main:app --reload --port 8000Interactive API documentation will be available at http://localhost:8000/docs.
2. Frontend Setup
Navigate to the directory:
cd frontendConfigure environment variables: Ensure a
.env.localfile exists:NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1Install dependencies:
npm installStart the development server:
npm run devThe dashboard will be running at http://localhost:3000.
3. Mobile Setup
Navigate to the directory:
cd mobileGet Flutter packages:
flutter pub getRun the application: Make sure you have an active emulator or connected device:
flutter run
π Security & Verification Parameters
The verification strictness can be controlled globally via the administrator settings page or in .env:
- Face Embedding matching threshold: Standard threshold is configured to
0.75(cosine similarity/confidence score). - Liveness Detection threshold: Values above
0.5denote real face image inputs. - Geofencing validation: Distance calculated dynamically using the Haversine formula based on student's GPS reports and active class geofence boundaries.