# rayjaywolf/newera architecture

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

- Interactive diagram: https://gitdiagram.com/rayjaywolf/newera
- Repository: https://github.com/rayjaywolf/newera

## Overview

##### Main Components
- Frontend (Client UI):
– Represented by the Next.js pages found in the “app” directory (with segregated areas like admin, projects, sign-in, etc.).
– Includes public-facing pages (e.g., main landing page, sign-up, sign-in) as well as admin and project-specific dashboards (pages under “app/admin” and “app/projects”).
- Backend/API Layer:
– The “app/api” directory contains numerous serverless API routes handling CRUD operations and business logic for attendance, workers, projects, machinery, materials, and image uploads.
- Business Logic & Services:
– Shared functionality is located under “lib” (with modules for AWS config, face recognition, ID generators, and Prisma integration) and “utils”.
– “hooks” provide additional client-side behavior, such as mobile support and toast notifications.
- Database:
– Use of Prisma is indicated by “prisma/schema.prisma” and related files in “lib/prisma” and “utils/db.” This points to a relational database at the backend.
- External Integrations:
– The presence of AWS configuration in “lib/aws-config.ts” and a dedicated “face-recognition” module suggests integration with an external face recognition service.
- UI Components:
– The “components” folder hosts a wide range of UI elements, from basic UI primitives to complex components like image viewers, project sidebars, advanced dialogs, and various charts and tables.

##### Relationships and Interactions
- The Client UI (browser) interacts with:
– Next.js pages that render various views (admin dashboards, projects, etc.).
– API endpoints for dynamic data and CRUD operations.
- API Endpoints:
– Directly map to serverless function routes in “app/api/*”.
– They handle data requests from frontend pages, transform data via the business logic provided in “lib” and “utils,” and then interact with the database.
- Backend Services:
– Modules like “face-recognition.ts” in “lib” take inputs from API endpoints (for example, when a worker’s attendance data requires facial recognition) and may also interact with external systems (AWS services).
- Database:
– The middleware (e.g., Prisma files) manages database interactions.
- UI Components and Hooks:
– All reusable and common UI fragments are in “components” and “hooks” and are utilized across both the frontend pages and possibly within dynamically rendered admin or project views.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
– The project is clearly split into UI (app directory and components), API logic (app/api), and business logic (lib and utils).
- File-System Based Routing:
– Next.js’s designated structure in “app” and “app/api” domains defines the routing, benefiting from clear and predictable URL structures.
- Serverless Architecture:
– API endpoints (each as an individual route.ts file) are designed to be stateless and could map directly to serverless functions on deployment platforms like Vercel.
- Modular Design:
– Shared logic and utilities (e.g., authentication, role management in “utils/roles.ts”) promote reusability and maintainability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend (Client UI)
    subgraph "Frontend (Client UI)"
        A1["Next.js Pages (app)"]:::frontend
        A2["Admin Pages (app/admin)"]:::frontend
        A3["Project Pages (app/projects)"]:::frontend
        A4["Auth Pages (app/sign-in, app/sign-up)"]:::frontend
        A7["UI Components (components)"]:::components
        A8["Custom Hooks (hooks)"]:::hooks
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        B1["Attendance API (app/api/attendance)"]:::api
        B2["Verify Attendance API (app/api/attendance/verify/route.ts)"]:::api
        B3["Admin API (app/api/admin)"]:::api
        B4["Projects API (app/api/projects)"]:::api
        B5["Machinery & Materials API (app/api/machinery & app/api/materials)"]:::api
        B6["Workers API (app/api/workers)"]:::api
        B7["Image Upload API (app/api/uploadImage/route.ts)"]:::api
    end

    %% Business Logic & Services
    subgraph "Business Logic & Services"
        C1["AWS Config (lib/aws-config.ts)"]:::logic
        C2["Face Recognition Service (lib/face-recognition.ts)"]:::logic
        C3["ID & Prisma Integration (lib/id-generators.ts, lib/prisma.ts)"]:::logic
        C4["Utilities (lib/utils.ts, lib/utils/materials.ts)"]:::logic
        C5["Roles Utils (utils/roles.ts)"]:::logic
        C6["DB Helpers (utils/db.ts)"]:::logic
    end

    %% Database
    subgraph "Database"
        D1["Prisma DB (prisma/schema.prisma)"]:::database
    end

    %% External Integrations
    subgraph "External Integrations"
        E1["AWS/Face Recognition External"]:::external
    end

    %% Connections from Frontend to API Layer
    A1 -->|"fetchData"| B1
    A1 -->|"fetchData"| B3
    A1 -->|"fetchData"| B4
    A1 -->|"fetchData"| B5
    A1 -->|"fetchData"| B6
    A1 -->|"upload"| B7
    A2 -->|"adminFetch"| B3
    A3 -->|"projectFetch"| B4
    A4 -->|"authRequest"| B3

    %% Connections from API Layer to Business Logic & Services
    B1 -->|"process"| C2
    B1 -->|"process"| C3
    B2 -->|"process"| C3
    B3 -->|"process"| C4
    B4 -->|"process"| C3
    B5 -->|"process"| C3
    B6 -->|"process"| C3
    B7 -->|"process"| C3

    %% Connections from Business Logic & Services to Database
    C3 -->|"dbQuery"| D1
    C6 -->|"helper"| D1
    C5 -->|"roleCheck"| D1

    %% Connection from Business Logic to External Integration
    C2 -->|"externalCall"| E1

    %% Associations inside Frontend for Components and Hooks
    A1 ---|"uses"| A7
    A1 ---|"uses"| A8

    %% Click Events for Frontend
    click A1 "https://github.com/rayjaywolf/newera/tree/main/app"
    click A2 "https://github.com/rayjaywolf/newera/blob/main/app/admin/page.tsx"
    click A2 "https://github.com/rayjaywolf/newera/blob/main/app/admin/attendance/page.tsx"
    click A2 "https://github.com/rayjaywolf/newera/blob/main/app/admin/workers/page.tsx"
    click A3 "https://github.com/rayjaywolf/newera/blob/main/app/projects/page.tsx"
    click A3 "https://github.com/rayjaywolf/newera/blob/main/app/projects/[id]/page.tsx"
    click A4 "https://github.com/rayjaywolf/newera/tree/main/app/sign-in"
    click A4 "https://github.com/rayjaywolf/newera/tree/main/app/sign-up"
    click A7 "https://github.com/rayjaywolf/newera/tree/main/components"
    click A8 "https://github.com/rayjaywolf/newera/tree/main/hooks"

    %% Click Events for Backend/API Layer
    click B1 "https://github.com/rayjaywolf/newera/tree/main/app/api/attendance"
    click B2 "https://github.com/rayjaywolf/newera/blob/main/app/api/attendance/verify/route.ts"
    click B3 "https://github.com/rayjaywolf/newera/blob/main/app/api/admin/attendance/route.ts"
    click B3 "https://github.com/rayjaywolf/newera/blob/main/app/api/admin/faces/route.ts"
    click B4 "https://github.com/rayjaywolf/newera/tree/main/app/api/projects"
    click B5 "https://github.com/rayjaywolf/newera/blob/main/app/api/machinery/usage/route.ts"
    click B5 "https://github.com/rayjaywolf/newera/blob/main/app/api/materials/route.ts"
    click B6 "https://github.com/rayjaywolf/newera/blob/main/app/api/workers/index-face/route.ts"
    click B6 "https://github.com/rayjaywolf/newera/blob/main/app/api/workers/delete-face/route.ts"
    click B7 "https://github.com/rayjaywolf/newera/blob/main/app/api/uploadImage/route.ts"

    %% Click Events for Business Logic & Services
    click C1 "https://github.com/rayjaywolf/newera/blob/main/lib/aws-config.ts"
    click C2 "https://github.com/rayjaywolf/newera/blob/main/lib/face-recognition.ts"
    click C3 "https://github.com/rayjaywolf/newera/blob/main/lib/id-generators.ts"
    click C3 "https://github.com/rayjaywolf/newera/blob/main/lib/prisma.ts"
    click C4 "https://github.com/rayjaywolf/newera/blob/main/lib/utils.ts"
    click C4 "https://github.com/rayjaywolf/newera/blob/main/lib/utils/materials.ts"
    click C5 "https://github.com/rayjaywolf/newera/blob/main/utils/roles.ts"
    click C6 "https://github.com/rayjaywolf/newera/blob/main/utils/db.ts"

    %% Click Event for Database
    click D1 "https://github.com/rayjaywolf/newera/blob/main/prisma/schema.prisma"

    %% Click Event for External Integrations
    click E1 "https://github.com/rayjaywolf/newera/blob/main/lib/aws-config.ts"

    %% Styles
    classDef frontend fill:#FFF3CD,stroke:#856404,stroke-width:2px;
    classDef api fill:#CCE5FF,stroke:#004085,stroke-width:2px;
    classDef logic fill:#D4EDDA,stroke:#155724,stroke-width:2px;
    classDef database fill:#F8D7DA,stroke:#721C24,stroke-width:2px;
    classDef external fill:#F5C6CB,stroke:#721C24,stroke-width:2px;
    classDef components fill:#E2E3E5,stroke:#6C757D,stroke-width:2px;
    classDef hooks fill:#D1ECF1,stroke:#0C5460,stroke-width:2px;
```
