Spaces:
Sleeping
title: NetraID Backend
emoji: π§βπΌ
colorFrom: cyan
colorTo: blue
sdk: docker
app_port: 8000
pinned: false
NetraID - Production-Grade AI Face Authentication Attendance System
NetraID is an enterprise-grade, 100% free, and self-hosted face-authentication attendance platform. Using advanced facial biometrics, liveness classifiers, and high-performance vector indexes, it provides an offline, secure, and production-ready system suitable for digital kiosks, schools, colleges, and startups.
Technical Stack & Architecture
NetraID uses clean-architecture layers (Repository and Service layers) to structure code modularly.
- AI & Computer Vision: SCRFD (Face Detection), ArcFace (Face Recognition), MiniFASNet (Silent Face Anti-Spoofing) running on pure ONNX Runtime.
- Backend API: Python 3.12, FastAPI, SQLAlchemy 2.0, Alembic, Pydantic V2, JWT RBAC, and Audit Logging.
- Voice synthesis: Offline
pyttsx3text-to-speech engine. - Vector Database: PostgreSQL 16 with the native
pgvectorextension. - Frontend Kiosk & Dashboard: Next.js 15, TypeScript, Tailwind CSS, Framer Motion, and Apache ECharts.
- Deployment: Docker, Docker Compose, and Nginx.
Project Structure
NetraID/
βββ backend/
β βββ app/
β β βββ api/ # API Router endpoints
β β βββ core/ # Database connection, security, seeding
β β βββ crud/ # CRUD repositories (SQLAlchemy 2.0)
β β βββ models/ # Database ORM models
β β βββ schemas/ # Pydantic V2 validation schemas
β β βββ services/ # FaceEngine AI & pyttsx3 TTS helper
β βββ requirements.txt # Python requirements
β βββ Dockerfile # Backend image builder
βββ frontend/
β βββ app/ # Next.js pages (Login, Dashboard, Kiosk)
β βββ components/ # Shared components (SidebarLayout)
β βββ package.json # Node requirements
β βββ Dockerfile # Frontend image builder
βββ docker/
β βββ nginx.conf # Reverse proxy configuration
βββ docker-compose.yml # Docker orchestrator
βββ README.md # System documentation
Setup Instructions
NetraID runs natively on both Windows and Linux.
Option A: Quick Launch via Docker Compose (Recommended)
Clone & Navigate:
cd NetraIDDownload AI Model Weights: Run the model downloader script locally to pull the ONNX models to the
./modelsfolder, or let the backend do it on boot. To run it manually:cd backend python -m pip install -r requirements.txt python app/core/download_models.py cd ..Start Stack:
docker compose up --buildAccess Applications:
- Dashboard & Kiosk: http://localhost (Nginx proxy)
- FastAPI API Swagger Docs: http://localhost/docs
- PostgreSQL Database: Port
5432
Option B: Local Development Setup (Windows & Linux)
1. Setup PostgreSQL + pgvector
Make sure you have a running PostgreSQL instance and install the pgvector extension:
CREATE EXTENSION IF NOT EXISTS vector;
2. Run Backend
- Initialize Virtual Env:
cd backend python -m venv venv # On Windows: venv\Scripts\activate # On Linux: source venv/bin/activate - Install Packages:
- On Linux: Install
espeakfor pyttsx3 and Mesa GL for OpenCV:sudo apt-get install -y libgl1-mesa-glx libglib2.0-0 espeak - On Windows: Python packages will install SAPI5 dependencies automatically.
pip install -r requirements.txt - On Linux: Install
- Download ONNX Models:
python app/core/download_models.py - Boot Server:
uvicorn app.main:app --reload --port 8000
3. Run Frontend
- Navigate & Install:
cd ../frontend npm install - Boot Dev Server:
Open http://localhost:3000 in your browser.npm run dev
System Workflows
1. Seeding & Credentials
On startup, the system seeds default values.
- Initial Super Admin:
admin@netraid.ai/Admin@NetraID2026 - Default Shift Timing: Start:
09:00, End:17:00 - Grace Period: 15 minutes.
- Similarity Thresholds: Face Cosine distance:
0.60, Liveness threshold:0.75
2. Biometric Face Enrollment (10 Poses)
To complete a registration, navigate to the Employees page, select a user, and click Camera. The admin must capture/upload 10 distinct poses to achieve high-accuracy matches:
- Poses: Front, Left, Right, Looking Up, Looking Down, Smiling, Neutral, Indoor Light, Outdoor Light, Glasses (Optional).
- Reference embeddings are saved as L2-normalized 512-D float vectors inside PostgreSQL.
3. Kiosk Scanning & Liveness
When an employee stands in front of the kiosk webcam:
- The system captures frames and scans for exactly one face (SCRFD).
- Runs Silent-Face-Anti-Spoofing (MiniFASNet). If the liveness score is below
0.75, the scan is rejected as a spoof (e.g. photos, phone screen). - Extracts the 512-D face embedding (ArcFace) and runs a pgvector cosine distance query:
SELECT * FROM face_embeddings ORDER BY embedding <=> :search_vector LIMIT 1; - Calculates similarity
1.0 - distance. If similarity is $\ge 0.60$, the employee is identified. - Marks Check-In (first swipe) or Check-Out (subsequent swipes) and logs the entry.
- Synthesizes a greeting offline using
pyttsx3(Windows SAPI5 / Linux espeak) based on time-of-day:05:00 - 11:59: "Good Morning"12:00 - 16:59: "Good Afternoon"17:00 - 23:59: "Good Evening"