# rifkidocs/presensi-face-recognition architecture

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

- Interactive diagram: https://gitdiagram.com/rifkidocs/presensi-face-recognition
- Repository: https://github.com/rifkidocs/presensi-face-recognition

## Overview

##### Project type and purpose
- This is a Next.js web application that runs primarily in the browser.
- It provides an attendance (“presensi”) dashboard for students, teachers, and staff, leveraging client-side face recognition and liveness checks.
- There is no separate backend or API folder; data is persisted locally (IndexedDB) and models are served as static assets.

##### File structure
- Top-level config files: next.config.mjs, tailwind.config.js, postcss.config.mjs, jsconfig.json.
- Public folder: hosts pre-trained face-api.js model shards and weight manifests.
- src/app: Next.js “app router” pages for dashboard and presensi—each with its own route.
- src/components: React UI components (sidebar, tables, forms) and higher-level components (LivenessCheck, WebcamContainer).
- src/hooks: custom hooks for camera, face recognition, location, mobile detection.
- src/lib: core utilities (faceDetection.js, indexedDB.js, presenceUtils.js).
- middleware.js: Next.js middleware (e.g., route guards).
- No /pages/api or database folder implies pure frontend.

##### README
- Standard Next.js scaffolding instructions.
- No mention of a separate backend or third-party data store.
- Deployed on Vercel, served as a static or server-rendered Next.js app.

##### Elements
- Blue rectangles for server/hosting (Next.js, Vercel)
- Green rectangles for client-side logic (React, Hooks, ML Pipeline)

##### Final advice
- Layer distinctly: Hosting → Data store → ML assets → Application logic → UI.
- Be very detailed: include components folder vs. ui subfolder vs. hooks vs. lib.
- Don’t overthink—break the system down into as many logical parts as needed so that every file/folder purpose is represented as a component or sub-component.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hosting Layer
    subgraph "Hosting Layer"
        NextServer["Next.js Server (SSR/SSG layer)"]:::server
        Vercel["Vercel Deployment"]:::external
    end

    %% Static Assets
    subgraph "Static Asset Store"
        PublicModels["face-api.js Model Host (public/models)"]:::external
    end

    %% Client Browser
    subgraph "Client Browser"
        %% React UI
        subgraph "React UI"
            AppRoutes["App Routes (src/app)"]:::logic
            UIComponents["UI Components (src/components)"]:::logic
        end

        %% ML Pipeline
        subgraph "ML Pipeline"
            MLModels["Model Shards & Manifests"]:::external
            FaceDetect["faceDetection.js"]:::logic
        end

        %% Hooks
        subgraph "Custom Hooks"
            HookFaceRec["useFaceRecognition.js"]:::logic
            HookWebcam["useWebcam.js"]:::logic
            HookLocation["useLocation.js"]:::logic
            HookMobile["use-mobile.jsx"]:::logic
        end

        %% Data Store
        IndexedDBStore["IndexedDB Store"]:::storage

        %% Utils & Components
        PresenceUtils["presenceUtils.js"]:::logic
        LivenessCheck["LivenessCheck Component"]:::logic
        WebcamContainer["WebcamContainer Component"]:::logic

        %% Browser APIs
        GeoAPI["navigator.geolocation"]:::external
        WebcamAPI["MediaDevices.getUserMedia"]:::external
    end

    %% Middleware
    Middleware["Route Guards (middleware.js)"]:::server

    %% Connections
    Vercel --> NextServer
    NextServer -->|serves pages| AppRoutes
    NextServer -->|serves static assets| PublicModels

    AppRoutes -->|renders UI| UIComponents
    UIComponents -->|includes| LivenessCheck
    UIComponents -->|includes| WebcamContainer

    WebcamContainer -->|captures frames| WebcamAPI
    WebcamAPI -->|provides stream| HookWebcam
    HookWebcam -->|video frames| FaceDetect
    MLModels -->|loaded by| FaceDetect
    FaceDetect -->|detections| PresenceUtils
    HookFaceRec -->|manages model| FaceDetect
    HookLocation -->|fetches location| GeoAPI
    PresenceUtils -->|persists data| IndexedDBStore
    IndexedDBStore -->|data for| UIComponents
    LivenessCheck -->|invokes| HookFaceRec

    Middleware -->|guards routes| AppRoutes

    %% Click Events
    click NextServer "https://github.com/rifkidocs/presensi-face-recognition/blob/main/next.config.mjs"
    click NextServer "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/layout.js"
    click PublicModels "https://github.com/rifkidocs/presensi-face-recognition/tree/main/public/models/"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/page.js"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/dashboard/page.jsx"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/dashboard/login/page.js"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/dashboard/kelola-siswa/page.js"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/dashboard/presensi-siswa/page.jsx"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/dashboard/presensi-guru/page.jsx"
    click AppRoutes "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/app/dashboard/presensi-pegawai/page.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/app-sidebar.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/nav-main.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/nav-secondary.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/nav-user.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/login-form.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/section-cards.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/chart-area-interactive.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/data-table-kelola-siswa.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/data-table-presensi-siswa.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/data-table-presensi-guru.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/data-table-presensi-pegawai.jsx"
    click UIComponents "https://github.com/rifkidocs/presensi-face-recognition/tree/main/src/components/ui/"
    click MLModels "https://github.com/rifkidocs/presensi-face-recognition/tree/main/public/models/"
    click FaceDetect "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/lib/faceDetection.js"
    click HookFaceRec "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/hooks/useFaceRecognition.js"
    click HookWebcam "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/hooks/useWebcam.js"
    click HookLocation "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/hooks/useLocation.js"
    click HookMobile "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/hooks/use-mobile.jsx"
    click IndexedDBStore "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/lib/indexedDB.js"
    click PresenceUtils "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/lib/presenceUtils.js"
    click LivenessCheck "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/LivenessCheck.js"
    click WebcamContainer "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/components/WebcamContainer.js"
    click Middleware "https://github.com/rifkidocs/presensi-face-recognition/blob/main/src/middleware.js"

    %% Styles
    classDef server fill:#cfe2f3,stroke:#0366d6,color:#000;
    classDef external fill:#eeeeee,stroke:#888888,color:#000,stroke-dasharray: 2 2;
    classDef logic fill:#d9ead3,stroke:#6aa84f,color:#000;
    classDef storage fill:#ffe599,stroke:#b45f06,color:#000,stroke-width:2px;
```
