# mrniteshray/attendify architecture

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

- Interactive diagram: https://gitdiagram.com/mrniteshray/attendify
- Repository: https://github.com/mrniteshray/attendify

## Overview

##### Main Components
- Mobile Client (Android App): Represent the entire Android application with its key layers.
- UI Layer:
- Activities and Fragments (e.g., MainActivity, AdminActivity, FacultyFragment, SessionFragment, LoginActivity) provide the user interface.
- XML layouts (various activity and fragment layouts, navigation graphs, menus) for UI design.
- Core Logic & Helpers:
- Business logic for managing attendance, authentication, and session flows.
- Helper classes like FaceNetModel, TFLiteHelper that encapsulate face recognition and TensorFlow Lite interactions.
- API/Networking Layer:
- RetrofitClient and TwilioApi (used for sending WhatsApp notifications and interacting with external endpoints).
- Data Layer:
- Data models (AttendanceRecord, Classess, user) which structure the attendance and user data.
- External Services:
- Firebase services (Authentication, Firestore, Cloud Messaging) for backend storage and notifications.
- Google ML Kit for QR code scanning and geofencing functionalities.
- Twilio for sending alerts to parents and faculty.

##### Out the Relationships and Interactions
- Interaction flow starting with a Faculty member initiating an attendance session:
- The “Session Start” triggers the generation of a dynamic QR code and starts a face recognition check.
- The UI layer (activities/fragments) connects to the underlying helper modules where the triple-layered authentication occurs:
- QR Code scanning (using Google ML Kit) leads into geofencing (via Google Play Services).
- Face recognition components (using TFLite and the FaceNet model) verify the student's identity.
- Once the verification is successful, the attendance data is stored by interacting with Firebase services.
- In case of failed verification or for notifications, the business logic calls the API layer via Retrofit, which in turn integrates with the Twilio API to send WhatsApp notifications.
- Analytics and anti-spoofing measures should be shown as part of the business logic that monitors attendance patterns.

##### Architectural Patterns and Design Principles
- Separation of concerns: Clearly partition UI components, business logic, and data layers.
- Modular design: Each functional module (authentication, attendance, notifications) should be represented as independent blocks with defined interfaces.
- Real-time communication: Emphasize how Firebase Firestore and Cloud Messaging provide instant updates.
- Integration points: Make clear how external services (Firebase, Twilio, Google ML Kit) are incorporated.

##### Relevant Technologies and Frameworks
- Kotlin (for main programming logic)
- TensorFlow Lite with FaceNet (for face recognition)
- Google ML Kit (for QR code scanning and geofencing)
- Retrofit (for API communication)
- Firebase (for authentication, storage, messaging)
- Twilio API (for WhatsApp notifications)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Android App"
        subgraph "UI Layer"
            MA["MainActivity"]:::ui
            AA["AdminActivity"]:::ui
            LA["LoginActivity"]:::ui
            FF["FacultyFragment"]:::ui
            SF["SessionFragment"]:::ui
            AD1["AttendanceAdapter"]:::ui
            AD2["SubjectStatsAdapter"]:::ui
            XL["XML Layouts"]:::ui
        end
        subgraph "Business Logic & Helpers"
            FM["FaceNetModel"]:::logic
            TH["TFLiteHelper"]:::logic
            LF["LoadingFragment"]:::logic
            CA["capAct"]:::logic
            RC["RetrofitClient"]:::logic
            TA["TwilioApi"]:::logic
        end
        subgraph "Data Models"
            AR["AttendanceRecord"]:::data
            CL["Classes"]:::data
            US["User"]:::data
        end
    end
    subgraph "External Services"
        FB["Firebase (Auth, Firestore, Messaging)"]:::external
        ML["Google ML Kit (QR&Geofencing)"]:::external
        TFLITE["TensorFlow Lite Model"]:::external
        TW["Twilio (WhatsApp Notifications)"]:::external
    end

    %% UI to Business Logic connections
    FF -->|"startsSession"| SF
    SF -->|"faceRecognition"| FM
    SF -->|"faceRecognition"| TH
    SF -->|"qrScanning"| ML
    %% Business Logic to External & Data
    FM -->|"usesModel"| TFLITE
    TH -->|"usesModel"| TFLITE
    FM -->|"verification"| FB
    TH -->|"verification"| FB
    SF -->|"storeAttendance"| AR
    SF -->|"storeAttendance"| CL
    SF -->|"storeAttendance"| US
    SF -->|"notifyFailure"| RC
    RC -->|"callTwilio"| TA
    TA -->|"sendNotification"| TW
    %% External feedback
    FB -->|"pushUpdates"| MA

    %% Styling
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef logic fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef data fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;

    %% Click Events for UI Layer
    click MA "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/MainActivity.kt"
    click AA "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/AdminActivity.kt"
    click LA "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/login_Activity.kt"
    click FF "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/Faculty/FacultyFragment.kt"
    click SF "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/Faculty/SessionFragment.kt"
    click AD1 "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/AttendanceAdapter.kt"
    click AD2 "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/Faculty/SubjectStatsAdapter.kt"
    click XL "https://github.com/mrniteshray/attendify/tree/main/app/src/main/res/layout/"

    %% Click Events for Business Logic & Helpers
    click FM "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/helper/FaceNetModel.kt"
    click TH "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/helper/TFLiteHelper.kt"
    click LF "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/helper/LoadingFragment.kt"
    click CA "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/helper/capAct.kt"
    click RC "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/api/RetrofitClient.kt"
    click TA "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/api/TwilioApi.kt"

    %% Click Events for Data Models
    click AR "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/Model/AttendanceRecord.kt"
    click CL "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/Model/Classess.kt"
    click US "https://github.com/mrniteshray/attendify/blob/main/app/src/main/java/xcom/niteshray/apps/attendify/Model/user.kt"

    %% Click Events for External Services
    click FB "https://github.com/mrniteshray/attendify/blob/main/app/google-services.json"
    click TFLITE "https://github.com/mrniteshray/attendify/blob/main/app/src/main/assets/mobile_face_net.tflite"
```
