# yeasin2002/sugary-react-recruitment architecture

> Architecture diagram of the GitHub repository yeasin2002/sugary-react-recruitment, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yeasin2002/sugary-react-recruitment
- Repository: https://github.com/yeasin2002/sugary-react-recruitment

## Overview

##### Project type and purpose
- This is a single-page frontend application built with Next.js and Tailwind CSS.
- Purpose: a recruitment task for “Sugary,” featuring login/authentication, a protected dashboard with infinite-scrolling material listings, and responsive UI interactions.

##### File structure
- Top-level: Next.js config files (next.config.js, tsconfig.json), package.json, public/assets, and core folders:
- app/ – Next.js App Router pages (auth, dashboard, homepage, layout, providers)
- components/ – UI components grouped by feature (dashboard, homepage, shared, ui)
- lib/ – shared utilities (API client, auth context, types, helpers)
- hooks/ – custom React hooks (debounce, intersection observer, toast)
- helper/ and data/ – data-fetching helpers and type definitions
- assets/, fonts/, public/ – static resources
- Configuration: axios interceptors for token refresh, Tailwind + PostCSS, eslint, bun.lock.

##### README for additional insights
- Uses authentication with access & refresh tokens (via Axios interceptors)
- Protected routes under /dashboard (guarded by auth-context)
- Infinite scroll for material list (lazy loading with intersection observer)
- Integration with external APIs: AdminAccount/Login, Account/RefreshToken, Materials/GetAll, plus image CDN.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Browser / Client"]:::client

    %% Next.js App Router
    subgraph "Next.js App Router"
        RootLayout["Root Layout"]:::framework
        AuthLayout["Auth Layout"]:::framework
        DashboardLayout["Dashboard Layout"]:::framework
        LoginPage["Login Page"]:::framework
        RegisterPage["Register Page"]:::framework
        DashboardMain["Dashboard Main Page"]:::framework
        DashboardProfile["Dashboard Profile Page"]:::framework
        HomepagePage["Homepage"]:::framework
    end

    Browser --> HomepagePage
    Browser --> LoginPage
    Browser --> RegisterPage
    Browser --> DashboardLayout

    HomepagePage --> HomepageIndex
    LoginPage --> AuthContext
    RegisterPage --> AuthContext
    DashboardLayout --> AuthGuard
    DashboardLayout --> DashboardHeader
    DashboardLayout --> AppProviders
    AuthGuard --> LoginPage
    DashboardLayout --> DashboardMain
    DashboardMain --> MaterialsList
    DashboardMain --> DashboardHeader
    DashboardMain --> MaterialCard
    DashboardMain --> MaterialsSkeleton

    %% UI Component Layer
    subgraph "UI Component Layer"
        subgraph "Dashboard Components"
            MaterialCard["Material Card"]:::ui
            MaterialsList["Materials List"]:::ui
            MaterialsSkeleton["Materials Skeleton Loader"]:::ui
        end
        subgraph "Homepage Components"
            AnimatedGroup["Animated Group"]:::ui
            HeroHeaders["Hero Headers"]:::ui
            HeroProductShow["Hero Product Showcase"]:::ui
            TextEffect["Text Effect"]:::ui
            HomepageIndex["Homepage Index"]:::ui
        end
        subgraph "Shared Components"
            DashboardHeader["Dashboard Header"]:::ui
            Logo["Logo"]:::ui
            ThemeSwitcher["Theme Switcher"]:::ui
        end
        subgraph "UI Primitives"
            Button["Button"]:::ui
            Card["Card"]:::ui
            Input["Input"]:::ui
            Skeleton["Skeleton"]:::ui
            ToastUI["Toast"]:::ui
        end
    end

    HomepageIndex --> AnimatedGroup
    HomepageIndex --> HeroHeaders
    HomepageIndex --> HeroProductShow
    HomepageIndex --> TextEffect
    MaterialsList --> MaterialsSkeleton
    MaterialsList --> MaterialCard

    %% Custom Hooks
    MaterialsList --> useIntersectionObserver
    MaterialsList --> useDebounce
    subgraph "Custom Hooks"
        useDebounce["useDebounce"]:::logic
        useIntersectionObserver["useIntersectionObserver"]:::logic
        useToast["useToast"]:::logic
    end

    %% State & Context Layer
    subgraph "State & Context Layer"
        AuthContext["AuthContext"]:::logic
        AppProviders["App Providers"]:::logic
        AuthGuard["Auth Guard"]:::logic
    end

    AuthContext --> AxiosClient
    AppProviders --> ThemeSwitcher
    AppProviders --> ToastUI

    %% Data-fetching Layer
    subgraph "Data-fetching Layer"
        AxiosClient["axiosClient + interceptors"]:::data
        ApiEndpoints["API Endpoints Definitions"]:::data
        FetchMaterialsHelper["Materials Fetch Helper"]:::data
        FetchWithFilters["Filtered Fetch Action"]:::data
    end

    AxiosClient --> AuthAPI
    AxiosClient --> MaterialsAPI
    AxiosClient -->|on 401| AuthAPI
    AuthContext -->|login, refresh| AxiosClient
    MaterialsList --> FetchMaterialsHelper
    FetchMaterialsHelper --> AxiosClient
    FetchMaterialsHelper --> ApiEndpoints
    FetchWithFilters --> AxiosClient
    FetchWithFilters --> ApiEndpoints

    %% Utilities & Types
    subgraph "Utilities & Types"
        TypesDefs["Type Definitions"]:::util
        GetImg["Image URL Helper"]:::util
        Utils["General Utilities"]:::util
    end

    MaterialsList --> GetImg

    %% Static Assets & Configuration
    subgraph "Static Assets & Config"
        GlobalsCSS["Global Styles"]:::config
        TailwindConfig["Tailwind Config"]:::config
        PostCSSConfig["PostCSS Config"]:::config
        PublicAssets["Public Assets"]:::config
        NextConfig["Next.js Config"]:::config
        TSConfig["TypeScript Config"]:::config
        ESLintConfig["ESLint Config"]:::config
    end

    RootLayout --> GlobalsCSS
    RootLayout --> TailwindConfig
    RootLayout --> PostCSSConfig
    RootLayout --> PublicAssets
    RootLayout --> NextConfig
    RootLayout --> TSConfig
    RootLayout --> ESLintConfig

    %% External Systems
    subgraph "External Systems"
        AuthAPI["Auth API (Login, RefreshToken)"]:::external
        MaterialsAPI["Materials API (GetAll)"]:::external
        ImageCDN["Image CDN"]:::external
    end

    MaterialsList -->|fetch images| ImageCDN

    %% Click Events
    click RootLayout "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/layout.tsx"
    click AuthLayout "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/(auth)/layout.tsx"
    click DashboardLayout "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/dashboard/layout.tsx"
    click LoginPage "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/(auth)/login/page.tsx"
    click RegisterPage "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/(auth)/register/page.tsx"
    click DashboardMain "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/dashboard/page.tsx"
    click DashboardProfile "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/dashboard/profile/page.tsx"
    click HomepagePage "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/page.tsx"
    click AuthGuard "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/(auth)/auth-guard.tsx"
    click AuthContext "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/lib/auth-context.tsx"
    click AppProviders "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/providers.tsx"
    click AxiosClient "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/lib/axiosClient.ts"
    click ApiEndpoints "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/lib/api.ts"
    click FetchMaterialsHelper "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/helper/fetch-materials.ts"
    click FetchWithFilters "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/actions/fetchMaterialsWithFilters.ts"
    click MaterialCard "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/dashboard/material-card.tsx"
    click MaterialsList "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/dashboard/materials-list.tsx"
    click MaterialsSkeleton "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/dashboard/materials-skeleton.tsx"
    click AnimatedGroup "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/homepage/animated-group.tsx"
    click HeroHeaders "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/homepage/hero-headers.tsx"
    click HeroProductShow "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/homepage/hero-product-show.tsx"
    click TextEffect "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/homepage/text-effect.tsx"
    click HomepageIndex "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/homepage/index.ts"
    click DashboardHeader "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/shared/dashboard-header.tsx"
    click Logo "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/shared/logo.tsx"
    click ThemeSwitcher "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/components/shared/theme-switcher.tsx"
    click useDebounce "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/hooks/use-debounce.ts"
    click useIntersectionObserver "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/hooks/use-intersection-observer.ts"
    click useToast "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/hooks/use-toast.ts"
    click TypesDefs "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/lib/types.ts"
    click GetImg "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/lib/getImg.ts"
    click Utils "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/lib/utils.ts"
    click GlobalsCSS "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/app/globals.css"
    click TailwindConfig "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/tailwind.config.ts"
    click PostCSSConfig "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/postcss.config.js"
    click PublicAssets "https://github.com/yeasin2002/sugary-react-recruitment/tree/main/public/"
    click NextConfig "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/next.config.js"
    click TSConfig "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/tsconfig.json"
    click ESLintConfig "https://github.com/yeasin2002/sugary-react-recruitment/blob/main/.eslintrc.json"

    %% Styles
    classDef client fill:#E3F2FD,stroke:#2196F3
    classDef framework fill:#E8F5E9,stroke:#4CAF50
    classDef ui fill:#E1F5FE,stroke:#0288D1
    classDef logic fill:#FFF3E0,stroke:#FB8C00
    classDef data fill:#F3E5F5,stroke:#8E24AA
    classDef util fill:#ECEFF1,stroke:#546E7A
    classDef config fill:#F1F8E9,stroke:#7CB342
    classDef external fill:#ECEFF1,stroke:#B0BEC5,stroke-dasharray: 5 5
```
