# kentrpg/assist-hub architecture

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

- Interactive diagram: https://gitdiagram.com/kentrpg/assist-hub
- Repository: https://github.com/kentrpg/assist-hub

## Overview

##### Main components
- Frontend/UI Layer:
- Consists primarily of Next.js pages (found under the pages/ directory) and reusable UI components (located in components/ and components/ui/ directories).
- Contains presentational and container elements for various user experiences (e.g., Home, Product, Cart, Inquiry, Admin, and User profiles).
- API Layer (Server Side within Next.js):
- Located under pages/api/ where various endpoints exist (authentication, admin operations, member details, payment confirmation, etc.).
- Acts as an intermediary between the frontend and external services/back-end systems.
- State Management & Utilities:
- Redux toolkit (utils/redux/) and custom hooks (hooks/) form a crucial part of the application’s state and business logic.
- Helper utilities (under utils/ and helpers/) facilitate API communications, data formatting, and error handling.
- Integration with External Services:
- Third-party integrations such as LINE Login, LINE Pay, and LINE Messaging are supported; these should be indicated as external components.
- Backend (External):
- Although not present in the code repository, the README indicates a back-end built with C# (.NET Framework) and Microsoft SQL Server hosted on Azure VM. This external service is responsible for handling persistent data and processing business logic (orders, inquiries, etc.).

##### Relationships and interactions
- The Client UI (Next.js pages/components) communicates user actions to the API routes.
- API routes perform server-side logic (using middleware, validations, and integration with Redux actions) and relay data between the frontend and the external back-end (e.g., via RESTful API calls).
- Utility functions, helper methods, and custom hooks act as bridges for formatting data, managing state changes, and enforcing authentication.
- External services (LINE Login/Pay/Messaging) are integrated into both the frontend (for initiating interactions) and back-end workflows (for payment confirmation and notifications).

##### Architectural patterns and design principles
- Separation of concerns is well demonstrated with distinct directories for UI components, API endpoints, state management, and styling.
- The MVC-like separation between presentational components (UI), container components (pages with layout and data bindings), and business logic (API routes & helpers) is clear.
- Emphasis on reusability and modularity – each component folder contains its code, styling, and data.
- The Git Flow practices enforce disciplined version control.

##### Relevant technologies
- Frontend: Next.js, React, TypeScript, styled-components, React Hook Form, Redux Toolkit.
- API: Next.js API routes acting as a middle-tier layer.
- External Integrations: LINE API services (Login, Pay, Messaging).
- Backend: C# (.NET), MSSQL, hosted on Azure.
- Auxiliary Tools: ESLint, Prettier, and design assets (Figma, Miro).

##### Specific elements
- UI Components/Pages (indicate routes like Home, Product, Cart, Inquiry, Admin, User Profile)
- API Layer / Next.js API routes
- State Management (Redux Store and associated slices)
- External Backend (C# Web API and MSSQL database)
- Third-party Integration (LINE Login, LINE Pay, LINE Messaging)
- From UI to API when a user performs an action (e.g., orders or submits an inquiry)
- From API to External Backend for data retrieval and updates
- From API (or UI) to external services for payment authentication or notifications.
- Optionally, add annotations for technologies or responsibilities (e.g., “Handles form validations using React Hook Form”, “Manages state with Redux Toolkit”).

## Diagram (Mermaid)

```mermaid
graph TD
    %% User
    U("User (Browser)"):::user

    %% Frontend/UI Layer subgraph
    subgraph "Frontend/UI Layer"
        NP("Next.js Pages"):::frontend
        UC("UI Components"):::frontend
    end

    %% API Layer subgraph
    subgraph "API Layer"
        API("Next.js API Endpoints"):::api
    end

    %% State Management & Utilities subgraph
    subgraph "State Management & Utilities"
        RT("Redux Toolkit"):::utilities
        CH("Custom Hooks"):::utilities
        HU("Helper Utilities"):::utilities
    end

    %% Third-Party Integration subgraph
    subgraph "Third-Party Integration"
        LAPI("LINE API Endpoints"):::integration
        LAU("LINE API Utilities"):::integration
    end

    %% External Backend
    EB("External Backend (.NET & MSSQL)"):::external

    %% Data Flow
    U -->|"Interacts"| NP
    U -->|"Interacts"| UC

    NP -->|"Fetches Data"| API
    UC -->|"Manages State"| RT
    UC -->|"Uses Hooks"| CH

    API -->|"Calls External"| EB
    API -->|"LINE Integration"| LAPI
    API -->|"LINE Integration"| LAU

    %% Utilities support API and UI
    RT ---|"State Management"| NP
    CH ---|"Enhances UI"| NP
    HU ---|"Formats/Handles"| API

    %% Click Events
    click NP "https://github.com/kentrpg/assist-hub/tree/main/pages/"
    click UC "https://github.com/kentrpg/assist-hub/tree/main/components/"
    click API "https://github.com/kentrpg/assist-hub/tree/main/pages/api/"
    click RT "https://github.com/kentrpg/assist-hub/tree/main/utils/redux/"
    click CH "https://github.com/kentrpg/assist-hub/tree/main/hooks/"
    click HU "https://github.com/kentrpg/assist-hub/tree/main/helpers/"
    click LAPI "https://github.com/kentrpg/assist-hub/tree/main/pages/api/line/"
    click LAU "https://github.com/kentrpg/assist-hub/tree/main/utils/api/line/"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef api fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef utilities fill:#f8bbd0,stroke:#c2185b,stroke-width:2px;
    classDef integration fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef external fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef user fill:#ffab91,stroke:#d84315,stroke-width:2px;
```
