I have conducted a comprehensive technical audit of the Smart Attendance System codebase. Below is the detailed breakdown of the project structure, logic, security analysis, and data flow.
| File | Description |
|---|---|
| app.py | The core Flask application handling routing, logic, and the face recognition engine. |
| db.py | Database connection utility (contains an inconsistency with app.py). |
| face_utils.py | Utility script using DeepFace (Note: Currently unused in the main app.py flow). |
| train.py | Standalone script for training the LBPH model and saving it to trainer.yml. |
| haarcascade_frontalface_default.xml | Pre-trained Haar Cascade model used for face detection within images. |
| index.html | Main landing page/dashboard with navigation to all system features. |
| login.html | Multi-role (Admin, Faculty, Student) authentication portal. |
| register.html | Student registration page with form fields for metadata and face capture. |
| attendance.html | Table view for browsing and deleting attendance records. |
| camera.html | Live camera interface for marking attendance using face recognition. |
| dashboard.html | Analytics page showing attendance stats by department and subject. |
| class_session.html | Session setup page for professors to define current subject/time before scanning. |
| style.css / script.js | Global assets for UI styling and general client-side interactions. |
| test_*.py | Various testing scripts for camera, OpenCV, and Haar Cascades. |
| dlib...whl | Binary wheels for dlib installation (likely for environment setup). |
app.py is the central controller of the system.
- Flask Structure: It follows a flat structure where all routes and logic reside in one file.
- Role-Based Logic:
- Admin/Faculty: Managed via
session['role']. Can view all records and registration. - Student: Redirected to a specific
student_dashboardviasession['reg_no']to see personal history.
- Admin/Faculty: Managed via
- Key Logic Flow:
- Registration: Validates input → Opens local webcam → Captures 20 frames → Saves to
images/→ Stores metadata in MySQL. - Recognition: Triggered by
/mark_attendance. It callstrain_model(), captures a frame, detects faces, predicts identity using LBPH, and logs "Present" in the DB.
- Registration: Validates input → Opens local webcam → Captures 20 frames → Saves to
- The Bottleneck: It re-trains the entire model (
train_model()) every time someone marks attendance. As the student count grows, this will become exponentially slow.
The system uses MySQL. While no .sql file is present, the schema is inferred from queries in app.py:
| Table | Columns |
|---|---|
| students | id (PK, AI), name, reg_no, department, class, password, email, phone |
| attendance | id (PK, AI), student_id (FK), name, department, class, subject, date, time, status |
| admins | id, username, password |
| faculty | id, faculty_id, password, name |
Important Note: db.py and app.py have conflicting passwords (root123 vs root1909). app.py has its own hardcoded connect_db function, making db.py redundant.
face_utils.py: Contains a functionverify_faceusing DeepFace (a high-level DL library). However, this file is not imported or used by the Flask app.- Active Method:
app.pyuses OpenCV's LBPH (Local Binary Patterns Histograms). This is a traditional machine learning approach that is fast but less accurate than modern Deep Learning (CNNs), especially in varying lighting.
- Storage: Face data is stored as raw
.jpgfiles in theimages/directory. - Workflow:
- Reads all files in
images/. - Extracts the
reg_nofrom the filename (e.g.,22CS001_1.jpg). - Converts to grayscale and detects faces.
- Trains the LBPH recognizer.
- Reads all files in
- Efficiency:
train.pysaves atrainer.ymlfile, butapp.pynever loads it. It re-trains from scratch on every attendance request to ensure the latest data is used—this is highly inefficient.
The UI is a "Premium" styled interface using Grid/Flexbox layouts and CSS animations.
| Page | Frontend Logic | Backend Route |
|---|---|---|
| index.html | Navigation hub with icon-based menu. | / |
| login.html | Role-switching tabs (Admin/Faculty/Student). | /login |
| register.html | Multi-step form with live preview ID card. | /register |
| camera.html | Handles webcam streaming using MJPEG. | /camera |
| attendance.html | Jinja2 loops to render DB records. | /attendance |
| dashboard.html | Visual bar charts for stats. | /dashboard |
- Plaintext Passwords: No hashing (bcrypt/argon2) is used for student, faculty, or admin passwords.
- SQL Injection Risks: While many queries are parameterized, the overall security posture is weak for user inputs.
- Hardware Access Error: The backend tries to open the webcam on the server hardware (
cv2.VideoCapture(0)). This works on a personal laptop but will fail if you deploy it to a remote server (the server has no camera).
- Retraining Loop:
app.pycallstrain_model()on every recognition event. This creates a massive lag as the dataset grows. - Thread Blocking: OpenCV operations are synchronous. One user's facial scan blocks the entire Flask application for other users.
- Inconsistent DB Config: Credential mismatch between
db.pyandapp.py.
graph TD
A[Student Registration] -->|Webcam Capture| B[images/ Folder]
A -->|Store Metadata| C[(MySQL: students)]
D[Faculty Login] -->|Set Session| E[Class Session Setup]
E -->|Redirect with Subject| F[Camera Feed]
F -->|Mark Attendance| G[app.py: train_model]
B -->|Fetch ALL Images| G
G -->|Train LBPH| H[In-Memory Model]
F -->|Capture Test Frame| I[Face Recognition]
H -->|Compare| I
I -->|Match Found| J[Insert Attendance Record]
J -->|Log Present| K[(MySQL: attendance)]
K -->|View Stats| L[Admin Dashboard]
| Library | Purpose |
|---|---|
| flask | Core web framework. |
| opencv-python | Face detection (Haar Cascades) and Recognition (LBPH). |
| mysql-connector-python | Interface for the smart_attendance database. |
| numpy | Efficient handling of image matrices. |
| DeepFace | (Installed but unused) Present in face_utils.py. |
| datetime | Generating timestamps for logs. |