# nectworks/nextjs-client architecture

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

- Interactive diagram: https://gitdiagram.com/nectworks/nextjs-client
- Repository: https://github.com/nectworks/nextjs-client

## Overview

##### Project type and purpose
- This is a Next.js-based client (frontend) repository ("nextjs-client") that implements the user interface for a larger application.
- It serves as a Single Page Application (SPA) with server-side rendering (SSR) and client-side routing, providing pages for home, blog, user profiles, admin panel, authentication flows (Google, LinkedIn), dashboard, and utilities for handling file operations, HTTP requests, and UI helpers.

##### File structure
- Top-level directories:
- app/           ← Next.js “app” directory containing pages and layouts
- _components/  ← shared UI components (Header, Footer, Profile widgets, Popups, ProtectedRoute, etc.)
- Utils/        ← utility functions (file checks, downloads, formatting, analytics events, private axios hook)
- config/       ← axiosInstance.js for base API configuration
- context/      ← React Context providers (UserContext, AdminUserContext, DashboardContext, ProfileContext)
- hooks/        ← custom React hooks (useGoogleIdentity)
- lib/          ← static assets helpers (font loader)
- public/       ← static files (images, fonts, pre-rendered HTML snapshots)
- Framework-specific files: next.config.mjs, middleware.js, jsconfig.json
- Tools: ESLint, Prettier, package.json

##### Extract insights from the README
- Confirms this is the “frontend code for our application, built with Next.js.”
- No backend code in this repo; communicates with external API servers (via Axios).

##### Main components & interactions
a. Components
- Browser / User Agent
- Next.js app (Node.js SSR and routing)
- Pages (app/…): Home, Blog, Profile, Dashboard, Admin Panel, Authentication flows, Static pages (About, FAQ, T&C, etc.)
- Shared Components (_components): Header, Footer, Profile sub-components, Menus, Popups, ProtectedRoute
- State Management (context/): UserContext, AdminUserContext, DashboardContext, ProfileContext + custom hooks
- HTTP Layer (config/axiosInstance + Utils/usePrivateAxios)
- Utilities (Utils/): file, UI, analytics, scroll, messaging
- Static Assets (public/, lib/font)
- Third-party services:
- Authentication providers (Google Identity, LinkedIn OAuth)
- Backend API server (REST endpoints)
- Analytics/GA

b. Relationships & data flows
1. User → Browser UI → Next.js routing → Renders appropriate Page component
2. Page component uses Shared Components and Context Providers for global state
3. Shared Components dispatch actions or read state from Context
4. Page/Component makes HTTP calls via axiosInstance or usePrivateAxios → Backend API
5. Authentication flows redirect to Google/LinkedIn → OAuth providers → redirect back to /google/auth-redirect or /linkedin/auth-redirect
6. Utilities support local functions (file downloads, formatting), and event tracking (gaEvents)

c. Architectural patterns & design principles
- Component-based architecture (Next.js App Router)
- Separation of concerns:
– Pages handle layout & data fetching
– _components for reusable UI
– context for global state
– Utils for pure helper functions
– config for HTTP config
- SSR/SSG and client-side hydration via Next.js
- ProtectedRoute guarding authenticated pages
- Custom hooks for encapsulating logic (e.g., useGoogleIdentity)

d. Key technologies & libraries
- Next.js (App Router, server & client components)
- React Context & Hooks
- Axios for HTTP
- CSS Modules / global CSS (globals.css)
- Prettier, ESLint for code quality
- OAuth Integration (Google, LinkedIn)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    User["User/Browser"]:::external
    User -->|"interacts with"| Router

    %% Next.js App Router & Layout
    Router["Next.js App Router & Layout"]:::pages
    click Router "https://github.com/nectworks/nextjs-client/blob/main/app/layout.js"
    click Router "https://github.com/nectworks/nextjs-client/blob/main/app/(root)/layout.js"

    %% Public Pages
    subgraph "Public Pages" 
        Home["Home Page"]:::pages
        BlogList["Blog List Page"]:::pages
        BlogDetail["Blog Detail Page"]:::pages
        ProfilePublic["Profile Public Page"]:::pages
        Home -->|"uses"| Router
        BlogList -->|"uses"| Router
        BlogDetail -->|"uses"| Router
        ProfilePublic -->|"uses"| Router
    end
    click Home "https://github.com/nectworks/nextjs-client/blob/main/app/(root)/home/page.js"
    click Home "https://github.com/nectworks/nextjs-client/blob/main/app/(root)/home/HomeMain.js"
    click BlogList "https://github.com/nectworks/nextjs-client/blob/main/app/(root)/blog/blogList.js"
    click BlogDetail "https://github.com/nectworks/nextjs-client/blob/main/app/(root)/blog/[blogId]/page.js"
    click BlogList "https://github.com/nectworks/nextjs-client/blob/main/app/(root)/blog/page.js"
    click ProfilePublic "https://github.com/nectworks/nextjs-client/blob/main/app/profile/page.js"
    click ProfilePublic "https://github.com/nectworks/nextjs-client/blob/main/app/profile/[username]/page.js"

    %% Dashboard Pages
    subgraph "Dashboard Pages"
        DashboardJob["Dashboard Job Page"]:::pages
        DashboardProfile["Dashboard Profile Page"]:::pages
        DashboardRefer["Dashboard Refer Page"]:::pages
    end
    click DashboardJob "https://github.com/nectworks/nextjs-client/blob/main/app/dashboard/job/page.js"
    click DashboardProfile "https://github.com/nectworks/nextjs-client/blob/main/app/dashboard/profile/[username]/page.js"
    click DashboardRefer "https://github.com/nectworks/nextjs-client/blob/main/app/dashboard/refer/page.js"
    DashboardJob -->|"uses"| Router
    DashboardProfile -->|"uses"| Router
    DashboardRefer -->|"uses"| Router

    %% Admin Panel
    subgraph "Admin Panel"
        AdminLayout["Admin Panel Layout"]:::pages
        AdminHome["Admin Home Page"]:::pages
        AdminUsers["Admin Users Page"]:::pages
        ManageBlog["Manage Blog Page"]:::pages
    end
    click AdminLayout "https://github.com/nectworks/nextjs-client/blob/main/app/admin-panel/layout.js"
    click AdminHome "https://github.com/nectworks/nextjs-client/blob/main/app/admin-panel/page.js"
    click AdminUsers "https://github.com/nectworks/nextjs-client/blob/main/app/admin-panel/admin-users/page.js"
    click ManageBlog "https://github.com/nectworks/nextjs-client/blob/main/app/admin-panel/manage-blog/page.js"
    AdminHome --> AdminLayout
    AdminUsers --> AdminLayout
    ManageBlog --> AdminLayout
    AdminLayout -->|"uses"| Router

    %% Authentication Flows
    subgraph "Authentication Flows"
        GoogleRedirect["Google OAuth Redirect"]:::external
        LinkedInRedirect["LinkedIn OAuth Redirect"]:::external
    end
    click GoogleRedirect "https://github.com/nectworks/nextjs-client/blob/main/app/google/auth-redirect/page.js"
    click LinkedInRedirect "https://github.com/nectworks/nextjs-client/blob/main/app/linkedin/auth-redirect/page.js"
    Home -->|"redirects to"| GoogleRedirect
    Home -->|"redirects to"| LinkedInRedirect
    GoogleRedirect -->|"callback to"| Home
    LinkedInRedirect -->|"callback to"| Home

    %% Shared UI Components
    subgraph "Shared UI Components"
        Header["Header Component"]:::components
        Footer["Footer Component"]:::components
        ProtectedRoute["ProtectedRoute Component"]:::components
        ProfileHeader["ProfileHeader Component"]:::components
    end
    click Header "https://github.com/nectworks/nextjs-client/blob/main/app/_components/Header/Header.js"
    click Footer "https://github.com/nectworks/nextjs-client/blob/main/app/_components/Footer/Footer.js"
    click ProtectedRoute "https://github.com/nectworks/nextjs-client/blob/main/app/_components/ProtectedRoute/ProtectedRoute.js"
    click ProfileHeader "https://github.com/nectworks/nextjs-client/blob/main/app/_components/Profile/ProfileHeader/ProfileHeader.js"
    Home -->|"renders"| Header
    Home -->|"renders"| Footer
    DashboardJob -->|"guards via"| ProtectedRoute
    ProfilePublic -->|"includes"| ProfileHeader

    %% State Management
    subgraph "Context / State Management"
        UserContext["UserContext"]:::state
        AdminUserContext["AdminUserContext"]:::state
        DashboardContext["DashboardContext"]:::state
        ProfileContext["ProfileContext"]:::state
    end
    click UserContext "https://github.com/nectworks/nextjs-client/blob/main/context/User/UserContext.js"
    click AdminUserContext "https://github.com/nectworks/nextjs-client/blob/main/context/AdminUserContext/AdminUserContext.js"
    click DashboardContext "https://github.com/nectworks/nextjs-client/blob/main/context/Dashboard/DashboardContext.js"
    click ProfileContext "https://github.com/nectworks/nextjs-client/blob/main/context/UpdateProfile/ProfileContext.js"
    Header -->|"reads from"| UserContext
    ProtectedRoute -->|"reads from"| UserContext
    DashboardJob -->|"uses"| DashboardContext
    ProfilePublic -->|"uses"| ProfileContext
    AdminHome -->|"uses"| AdminUserContext

    %% HTTP Layer & Utils
    subgraph "HTTP & Utils"
        AxiosInstance["Axios Base Config"]:::utils
        PrivateAxios["usePrivateAxios Hook"]:::utils
        CheckFile["checkFileExtension"]:::utils
        DownloadDoc["downloadDocument"]:::utils
        FormatCoins["formatNectCoins"]:::utils
        GAEvents["gaEvents"]:::utils
        ScrollTop["scrollToTop"]:::utils
        BottomMsg["showBottomMessage"]:::utils
    end
    click AxiosInstance "https://github.com/nectworks/nextjs-client/blob/main/config/axiosInstance.js"
    click PrivateAxios "https://github.com/nectworks/nextjs-client/blob/main/Utils/usePrivateAxios.js"
    click CheckFile "https://github.com/nectworks/nextjs-client/blob/main/Utils/checkFileExtension.js"
    click DownloadDoc "https://github.com/nectworks/nextjs-client/blob/main/Utils/downloadDocument.js"
    click FormatCoins "https://github.com/nectworks/nextjs-client/blob/main/Utils/formatNectCoins.js"
    click GAEvents "https://github.com/nectworks/nextjs-client/blob/main/Utils/gaEvents.js"
    click ScrollTop "https://github.com/nectworks/nextjs-client/blob/main/Utils/scrollToTop.js"
    click BottomMsg "https://github.com/nectworks/nextjs-client/blob/main/Utils/showBottomMessage.js"
    UserContext -->|"dispatch HTTP"| AxiosInstance
    DashboardContext -->|"dispatch HTTP"| PrivateAxios
    Home -->|"downloads"| DownloadDoc
    Home -->|"formats"| FormatCoins
    Home -->|"tracks event"| GAEvents
    Home -->|"scrolls"| ScrollTop
    Home -->|"messages"| BottomMsg

    %% Custom Hooks
    subgraph "Custom Hooks"
        UseGoogleIdentity["useGoogleIdentity"]:::hooks
    end
    click UseGoogleIdentity "https://github.com/nectworks/nextjs-client/blob/main/hooks/useGoogleIdentity.js"
    GoogleRedirect -->|"uses"| UseGoogleIdentity

    %% Static Assets & Fonts
    subgraph "Static Assets"
        PublicAssets["public/"]:::external
        FontLoader["Font Loader"]:::external
    end
    click PublicAssets "https://github.com/nectworks/nextjs-client/tree/main/public/"
    click FontLoader "https://github.com/nectworks/nextjs-client/blob/main/lib/font/Inter.js"
    Router -->|"serves"| PublicAssets
    Router -->|"loads"| FontLoader

    %% External Services
    subgraph "External Services"
        BackendAPI["Backend API Server"]:::external
        GoogleOAuth["Google Identity"]:::external
        LinkedInOAuth["LinkedIn OAuth"]:::external
        Analytics["Analytics/GA"]:::external
    end
    AxiosInstance -->|"calls"| BackendAPI
    GoogleRedirect -->|"auth via"| GoogleOAuth
    LinkedInRedirect -->|"auth via"| LinkedInOAuth
    GAEvents -->|"sends to"| Analytics

    %% Middleware
    Middleware["Next.js Middleware"]:::utils
    click Middleware "https://github.com/nectworks/nextjs-client/blob/main/middleware.js"
    Router -->|"uses"| Middleware

    %% Styles
    classDef pages fill:#D6EFFF,stroke:#0066CC,color:#000
    classDef components fill:#E6FFEA,stroke:#1A9F23,color:#000
    classDef state fill:#FFE8CC,stroke:#E69F00,color:#000
    classDef utils fill:#EED6FF,stroke:#9F23E6,color:#000
    classDef hooks fill:#FFF0D6,stroke:#E68F00,color:#000
    classDef external fill:#F2F2F2,stroke:#999,color:#000
```
