# tejas7k/face-attendeance-system architecture

> Architecture diagram of the GitHub repository tejas7k/face-attendeance-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tejas7k/face-attendeance-system
- Repository: https://github.com/tejas7k/face-attendeance-system

## Overview

##### Project Type and Purpose
- This project is a Python-based face recognition application. It uses a web interface (built in Flask) to allow user registration (including face capturing) and to log attendance via face recognition.
- Key technologies include Flask (web server), OpenCV (face detection with the Haar Cascade), and scikit-learn (face recognition with a KNN model), and it logs attendance data in CSV files.

##### Analyzing the File Structure
- Top-level files:
- app.py: The main application file which manages routes, face detection, recognition, and attendance logging.
- haarcascade_frontalface_default.xml: The pre-trained Haar Cascade used for face detection.
- README.md and background.png (additional UI resource).
- Directories:
- static: Contains the serialized face recognition model (face_recognition_model.pkl) and a folder named “faces” where each subdirectory (e.g., tejas_7) holds face images of a registered user.
- templates: Contains the HTML templates (home.html) used for the web interface.
- The attendance records (CSV files) are saved (as noted in the README) in an Attendance directory (even if not immediately present in the file tree, it is described as part of the system).

##### Key Components
- Web Server Component:
- Flask application (app.py) that handles different routes such as home ("/"), user registration ("/add"), and starting attendance ("/start").
- Face Detection Module:
- OpenCV integrated with the Haar Cascade (haarcascade_frontalface_default.xml) to detect faces in webcam frames.
- Face Recognition Module:
- The KNN model for face recognition is trained on captured face images. The trained model is stored as “face_recognition_model.pkl” in the static folder.
- Data Storage / Attendance Logging:
- Attendance records are stored in CSV files (named with the date) under an Attendance directory.
- User Interface:
- HTML templates (home.html) in the templates directory which render the web pages.
- Additional static assets such as the background image for the webcam interface.
- Image Capture and Storage:
- The static/faces directory contains subdirectories for each registered user’s face image dataset.

##### Establishing Relationships and Data Flow
- The user accesses the system via a web browser and loads the web interface (served by Flask from the templates).
- When a user registers:
- The system captures face images from a webcam.
- These images are stored in the corresponding user directory under static/faces.
- The face detection module (using OpenCV and the Haar Cascade file) processes these images.
- When registering and starting attendance:
- The images are either directly compared using the KNN model or used to trigger model training, updating the stored model (face_recognition_model.pkl).
- Attendance is logged in a CSV file within the Attendance folder with user details and timestamp.
- Data flow from the Web Browser to the Flask server.
- Flask’s communication with the face detection and face recognition services.
- Storage operations to the static directory (for models and captured face images) and the Attendance directory for logs.

##### Final Advice for the Principal Software Engineer
- Component is labeled clearly with its role (e.g., “Flask Server: Handles routing and processing”).
- A different one for processing modules,
- And another for data storage components.
- As many components as possible to reflect both the high-level architecture and the finer details of how voice data flows from registration to attendance logging.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI("Web Browser / User Interface"):::ui
        HTML("HTML Templates"):::ui
    end

    %% Application Layer
    subgraph "Application Layer"
        Flask("Flask Web Server (app.py)"):::process
    end

    %% Processing Modules
    subgraph "Processing Modules"
        FD("Face Detection Module (OpenCV + Haar Cascade)"):::process
        FR("Face Recognition Module (KNN Model Storage)"):::process
    end

    %% Data Storage
    subgraph "Data Storage"
        Faces("Image Storage (static/faces)"):::storage
        Attendance("Attendance Logger (CSV Files)"):::storage
    end

    %% Connections: Frontend to Application
    UI -->|"sendsRequest"| Flask
    HTML -->|"rendersUI"| Flask

    %% Connections: Application to Processing
    Flask -->|"triggersDetection"| FD
    Flask -->|"triggersRecognition"| FR

    %% Processing Interaction
    FD -->|"detectsFace"| FR

    %% Data Flow: Recognition to Storage
    FR -->|"updatesImages"| Faces
    FR -->|"logsAttendance"| Attendance

    %% Click Events
    click Flask "https://github.com/tejas7k/face-attendeance-system/blob/main/app.py"
    click FD "https://github.com/tejas7k/face-attendeance-system/blob/main/haarcascade_frontalface_default.xml"
    click FR "https://github.com/tejas7k/face-attendeance-system/blob/main/static/face_recognition_model.pkl"
    click HTML "https://github.com/tejas7k/face-attendeance-system/blob/main/templates/home.html"
    click Faces "https://github.com/tejas7k/face-attendeance-system/tree/main/static/faces"

    %% Styles
    classDef ui fill:#a3d9ff,stroke:#333,stroke-width:2px;
    classDef process fill:#d1f2a5,stroke:#333,stroke-width:2px;
    classDef storage fill:#f9e79f,stroke:#333,stroke-width:2px;
```
