# nkosimlaba/facial-recognition-attendance-system architecture

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

- Interactive diagram: https://gitdiagram.com/nkosimlaba/facial-recognition-attendance-system
- Repository: https://github.com/nkosimlaba/facial-recognition-attendance-system

## Overview

##### Main Components
- Frontend/UI:
- Represented by the static HTML templates (e.g., arrival.html, departure.html, employee_enroll.html, student_enroll.html) and associated CSS/JavaScript files (pause-camera.js, picture-capture.js, common.css, pause-camera.css) within src/main/resources/static.
- This is the browser-based UI that users interact with.
- Web API / Application Server:
- The Java-based web server and controller classes (WebServer.java and Controller.java) located in src/main/java/za/co/theemlaba/webapi. They are responsible for routing, handling HTTP requests, and serving the web pages.
- Database Access Layer:
- Both Java and Python modules are present for database interactions (e.g., Database.java in the Java package and database.py in the python package), which abstract interactions with the underlying SQLite database.
- Face Recognition Service:
- The Python module (face_recognition_service.py) which implements the face recognition logic, integrated with the attendance workflow.
- Build and Dependency Components:
- Build scripts and configurations like Makefile, pom.xml (for Maven), and CMake dependency files ensure that dependencies and builds are managed correctly.

##### Relationships and Interactions
- Clients (web browsers) send user interactions and HTTP requests to the Web API.
- The Web API (Java server) receives these requests, interfaces with the Database Access Layer for enrollment and attendance recording.
- For face recognition, the API or a background service triggers the Python-based face recognition module, which processes camera feeds and returns recognition results.
- There is a clear separation between the frontend and backend layers, with well-defined interfaces (HTTP endpoints).
- The static resources (HTML, CSS, JS) are served by the web server to the clients.

##### Architectural Patterns and Technologies
- MVC-like Pattern:
- The web API design implies a separation between the controller (handling HTTP requests), models (the data layer via Database classes) and views (HTML templates served to clients).
- Hybrid Technology Stack:
- Java is used for the core server functionality and web API.
- Python is used for specialized tasks such as face recognition and possibly some database interactions.
- Web-Client/Server Architecture:
- The interaction between the browser and the backend server is central to the design, with RESTful endpoints implied by the “make webapi” and provided endpoints.
- Build and Dependency Management:
- Maven (pom.xml) and Makefiles are used to handle compilation, dependency resolution, and testing procedures.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Components
    subgraph "Frontend"
        UI["Web Browser (UI)"]:::frontend
        StaticAssets["Static Assets"]:::static
        Templates["Templates (HTML)"]:::static
        Scripts["Scripts (JS)"]:::static
        Styles["Styles (CSS)"]:::static
    end

    %% Backend Components
    subgraph "Backend"
        API["Java Web API"]:::backend
        WebServer["WebServer"]:::backend
        Controller["Controller"]:::backend
        JavaDB["Database Access (Java)"]:::backend
        PyDB["Database Access (Python)"]:::python
        FaceRecog["Python Face Recognition Service"]:::python
    end

    %% Database Component
    DB["Database (SQLite)"]:::database

    %% Build and Dependency Tools
    subgraph "Build Tools"
        Build["Build Tools"]:::build
        Makefile["Makefile"]:::build
        Maven["Maven (pom.xml)"]:::build
        PythonDeps["Python Dependencies"]:::build
    end

    %% Relationships and Data Flow
    UI -->|"HTTP_request"| API
    API -->|"serves"| StaticAssets
    StaticAssets -->|"contains"| Templates
    StaticAssets -->|"contains"| Scripts
    StaticAssets -->|"contains"| Styles

    API -->|"handles"| WebServer
    API -->|"handles"| Controller

    API -->|"invokes_JavaDB"| JavaDB
    JavaDB -->|"executes_SQL"| DB

    API -->|"calls_face_recognition"| FaceRecog
    FaceRecog -->|"updates_DB"| DB
    FaceRecog -->|"calls_PyDB"| PyDB
    PyDB -->|"executes_SQL"| DB

    Build -->|"builds"| API
    Build -->|"builds"| FaceRecog
    Build -->|"builds"| StaticAssets

    %% Click Events
    click StaticAssets "https://github.com/nkosimlaba/facial-recognition-attendance-system/tree/main/src/main/resources/static/"
    click Templates "https://github.com/nkosimlaba/facial-recognition-attendance-system/tree/main/src/main/resources/static/templates/"
    click Scripts "https://github.com/nkosimlaba/facial-recognition-attendance-system/tree/main/src/main/resources/static/scripts/"
    click Styles "https://github.com/nkosimlaba/facial-recognition-attendance-system/tree/main/src/main/resources/static/styles/"
    click API "https://github.com/nkosimlaba/facial-recognition-attendance-system/tree/main/src/main/java/za/co/theemlaba/webapi/"
    click WebServer "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/src/main/java/za/co/theemlaba/webapi/WebServer.java"
    click Controller "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/src/main/java/za/co/theemlaba/webapi/Controller.java"
    click JavaDB "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/src/main/java/za/co/theemlaba/database/Database.java"
    click PyDB "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/src/main/python/za/co/theemlaba/database.py"
    click FaceRecog "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/src/main/python/za/co/theemlaba/face_recognition_service.py"
    click Makefile "https://github.com/nkosimlaba/facial-recognition-attendance-system/tree/main/Makefile"
    click Maven "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/pom.xml"
    click PythonDeps "https://github.com/nkosimlaba/facial-recognition-attendance-system/blob/main/dependencies/requirements.txt"

    %% Styles
    classDef frontend fill:#a8dadc,stroke:#000,stroke-width:1px;
    classDef static fill:#ffb703,stroke:#000,stroke-width:1px;
    classDef backend fill:#457b9d,stroke:#000,stroke-width:1px;
    classDef python fill:#1d3557,stroke:#fff,stroke-width:1px;
    classDef database fill:#e63946,stroke:#000,stroke-width:1px;
    classDef build fill:#2a9d8f,stroke:#000,stroke-width:1px;
```
