# thetimemachine01/facedec architecture

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

- Interactive diagram: https://gitdiagram.com/thetimemachine01/facedec
- Repository: https://github.com/thetimemachine01/facedec

## Overview

##### Project type and purpose
- From the README and file tree, this is a two-part system:
- A React Native mobile application for end-users (employees/students) to check in/out via face recognition.
- A Spring Boot monolith backend providing REST APIs for authentication, attendance, face detection orchestration, and data persistence.
- Purpose: automate attendance via real-time face detection, secure user management, and generate attendance logs.

##### File structure
- Top-level artifacts:
- Dockerfile, docker-compose.yml → containerized deployment of backend + database.
- pom.xml, mvnw → Spring Boot build.
- src/main/java/com/application/facedec → layered code (controller, service, repository, config, dto, entity, exceptions).
- src/main/resources/db/migration → Flyway SQL migrations.
- OpenCV Haarcascade XML in resources → face detection model.
- Patterns & frameworks:
- Layered MVC: Controllers → Services → Repositories (JPA).
- Spring Security with JWT filters.
- Face detection integrated via OpenCVConfig in controller layer.
- Database migrations via Flyway.

##### README for additional insights
- Tech stack: React Native (mobile), Spring Boot (backend), unspecified RDBMS, Docker for deployment.
- Features: real-time face detection, user management, attendance tracking, notifications.
- Future scope indicates an admin web front-end (not yet implemented) and external integrations (HR/payroll).

a. Main components:
1. Mobile Application (React Native)
2. API Gateway / Spring Boot Backend
– Controllers (AuthController, AttendanceController, FaceDetectionController, HealthController)
– Security Layer (JWTAuthenticationFilter, SecurityConfig, JwtTokenProvider)
– Service Layer (AuthService, AttendanceService, FaceDetectionService, EmployeeService, UserService)
– Data Access Layer (JPA Repositories)
3. Database (PostgreSQL/MySQL) with Flyway migrations
4. Face Detection Engine (OpenCV + haarcascade XML)
5. External Services (e.g., Notification Service, Email/SMS gateway)
6. Infrastructure (Docker containers via docker-compose, truststore for SSL/TLS)
b. Relationships & interactions:
- Mobile App ⇄ Backend REST API (HTTPS, JWT bearer tokens)
- Backend Security Layer intercepts requests → authenticates/authorizes via JWT and CustomUserDetailsService
- Controllers delegate to Services → business logic
- Services call Repositories → CRUD on DB
- FaceDetectionService loads Haarcascade via OpenCVConfig, uses camera capture data from mobile to detect & match face→ updates attendance record
- Flyway applies migrations at startup
- Docker-Compose orchestrates backend + DB containers
c. Architectural patterns & design principles:
- Layered architecture (presentation → service → repository)
- Dependency Injection (Spring)
- Single monolithic deployable service (no microservices yet)
- Security by design: JWT, HTTPS, truststore
- CI/CD via GitHub Actions (main.yml)
d. Key technologies & frameworks:
- React Native (front-end)
- Spring Boot, Spring Security, JWT
- OpenCV (face detection)
- Flyway (DB migrations)
- JPA/Hibernate
- Docker & Docker-Compose

##### Essential architectural elements to capture
- Layered package structure: config, controller, dto, entity, repository, service, exceptions
- JWT authentication flow and token storage (RefreshToken entity/repository)
- Face detection component (OpenCVConfig + haarcascade XML → FaceDetectionService → FaceDetectionRepository)
- Flyway migration scripts (V1, V2, V3)
- Dockerized deployment and CI pipeline

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile App
    subgraph "Mobile Application"
        direction TB
        MobileApp["React Native Mobile App"]:::frontend
    end

    %% Infrastructure
    subgraph "Infrastructure (Docker Compose)"
        direction TB
        BackendContainer["Spring Boot Backend"]:::infra
        Database[(PostgreSQL/MySQL)]:::db
    end

    %% CI/CD
    CI["GitHub Actions\n(.github/workflows/main.yml)"]:::ext

    %% Backend Layers
    subgraph BackendContainer
        direction TB
        FacedecApp["FacedecApplication"]:::app
        subgraph "Configuration"
            direction TB
            AppConfig["application.yml"]:::config
            Truststore["truststore.jks"]:::config
            Flyway["Flyway Migrations"]:::config
        end
        subgraph "Controllers"
            direction TB
            AuthController["AuthController"]:::controller
            UserController["UserController"]:::controller
            AttendanceController["AttendanceController"]:::controller
            FaceDetectionController["FaceDetectionController"]:::controller
            HealthController["HealthController"]:::controller
            OpenCVConfig["OpenCVConfig"]:::face
        end
        subgraph "Security"
            direction TB
            SecurityConfig["SecurityConfig"]:::config
            JWTFilter["JWTAuthenticationFilter"]:::config
            TokenProvider["JwtTokenProvider"]:::config
            UserDetails["CustomUserDetailsService"]:::config
            SecurityUtils["SecurityUtils"]:::config
        end
        subgraph "Services"
            direction TB
            AuthServiceImpl["AuthServiceImpl"]:::service
            AttendanceService["AttendanceService"]:::service
            FaceDetectionService["FaceDetectionService"]:::service
            EmployeeService["EmployeeService"]:::service
            UserService["UserService"]:::service
        end
        subgraph "Repositories"
            direction TB
            AttendanceRepo["AttendanceRepository"]:::repo
            FaceRepo["FaceDetectionRepository"]:::repo
            RefreshTokenRepo["RefreshTokenRepository"]:::repo
            RoleRepo["RoleRepository"]:::repo
            TokenRepo["TokenRepository"]:::repo
            UserRepo["UserRepository"]:::repo
        end
        subgraph "Entities & DTOs"
            direction TB
            Entities["Entities & DTOs\n(entity classes, dto packages)"]:::entity
            Exceptions["GlobalExceptionHandler & Exceptions"]:::exception
            Haarcascade["haarcascade_frontalface_default.xml"]:::face
        end
        %% Startup
        FacedecApp -->|loads| AppConfig
        AppConfig -->|initializes| Flyway
        Flyway -->|runs| Entities
        FacedecApp --> Config
        %% Controller flow
        MobileApp -->|HTTPS JWT| AuthController
        AuthController -->|POST /login| AuthServiceImpl
        AuthController -->|POST /register| AuthServiceImpl
        AuthController -->|POST /refresh| AuthServiceImpl
        AuthController -->|uses| RefreshTokenRepo
        UserController -->|CRUD Users| UserService
        AttendanceController -->|In/Out Logs| AttendanceService
        FaceDetectionController -->|Detect| FaceDetectionService
        FaceDetectionController -->|configures| OpenCVConfig
        HealthController -->|GET /health| FacedecApp
        %% Security flow
        AuthController -->|secured by| SecurityConfig
        SecurityConfig --> JWTFilter
        JWTFilter --> TokenProvider
        TokenProvider --> UserDetails
        UserDetails --> UserRepo
        %% Service to Repo
        AuthServiceImpl --> UserRepo
        AuthServiceImpl --> RoleRepo
        AttendanceService --> AttendanceRepo
        FaceDetectionService --> FaceRepo
        EmployeeService --> UserRepo
        UserService --> UserRepo
        %% Repo to DB
        AttendanceRepo --> Database
        FaceRepo --> Database
        RefreshTokenRepo --> Database
        RoleRepo --> Database
        TokenRepo --> Database
        UserRepo --> Database
        %% External Integrations
        subgraph "External Services"
            Notification["Notification Service\n(Email/SMS)"]:::ext
            ExternalHR["HR/Payroll Integration"]:::ext
        end
        AttendanceService --> Notification
        UserService --> Notification
        AttendanceService --> ExternalHR
        %% CI/CD
        CI -->|builds| FacedecApp
        CI -->|runs| Dockerfile
        CI -->|deploys| dockerCompose
    end

    %% Click Events
    click FacedecApp "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/FacedecApplication.java"
    click AppConfig "https://github.com/thetimemachine01/facedec/blob/main/src/main/resources/application.yml"
    click Flyway "https://github.com/thetimemachine01/facedec/blob/main/src/main/resources/db/migration/V1__Initial_Setup.sql"
    click Flyway "https://github.com/thetimemachine01/facedec/blob/main/src/main/resources/db/migration/V2__Add_Role_Column.sql"
    click Flyway "https://github.com/thetimemachine01/facedec/blob/main/src/main/resources/db/migration/V3__Add_CreatedAt_And_Tokens.sql"
    click AuthController "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/controller/Auth/AuthController.java"
    click UserController "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/controller/Auth/UserController.java"
    click AttendanceController "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/controller/AttendanceController.java"
    click FaceDetectionController "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/controller/Face/FaceDetectionController.java"
    click OpenCVConfig "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/controller/Face/OpenCVConfig.java"
    click HealthController "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/controller/HealthController.java"
    click SecurityConfig "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/config/SecurityConfig.java"
    click JWTFilter "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/config/JWTAuthenticationFilter.java"
    click TokenProvider "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/config/JwtTokenProvider.java"
    click UserDetails "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/config/CustomUserDetailsService.java"
    click SecurityUtils "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/config/SecurityUtils.java"
    click AuthServiceImpl "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/service/AuthServiceImpl.java"
    click AttendanceService "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/service/AttendanceService.java"
    click FaceDetectionService "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/service/FaceDetectionService.java"
    click EmployeeService "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/service/EmployeeService.java"
    click UserService "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/service/UserService.java"
    click AttendanceRepo "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/repository/AttendanceRepository.java"
    click FaceRepo "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/repository/FaceDetectionRepository.java"
    click RefreshTokenRepo "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/repository/RefreshTokenRepository.java"
    click RoleRepo "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/repository/RoleRepository.java"
    click TokenRepo "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/repository/TokenRepository.java"
    click UserRepo "https://github.com/thetimemachine01/facedec/blob/main/src/main/java/com/application/facedec/repository/UserRepository.java"
    click Haarcascade "https://github.com/thetimemachine01/facedec/blob/main/src/main/resources/haarcascade_frontalface_default.xml"
    click dockerCompose "https://github.com/thetimemachine01/facedec/blob/main/docker-compose.yml"
    click Dockerfile "https://github.com/thetimemachine01/facedec/tree/main/Dockerfile"
    click CI "https://github.com/thetimemachine01/facedec/blob/main/.github/workflows/main.yml"
    click pom "https://github.com/thetimemachine01/facedec/blob/main/pom.xml"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef infra fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32;
    classDef db fill:#FFF3E0,stroke:#EF6C00,color:#E65100;
    classDef config fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C;
    classDef controller fill:#E1F5FE,stroke:#0288D1,color:#01579B;
    classDef service fill:#E0F2F1,stroke:#00695C,color:#004D40;
    classDef repo fill:#FFFDE7,stroke:#F9A825,color:#F57F17;
    classDef entity fill:#FBE9E7,stroke:#BF360C,color:#D84315;
    classDef exception fill:#FFEBEE,stroke:#C62828,color:#B71C1C;
    classDef face fill:#FFF8E1,stroke:#FFB300,color:#FF8F00;
    classDef ext fill:#ECEFF1,stroke:#607D8B,color:#455A64;
    classDef app fill:#E3F2FD,stroke:#1976D2,color:#0D47A1;
```
