# deepsoftwareeng/facedetectionattendance architecture

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

- Interactive diagram: https://gitdiagram.com/deepsoftwareeng/facedetectionattendance
- Repository: https://github.com/deepsoftwareeng/facedetectionattendance

## Overview

##### Main Components
- User Interface (Presentation Layer): Represented by the WPF views (XAML files in the “FaceDetectionAttendance/MVVM/View” folder) and UI components (custom controls in “FaceDetectionAttendance/MVVM/Components”). These are the parts that the end user interacts with.
- Presentation Logic: The ViewModels (located in “FaceDetectionAttendance/MVVM/ViewModel”) that bind the UI to the application’s underlying logic. They handle data binding, commands, and interactions between the UI and the business logic.
- Domain Models and Business Logic: The Models (in “FaceDetectionAttendance/MVVM/Model”) define the core objects (such as Account, Attendance, Request, etc.) and include utility classes like Database connection helper objects.
- Face Detection Module: Though not separated into a distinct module, the presence of the “haarcascade_frontalface_default.xml” indicates that OpenCV is used in conjunction with some underlying code (possibly in the Models or a utility class) to execute face recognition.
- Database Layer: External SQL server connectivity (using localdb/SQL Server) as mentioned in the README, with the schema defined in “CCPTPM.sql”. This component manages all data persistence (accounts, attendance records, etc.).
- External Services & Utilities: Email sending components (“SendEmailUI” and its associated ViewModel) to notify the manager about attendance, along with image resources and other assets in the “Resource” folder.

##### Out the Relationships and Interactions
- The UI layer (Views and custom components) captures user events and feeds them into the associated ViewModels.
- The ViewModels then make calls to the Domain Models for operations like login, managing accounts, marking attendance, processing face detection, and generating reports.
- The Face Detection feature integrates with the Model layer to process camera or image input using OpenCV (leveraging the provided cascade XML file).
- Data from user interactions and face recognition results flow to the Database layer via appropriate Model classes which encapsulate the connection logic (as seen with “Dataconnecttion.cs”).
- Email notifications or requests (handled in “SendEmail.cs” and related View/UI files) deliver automated communications to the manager.
- The entire data flow is supported by MVVM’s separation of concerns, making the components loosely coupled and testable.

##### Architectural Patterns and Components
- Client-Server Communication: Even though it’s a desktop application, represent the database as a separate server component (SQL Server/localdb) that the application communicates with.
- Integration with OpenCV: Even if the OpenCV calls are encapsulated within utility or service classes, clearly denote this as the face recognition engine.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface (WPF)"
        UIViews["WPF Views (XAML)"]:::ui
        UIComponents["UI Components (Custom Controls)"]:::ui
    end

    %% Presentation Logic
    subgraph "Presentation Logic (ViewModels)"
        ViewModels["ViewModels"]:::viewmodel
    end

    %% Domain Models & Business Logic
    subgraph "Domain Models & Business Logic (Models)"
        Models["Models"]:::model
    end

    %% Face Detection Module
    subgraph "Face Detection Module (OpenCV)"
        HaarCascade["Haar Cascade XML"]:::detection
        BitmapUtil["BitmapSourceConvert Utility"]:::detection
    end

    %% Database Layer
    Database["SQL Server/localdb"]:::database

    %% External Services: Email Notification
    subgraph "Email Notification"
        EmailUI["Email UI"]:::email
        EmailLogic["Email Logic"]:::email
    end

    %% Connections
    UIViews -->|"userEvents"| ViewModels
    UIComponents -->|"userEvents"| ViewModels
    ViewModels -->|"businessLogic"| Models
    Models -->|"dataPersistence"| Database
    Models -->|"faceProcessing"| HaarCascade
    Models -->|"faceProcessing"| BitmapUtil
    ViewModels -->|"notifyManager"| EmailUI
    ViewModels -->|"notifyManager"| EmailLogic

    %% Click Events
    click UIViews "https://github.com/deepsoftwareeng/facedetectionattendance/tree/master/FaceDetectionAttendance/MVVM/View"
    click UIComponents "https://github.com/deepsoftwareeng/facedetectionattendance/tree/master/FaceDetectionAttendance/MVVM/Components"
    click ViewModels "https://github.com/deepsoftwareeng/facedetectionattendance/tree/master/FaceDetectionAttendance/MVVM/ViewModel"
    click Models "https://github.com/deepsoftwareeng/facedetectionattendance/tree/master/FaceDetectionAttendance/MVVM/Model"
    click HaarCascade "https://github.com/deepsoftwareeng/facedetectionattendance/blob/master/FaceDetectionAttendance/haarcascade_frontalface_default.xml"
    click BitmapUtil "https://github.com/deepsoftwareeng/facedetectionattendance/blob/master/FaceDetectionAttendance/MVVM/Model/BitmapSourceConvert.cs"
    click Database "https://github.com/deepsoftwareeng/facedetectionattendance/blob/master/FaceDetectionAttendance/MVVM/Model/Dataconnecttion.cs"
    click EmailUI "https://github.com/deepsoftwareeng/facedetectionattendance/blob/master/FaceDetectionAttendance/MVVM/View/SendEmailUI.xaml"
    click EmailLogic "https://github.com/deepsoftwareeng/facedetectionattendance/blob/master/FaceDetectionAttendance/MVVM/ViewModel/SendEmail.cs"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef viewmodel fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef model fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef detection fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef database fill:#f5c6cb,stroke:#dc3545,stroke-width:2px;
    classDef email fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
