# cloud-native-group-1/leave-n-attendance-frontend architecture

> Architecture diagram of the GitHub repository cloud-native-group-1/leave-n-attendance-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cloud-native-group-1/leave-n-attendance-frontend
- Repository: https://github.com/cloud-native-group-1/leave-n-attendance-frontend

## Overview

##### Project type and purpose
- This is a full-stack Next.js web application for leave and attendance management (frontend + serverless backend/API calls).
- It offers features such as leave requests, attendance tracking, team monitoring, notifications, and reports.

##### File structure
- **app/** – Next.js “app” directory (layouts, pages, SSR/SSG routes).
- **components/** – Reusable UI components (dialogs, tables, charts, sidebar, UI primitives under ui/).
- **hooks/** – Custom React hooks (e.g., use-auth, use-mobile).
- **lib/services/** – API client layer (calendar, leave-request, user, team, notifications, etc.).
- **ci/cd files** – GitHub Actions workflows, Dockerfile, Vercel/Cloud Run config.
- **tests/** – Unit tests (Jest) and end-to-end tests (Playwright).

##### README insights
- CI: Jest unit tests, Playwright E2E tests, GitHub Actions.
- CD: Vercel auto-deploy on main, Docker + Cloud Run.
- No direct DB logic in the repo (assumes backend APIs are external or serverless).

a. **Client (Browser)**
- Users interact via browser, mobile, or desktop.
b. **Next.js Frontend**
- Pages and layouts under app/, renders UI.
- Uses components/ and hooks/ for client-side logic.
- Server-side rendering and API routes (if any).
c. **API Client Layer**
- lib/services/*: fetch wrappers for REST endpoints.
- lib/api.ts: central HTTP client.
d. **External Backend / REST API**
- Hosted elsewhere or via Cloud Run.
- Implements business logic, persistence, authentication.
e. **Database & Auth**
- May be a managed Postgres/MongoDB, plus an auth provider (e.g., NextAuth or OAuth).
f. **CI/CD Pipeline**
- GitHub Actions running Jest and Playwright.
- Docker build for Cloud Run, Vercel deployment.

##### Relationships & data flow
- Browser → Next.js Frontend (SSR/CSR)
- Next.js Frontend → lib/services → External REST API
- REST API ↔ Database
- REST API ↔ Auth Service
- CI systems push to repositories → GitHub Actions → tests → build → deployment to Vercel/Cloud Run

##### Architectural patterns & design principles
- **Separation of concerns**: UI (components/) vs. Data fetching (lib/services) vs. State (hooks/)
- **Server-side rendering (SSR)** for initial page loads, **client-side navigation** for speed
- **API client abstraction layer** for testability and reuse
- **Modular UI** via atomic “ui/” primitives and higher-order components

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Client Layer"
        direction TB
        Browser["Browser / Mobile / Desktop"]:::frontend
        NextJS["Next.js Frontend"]:::frontend
        Pages["Pages & Layouts (app/)"]:::frontend
        UI["UI Components (components/)"]:::frontend
        HooksAuth["use-auth.tsx"]:::frontend
        HooksMobile["use-mobile.tsx"]:::frontend
    end

    subgraph "Data Layer"
        direction TB
        APIClient["lib/api.ts"]:::backend
        Services["Service Wrappers (lib/services/)"]:::backend
    end

    subgraph "Server / Infrastructure"
        direction TB
        RestAPI["External REST API"]:::backend
        Database["Database"]:::backend
        AuthService["Auth Provider"]:::backend
    end

    subgraph "DevOps & CI/CD"
        direction TB
        Repo["GitHub Repo"]:::devops
        GHActions["GitHub Actions"]:::devops
        JestPW["Jest & Playwright Tests"]:::devops
        DockerFiles["Dockerfile / Dockerfile.test"]:::devops
        Deploy["Vercel & Cloud Run"]:::devops
    end

    Browser -->|Interacts with| NextJS
    NextJS --> Pages
    NextJS --> UI
    NextJS --> HooksAuth
    NextJS --> HooksMobile

    NextJS --> APIClient
    NextJS --> Services
    APIClient --> Services

    Services --> RestAPI
    RestAPI --> Database
    RestAPI --> AuthService

    Repo --> GHActions
    GHActions --> JestPW
    GHActions --> DockerFiles
    DockerFiles --> Deploy
    GHActions --> Deploy

    click Pages "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/tree/main/app/"
    click UI "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/tree/main/components/"
    click HooksAuth "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/hooks/use-auth.tsx"
    click HooksMobile "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/hooks/use-mobile.tsx"
    click APIClient "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/lib/api.ts"
    click Services "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/tree/main/lib/services/"
    click Repo "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/README.md"
    click GHActions "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/.github/workflows/jest.yml"
    click GHActions "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/.github/workflows/playwright.yml"
    click DockerFiles "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/tree/main/Dockerfile"
    click Deploy "https://github.com/cloud-native-group-1/leave-n-attendance-frontend/blob/main/.github/workflows/deploy-to-cloud-run.yml"

    classDef frontend fill:#E0F7FA,stroke:#036B83,color:#000;
    classDef backend fill:#E8F5E9,stroke:#2E7D32,color:#000;
    classDef devops fill:#ECEFF1,stroke:#546E7A,color:#000;
```
