# sp25se148/fucapstone_fe architecture

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

- Interactive diagram: https://gitdiagram.com/sp25se148/fucapstone_fe
- Repository: https://github.com/sp25se148/fucapstone_fe

## Overview

##### Main Components
a. Next.js Frontend (Presentation Layer):
- Pages under src/app – grouped by roles (login, admin, manager, student, supervisor, superadmin).
- Layouts and common components (found under src/components/layout, src/components/ui) that are reused on many pages.
- Dynamic routing that drives the UI experience.
b. API Routes (Backend Layer within Next.js):
- API endpoints under src/app/api (e.g., authentication routes for login and logout) which handle server-side logic.
- Server middleware (e.g., middleware.ts) processing requests.
c. State and Business Logic:
- Multiple context providers under src/contexts for handling global states related to each domain (admin, manager, student, supervisor, superadmin).
- Custom hooks under src/hooks for API calls and responsiveness.
d. Utility and Shared Modules:
- Libraries under src/lib and src/utils – containing utility functions and services like "signalRService" for real-time communications.
- Configuration and theming elements under src/components/theme.
e. External Integrations:
- Next/font integration and any optimization services provided by Next.js.
- Deployment configuration shown by Next.js deployment instructions and setup (for instance Vercel).

##### Relationships and Data Flow
- The presentation layer (pages/components) interacts with the state management layer (contexts and hooks) to fetch and manage data.
- On user actions (for example, form submissions on the login page or admin dashboard interactions), the UI components make API calls to the Next.js API routes.
- Middleware and server-side routes ensure proper authentication and configuration.
- Shared UI components (buttons, tables, modals, etc.) are used across different domain areas, ensuring a cohesive user experience.
- The various contexts (found in src/contexts) encapsulate business logic for different roles and share data among components.
- SignalR (or similar real-time utility) integrates closely with the state management and API response cycle to deliver live updates.

##### Architectural Patterns and Design Principles
- Modular Structure: Clear separation by role and functionality helps in maintaining and scaling.
- Layered Architecture: Distinct separation between presentation (pages and components), business logic (contexts and hooks), and server-side processing (API routes and middleware).
- Reusability and DRY: Use of shared components (in src/components/ui) and global contexts to avoid duplicate code.
- Role-Based Segmentation: Different directories for admin, manager, student, etc., indicate a role-based access and navigation flow.

##### Relevant Technologies
- Next.js – for both server- and client-side rendering.
- React – core library for building user interfaces.
- Context API & Custom Hooks – for state management.
- Tailwind CSS – as indicated by tailwind.config.ts.
- ESLint & TypeScript – for code quality and type safety.
- Possibly SignalR integration for real-time communications (as suggested by src/contexts/signalR-context.tsx and src/utils/signalRService.ts).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Integrations
    subgraph "External Integrations"
        ex1("Next Configuration"):::external
        ex2("TypeScript Config"):::external
        ex3("Tailwind Config"):::external
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        p1("Login Page"):::presentation
        p2("Admin Pages"):::presentation
        p3("Manager Pages"):::presentation
        p4("Student Pages"):::presentation
        p5("Supervisor Pages"):::presentation
        p6("Superadmin Pages"):::presentation
        p7("Layout Components"):::presentation
        p8("UI Components"):::presentation
    end

    %% State & Business Logic
    subgraph "State & Business Logic"
        s1("Admin Context"):::state
        s2("Manager Context"):::state
        s3("Student Context"):::state
        s4("Supervisor Context"):::state
        s5("Superadmin Context"):::state
        s6("Custom Hooks: use-api"):::state
        s7("Custom Hooks: use-mobile"):::state
    end

    %% API Routes
    subgraph "API Routes"
        a1("API Endpoints"):::api
        a2("Auth Login API"):::api
        a3("Auth Logout API"):::api
        a4("Middleware"):::api
    end

    %% Utility & Shared Modules
    subgraph "Utility & Shared Modules"
        u1("Library & Utils"):::utility
        u2("SignalR Service"):::utility
        u3("Status Utils"):::utility
        u4("Theme Components"):::utility
    end

    %% Relationships - External Integrations to Others
    ex1 -->|"configures"| p7
    ex3 -->|"applies styling to"| u4

    %% Relationships within Presentation Layer
    p7 -->|"provides layout to"| p1
    p7 -->|"provides layout to"| p2
    p7 -->|"provides layout to"| p3
    p7 -->|"provides layout to"| p4
    p7 -->|"provides layout to"| p5
    p7 -->|"provides layout to"| p6

    p8 -->|"shared UI elements for"| p1
    p8 -->|"shared UI elements for"| p2
    p8 -->|"shared UI elements for"| p3
    p8 -->|"shared UI elements for"| p4
    p8 -->|"shared UI elements for"| p5
    p8 -->|"shared UI elements for"| p6

    %% Presentation to State & Business Logic
    p1 -->|"triggers API calls via"| s6
    p2 -->|"triggers API calls via"| s6
    p3 -->|"triggers API calls via"| s6
    p4 -->|"triggers API calls via"| s6
    p5 -->|"triggers API calls via"| s6
    p6 -->|"triggers API calls via"| s6

    %% State & Business Logic interactions with API Routes
    s6 -->|"calls"| a2
    s6 -->|"calls"| a3
    s6 -->|"communicates with"| a1

    %% API Routes to State & Business Logic update
    a1 -->|"updates"| s1
    a1 -->|"updates"| s2
    a1 -->|"updates"| s3
    a1 -->|"updates"| s4
    a1 -->|"updates"| s5

    %% Middleware handling API requests
    a4 -->|"manages"| a1

    %% Utility & Shared Modules relationships
    u1 -->|"provides functions to"| u2
    u1 -->|"provides functions to"| u3
    u2 -->|"real-time updates to"| s1
    u2 -->|"real-time updates to"| s2
    u2 -->|"real-time updates to"| s3
    u2 -->|"real-time updates to"| s4
    u2 -->|"real-time updates to"| s5
    u4 -->|"supports theming for"| p8

    %% Class definitions for colors
    classDef presentation fill:#d0e9ff,stroke:#333,stroke-width:2px;
    classDef api fill:#ffe0b3,stroke:#333,stroke-width:2px;
    classDef state fill:#d5f5e3,stroke:#333,stroke-width:2px;
    classDef utility fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#333,stroke-width:2px;

    %% Click Events - Presentation Layer
    click p1 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/(login-page)"
    click p2 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/admin"
    click p3 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/manager"
    click p4 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/student"
    click p5 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/supervisor"
    click p6 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/superadmin"
    click p7 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/components/layout"
    click p8 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/components/ui"

    %% Click Events - API Routes
    click a1 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/app/api"
    click a2 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/app/api/auth/login/route.ts"
    click a3 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/app/api/auth/logout/route.ts"
    click a4 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/middleware.ts"

    %% Click Events - State & Business Logic
    click s1 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/contexts/admin"
    click s2 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/contexts/manager"
    click s3 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/contexts/student"
    click s4 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/contexts/supervisor"
    click s5 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/contexts/superadmin"
    click s6 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/hooks/use-api.ts"
    click s7 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/hooks/use-mobile.tsx"

    %% Click Events - Utility & Shared Modules
    click u1 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/lib"
    click u2 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/utils/signalRService.ts"
    click u3 "https://github.com/sp25se148/fucapstone_fe/blob/main/src/utils/statusUtils.tsx"
    click u4 "https://github.com/sp25se148/fucapstone_fe/tree/main/src/components/theme"

    %% Click Events - External Integrations
    click ex1 "https://github.com/sp25se148/fucapstone_fe/blob/main/next.config.ts"
    click ex2 "https://github.com/sp25se148/fucapstone_fe/blob/main/tsconfig.json"
    click ex3 "https://github.com/sp25se148/fucapstone_fe/blob/main/tailwind.config.ts"
```
