# rfypych/face-attendance architecture

> Architecture diagram of the GitHub repository rfypych/face-attendance, 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/rfypych/face-attendance
- Repository: https://github.com/rfypych/face-attendance

## Overview

##### Main Components
- Backend Service: Built with Python, using FastAPI as the web framework. It houses the API routes (located in app/api/routes.py) and the main entry point (app/main.py).
- Face Recognition Module: Located in app/models (specifically face_recognition.py) which handles the facial recognition logic using MobileFaceNet via ONNX Runtime and OpenCV for Haar Cascade face detection.
- Database: The SQLite database (app/database/face_attendance.db) managed by app/database/db.py for storing user data and face embeddings.
- Frontend Application: A web application built with React (inside app/frontend). It provides the user interface including components for Admin Dashboard, Login, Attendance, Registration, etc.
- External Libraries & Tools: These include OpenCV for image processing, ONNX Runtime for optimized face recognition, and Node.js & npm for the frontend dependencies.

##### Relationships and Data Flow
- Users interact with the React frontend through a web browser. The frontend communicates with the backend API (FastAPI) via HTTP calls.
- The backend processes API requests, invoking the face recognition module for operations such as registration and attendance checking.
- Data is stored or retrieved from the SQLite database. This includes user information and facial embeddings.
- The face recognition component accesses the deep learning model (MobileFaceNet) optimized using ONNX Runtime, while also using Haar Cascades (from OpenCV) for initial face detection.
- The backend (and its API routes) serves as the integration point that connects the user inputs from the frontend with the underlying services (database and recognition module).

##### Architectural Patterns and Key Technologies
- Separation of Concerns: The clear distinction between backend (API, database, face recognition) and frontend (React client).
- MVC / Layered Pattern: Although not strictly MVC, the design separates presentation (frontend), business logic (FastAPI routes), and data access (SQLite database).
- Asynchronous and RESTful API: The FastAPI structure that manages asynchronous API requests ensuring efficient back-end operations for CPU-optimized tasks.

##### Elements
- Use clear labels for each component:
- "Web Client (React Frontend)"
- "API Server (FastAPI)"
- "Face Recognition Module (MobileFaceNet, ONNX Runtime, OpenCV)"
- "Database (SQLite)"
- Optionally, include deployment details like port numbers if desired (e.g., FastAPI on port 8000, React on port 3000).

##### Additional Recommendations
- Configuration or initialization files (such as __init__.py) briefly to note that the project is modular.
- While it is good to include many details, avoid clutter: make sure the main interactions and responsibilities are prominent.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Web Client (React Frontend)"]:::frontend

    subgraph "Backend Service (FastAPI)"
        B["Main Entry (app/main.py)"]:::backend
        C["API Routes (app/api/routes.py)"]:::backend
        B -->|"callsRoutes"| C
    end

    D["Face Recognition (MobileFaceNet, ONNX Runtime, OpenCV)"]:::ml

    subgraph "Database"
        E["DB Connector (app/database/db.py)"]:::db
        F["SQLite DB (app/database/face_attendance.db)"]:::db
        E -->|"accesses"| F
    end

    A -->|"sendsRequest"| B
    B -->|"invokesRecognition"| D
    B -->|"queriesDB"| E

    click A "https://github.com/rfypych/face-attendance/tree/main/app/frontend"
    click B "https://github.com/rfypych/face-attendance/blob/main/app/main.py"
    click C "https://github.com/rfypych/face-attendance/blob/main/app/api/routes.py"
    click D "https://github.com/rfypych/face-attendance/blob/main/app/models/face_recognition.py"
    click E "https://github.com/rfypych/face-attendance/blob/main/app/database/db.py"
    click F "https://github.com/rfypych/face-attendance/blob/main/app/database/face_attendance.db"

    classDef frontend fill:#C0E8F9,stroke:#045,stroke-width:2px;
    classDef backend fill:#F9E0C0,stroke:#C45,stroke-width:2px;
    classDef ml fill:#E0F9C0,stroke:#0A5,stroke-width:2px;
    classDef db fill:#F9C0C0,stroke:#905,stroke-width:2px;
```
