← BACK

EduConnect

attendance management system

HTML ⭐ 0

EduConnect — Smart Attendance System

A Flask-based attendance system built for schools with face recognition, 100m geofencing, offline-first syncing, and real-time alerts. Includes teacher and student dashboards with a polished Tailwind UI and dark mode.

Features

  • Face verification: Students mark attendance with a face capture; server re-verifies on sync.
  • 100m geofencing: Optional proximity check between student and teacher locations.
  • Offline-first: IndexedDB + Service Worker; queues attendance and syncs when back online.
  • Real-time alerts: Teachers receive alerts (Socket.IO) for manual requests or geofence violations.
  • Teacher dashboard: Live summaries, lists, quick actions, manual marking.
  • Student dashboard: Face capture flow, monthly stats, alerts.
  • Dark mode: Class-based Tailwind dark theme with a persistent toggle.
  • PWA-ready: Manifest + Service Worker in static/.

Tech Stack

  • Backend: Flask, Flask-SocketIO
  • ML: face_recognition (dlib), OpenCV, NumPy
  • DB: MySQL (SSL), simple SQL schema
  • Frontend: Tailwind (CDN), Feather icons, Vanilla JS
  • Offline: Service Worker, IndexedDB

Repository Layout (important parts)

attendence-app/
├─ main.py                  # Flask app + routes (APIs, guards, helpers)
├─ modules/
│  ├─ database.py           # MySQL connection + small helper migrations
│  └─ register.py           # Face encoding utilities
├─ templates/
│  ├─ index.html            # Landing page
│  ├─ auth.html             # Login / Register
│  ├─ dashboard.html        # Teacher dashboard
│  └─ student_dashboard.html# Student dashboard
├─ static/
│  ├─ student.js            # Student interactions + offline sync
│  ├─ indexedDB.js          # IndexedDB helpers
│  ├─ service-worker.js     # Offline + background sync
│  └─ manifest.json         # PWA manifest
├─ ca.pem                   # MySQL CA cert (SSL)
├─ requirements.txt         # Python deps (see below for full list)
└─ README.md

Prerequisites

  • Python 3.10+
  • MySQL 8+ (or compatible; project uses SSL)
  • Windows/macOS/Linux with build tools (OpenCV/dlib/face_recognition may need extras on Windows)

Windows notes for face_recognition

  • Installing face_recognition may require prebuilt wheels for dlib and opencv-python. If pip fails to build, search for precompiled wheels matching your Python version.

Setup

  1. Create and activate a virtual environment
  • Windows (PowerShell):
    python -m venv .venv
    .\.venv\Scripts\Activate.ps1
    
  • macOS/Linux:
    python3 -m venv .venv
    source .venv/bin/activate
    
  1. Install dependencies
  • Update requirements.txt or install packages directly:
    pip install flask flask-socketio eventlet mysql-connector-python face-recognition opencv-python numpy
    
    If installation of face-recognition fails, try:
    pip install face-recognition-models
    
  1. Configure database
  • The connection is defined in modules/database.py and references ca.pem.
  • Recommended: move secrets to environment variables and load them (e.g., via os.getenv). Example variables:
    • DB_HOST
    • DB_PORT
    • DB_USER
    • DB_PASSWORD
    • DB_NAME
    • DB_SSL_CA
  1. Create database schema
    Create minimal tables if you don’t already have them:
CREATE TABLE IF NOT EXISTS teachers (
  id INT AUTO_INCREMENT PRIMARY KEY,
  first_name VARCHAR(100) NOT NULL,
  last_name VARCHAR(100) NOT NULL,
  email VARCHAR(255) UNIQUE NOT NULL,
  password VARCHAR(255) NOT NULL,
  school_name VARCHAR(255),
  latitude DECIMAL(10,8) NULL,
  longitude DECIMAL(11,8) NULL
);

CREATE TABLE IF NOT EXISTS students (
  id INT AUTO_INCREMENT PRIMARY KEY,
  first_name VARCHAR(100) NOT NULL,
  last_name VARCHAR(100) NOT NULL,
  email VARCHAR(255) UNIQUE NOT NULL,
  password VARCHAR(255) NOT NULL,
  student_id VARCHAR(100) UNIQUE NOT NULL,
  face_data LONGBLOB NULL,
  face_encoding LONGBLOB NULL
);

CREATE TABLE IF NOT EXISTS attendance (
  id INT AUTO_INCREMENT PRIMARY KEY,
  student_id INT NOT NULL,
  enrollment_no VARCHAR(100) NOT NULL,
  name VARCHAR(255) NOT NULL,
  status ENUM('Present','Absent') NOT NULL,
  marked_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (student_id) REFERENCES students(id)
);

CREATE TABLE IF NOT EXISTS manual_attendance_requests (
  id INT AUTO_INCREMENT PRIMARY KEY,
  student_id INT NOT NULL,
  requested_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY (student_id) REFERENCES students(id)
);

Running the app (development)

  • Export Flask variables and start:
    • Windows (PowerShell):
      $env:FLASK_APP = "main.py"
      $env:FLASK_ENV = "development"
      flask run
      
    • macOS/Linux:
      export FLASK_APP=main.py
      export FLASK_ENV=development
      flask run
      

Notes:

  • Flask-SocketIO will work in dev; for websockets at scale, consider running with eventlet:
    python -c "from main import app, socketio; socketio.run(app, host='0.0.0.0', port=5000)"
    

Key Endpoints (selection)

  • Student
    • POST /login/student (form) — login
    • POST /register/student (form + face image) — registration
    • POST /api/verify-face — verifies face from webcam capture
    • POST /api/sync-attendance — offline sync with server-side re-verification and optional geofencing
    • POST /api/request-manual-attendance — asks teacher to mark present
    • GET /api/student-monthly-stats — monthly stats
  • Teacher
    • POST /login/teacher, POST /register/teacher
    • GET /api/summary — counts for dashboard
    • GET /api/get-present-students — list
    • POST /api/mark-attendance — manual mark by enrollment no
    • POST /api/mark-all-present / POST /api/mark-all-absent
    • GET /api/manual-attendance-requests — pending manual requests
    • POST /api/handle-manual-attendance-request — approve/ignore
    • POST /api/set-teacher-location — saves teacher latitude/longitude

Offline-first and Sync

  • Attendance is cached in IndexedDB when offline via static/indexedDB.js.
  • A Service Worker (static/service-worker.js) registers a background sync task sync-attendance.
  • When online, the client calls /api/sync-attendance. The server:
    • Re-decodes the image and computes a fresh face encoding.
    • Compares with stored student encoding (distance threshold).
    • Optionally validates 100m geofence.
    • Inserts attendance if valid and not already present that day.

Dark Mode

  • Tailwind class-based dark mode is enabled and persisted via localStorage.
  • Toggle buttons are available in headers across pages.

Security Notes

  • Do not commit real DB passwords. Use environment variables or a secrets manager.
  • Face encodings are stored server-side and compared using distance thresholding.
  • SSL DB connections are supported via ca.pem.

Troubleshooting

  • Windows build errors for dlib/face_recognition:
    • Try prebuilt wheels compatible with your Python version.
  • OpenCV import errors:
    • Ensure opencv-python installed. For headless servers, opencv-python-headless may be preferable.
  • Socket.IO not upgrading to websockets:
    • Run with eventlet or a production server that supports websockets.

License

Specify your project’s license here.# EduConnect