# pateldev01/araamifrontend architecture

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

- Interactive diagram: https://gitdiagram.com/pateldev01/araamifrontend
- Repository: https://github.com/pateldev01/araamifrontend

## Overview

##### Project Type and Purpose
- This is a full‑stack, e‑commerce web application built with Next.js (React) using server‑side rendering (SSR), static‑site generation (SSG) and client‑side state management.
- The “pages” directory defines the routing and SSR/SSG functions, “server.js” provides a custom Node/Express server for middleware and advanced routing, and “src/components” contains hundreds of reusable UI components.

##### File‑Structure Analysis
- Top‑level highlights:
- Middleware/ – custom Express middleware for authentication, maintenance mode, multi‑vendor routing
- pages/ – Next.js page components and dynamic routes (SSR/SSG)
- public/ – static assets served via CDN (images, fonts, manifest, Service Worker)
- src/components/ – UI building blocks grouped by feature/domain (Auth, Cart, Blogs, Home, etc.)
- src/contexts, src/store – client‑side state (React Context & Zustand stores)
- utils/ – API wrapper, auth utilities, formatters, settings
- server.js, next.config.js – custom server entry point and build configuration

##### README Insights
- Confirms Next.js usage with custom server support.
- No built‑in backend code under pages/api, implying external APIs or microservices handle data persistence.
- Emphasis on image dimensions hints at static‑asset optimization and CDN usage.

a. Client Layer (Browser/Mobile)
– Renders SSR/SSG HTML, hydrates to React
– Interacts via HTTP/HTTPS with the Next.js server and external APIs
b. CDN / Static File Delivery
– Serves files under /public/assets, SW, images, fonts
c. Next.js Custom Server (Node.js + Express)
– Entry: server.js → attaches middleware (isAuth, isMaintenance, isMultivendor)
– Routing: delegates to Next’s page router or API routes if defined
– SSR/SSG: invokes getServerSideProps / getStaticProps in pages/*
d. Business Logic Layer
– pages/* (React pages) orchestrate data fetching via utils/apiRequest
– src/components/* render UI; grouped by feature (Auth, Cart, Home, Blogs, Profile, etc.)
e. Client‑Side State Management
– React Contexts (src/contexts) for global behaviors (login state)
– Zustand stores (src/store) for cart, wishlist, compare, site settings
f. Data & External Services
– External Commerce APIs: product catalog, user auth, orders
– Third‑party services: Payment gateway, Email/Verification service, CDN for images
g. Utility Layer
– utils/ modules for formatting, auth token handling, API requests, language, and settings

##### Component Interactions & Data Flow
- Browser → Next.js server: initial request for a page (SSR/SSG)
- Next.js server → External API: fetch data via utils/apiRequest inside getServerSideProps
- Next.js server → CDN: fetch static assets (images, fonts, SW) for page rendering
- Browser → External API: after hydration, client‑side code (components + store) issues XHR/fetch to APIs
- Client‑side store/contexts manage state (cart, user session) and broadcast updates to components

##### Architectural Patterns & Design Principles
- Separation of concerns: Routing (pages/), UI (components/), State (contexts + store), Data (utils/)
- SSR/SSG for SEO and performance, with SW for offline support (public/sw.js + workbox)
- Atomic UI: very granular, feature‑based component directories
- Middleware pipeline in custom server for auth and environment gating

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        browser["Browser (SSR/CSR)"]:::client
    end

    %% CDN Layer
    subgraph "CDN / Static Assets"
        cdn["CDN (public/assets, sw.js, workbox, manifest)"]:::cdn
    end

    %% Server Layer
    subgraph "Next.js Custom Server"
        server["server.js"]:::service
        isAuth["isAuth Middleware"]:::middleware
        isMaintain["isMaintenance Middleware"]:::middleware
        isMulti["isMultivendor Middleware"]:::middleware
        router["Next.js Router (pages/)"]:::service
        ssr["getServerSideProps / getStaticProps"]:::logic
    end

    %% Business Logic Layer
    subgraph "Pages & Components"
        pages["pages/"]:::frontend
        orderPage["pages/order/[id]/index.js"]:::frontend
        productsList["pages/products/index.js"]:::frontend
        productDetail["pages/single-product/index.js"]:::frontend
        blogsPage["pages/blogs/"]:::frontend

        authComp["src/components/Auth/"]:::frontend
        cartComp["src/components/Cart/"]:::frontend
        cartPageComp["src/components/CartPage/"]:::frontend
        blogComp["src/components/Blogs/"]:::frontend
        homeComp["src/components/Home/"]:::frontend
        profileComp["src/components/Auth/Profile/"]:::frontend
        helpers["src/components/Helpers/"]:::frontend
        shared["src/components/Shared/"]:::frontend
        partials["src/components/Partials/"]:::frontend
    end

    %% State Management
    subgraph "State Management"
        defaultUser["src/contexts/DefaultUser.js"]:::data
        cartStore["src/store/Cart.js"]:::data
        wishlistStore["src/store/wishlistData.js"]:::data
        compareStore["src/store/compareProduct.js"]:::data
        setupStore["src/store/websiteSetup.js"]:::data
        globalStore["src/store/store.js"]:::data
    end

    %% Utility Layer
    subgraph "Utilities"
        apiRequest["utils/apiRequest.js"]:::utility
        authUtil["utils/auth.js"]:::utility
        dateFmt["utils/DateFormat.js"]:::utility
        settings["utils/settings.js"]:::utility
        langModel["utils/languageModel.js"]:::utility
        hex["utils/hexToRgb.js"]:::utility
        modifyObj["utils/modify_obj_key_and_return_new_obj.js"]:::utility
        wordCount["utils/wordCount.js"]:::utility
    end

    %% External Services
    subgraph "External Services"
        commerceAPI["External Commerce API"]:::external
        payment["Payment Gateway"]:::external
        emailService["Email/Verification Service"]:::external
    end

    %% Configuration
    subgraph "Build & Config"
        nextConfig["next.config.js"]:::utility
        tailwindConfig["tailwind.config.js"]:::utility
        postcssConfig["postcss.config.js"]:::utility
    end

    %% Flows
    browser -->|HTTP SSR Request| server
    server --> isAuth --> isMaintain --> isMulti --> router
    router --> ssr --> apiRequest --> commerceAPI
    router --> ssr --> cdn
    ssr --> pages
    pages --> orderPage
    pages --> productsList
    pages --> productDetail
    pages --> blogsPage

    ssr --> authComp
    ssr --> cartComp
    ssr --> blogComp
    ssr --> homeComp

    browser -->|Hydration| authComp
    browser --> cartComp
    browser --> blogComp
    browser --> homeComp

    browser -->|Client API Calls| apiRequest --> commerceAPI
    browser -->|Client API Calls| apiRequest --> payment
    browser -->|Client API Calls| apiRequest --> emailService

    browser --> defaultUser
    browser --> cartStore
    browser --> wishlistStore
    browser --> compareStore
    browser --> setupStore
    browser --> globalStore

    pages --> authUtil
    pages --> dateFmt
    pages --> settings
    pages --> langModel
    pages --> hex
    pages --> modifyObj
    pages --> wordCount

    server --> nextConfig
    server --> tailwindConfig
    server --> postcssConfig

    browser --> cdn

    %% Click Events
    click server "https://github.com/pateldev01/araamifrontend/blob/main/server.js"
    click isAuth "https://github.com/pateldev01/araamifrontend/blob/main/Middleware/isAuth.js"
    click isMaintain "https://github.com/pateldev01/araamifrontend/blob/main/Middleware/isMaintainance.js"
    click isMulti "https://github.com/pateldev01/araamifrontend/blob/main/Middleware/isMultivendor.js"
    click pages "https://github.com/pateldev01/araamifrontend/tree/main/pages/"
    click orderPage "https://github.com/pateldev01/araamifrontend/blob/main/pages/order/[id]/index.js"
    click productsList "https://github.com/pateldev01/araamifrontend/blob/main/pages/products/index.js"
    click productDetail "https://github.com/pateldev01/araamifrontend/blob/main/pages/single-product/index.js"
    click blogsPage "https://github.com/pateldev01/araamifrontend/tree/main/pages/blogs/"
    click authComp "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Auth/"
    click cartComp "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Cart/"
    click cartPageComp "https://github.com/pateldev01/araamifrontend/tree/main/src/components/CartPage/"
    click blogComp "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Blogs/"
    click homeComp "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Home/"
    click profileComp "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Auth/Profile/"
    click helpers "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Helpers/"
    click shared "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Shared/"
    click partials "https://github.com/pateldev01/araamifrontend/tree/main/src/components/Partials/"
    click defaultUser "https://github.com/pateldev01/araamifrontend/blob/main/src/contexts/DefaultUser.js"
    click cartStore "https://github.com/pateldev01/araamifrontend/blob/main/src/store/Cart.js"
    click wishlistStore "https://github.com/pateldev01/araamifrontend/blob/main/src/store/wishlistData.js"
    click compareStore "https://github.com/pateldev01/araamifrontend/blob/main/src/store/compareProduct.js"
    click setupStore "https://github.com/pateldev01/araamifrontend/blob/main/src/store/websiteSetup.js"
    click globalStore "https://github.com/pateldev01/araamifrontend/blob/main/src/store/store.js"
    click apiRequest "https://github.com/pateldev01/araamifrontend/blob/main/utils/apiRequest.js"
    click authUtil "https://github.com/pateldev01/araamifrontend/blob/main/utils/auth.js"
    click dateFmt "https://github.com/pateldev01/araamifrontend/blob/main/utils/DateFormat.js"
    click settings "https://github.com/pateldev01/araamifrontend/blob/main/utils/settings.js"
    click langModel "https://github.com/pateldev01/araamifrontend/blob/main/utils/languageModel.js"
    click hex "https://github.com/pateldev01/araamifrontend/blob/main/utils/hexToRgb.js"
    click modifyObj "https://github.com/pateldev01/araamifrontend/blob/main/utils/modify_obj_key_and_return_new_obj.js"
    click wordCount "https://github.com/pateldev01/araamifrontend/blob/main/utils/wordCount.js"
    click publicAssets "https://github.com/pateldev01/araamifrontend/tree/main/public/assets/"
    click sw "https://github.com/pateldev01/araamifrontend/blob/main/public/sw.js"
    click workbox "https://github.com/pateldev01/araamifrontend/blob/main/public/workbox-50de5c5d.js"
    click manifest "https://github.com/pateldev01/araamifrontend/blob/main/public/manifest.json"
    click nextConfig "https://github.com/pateldev01/araamifrontend/blob/main/next.config.js"
    click tailwindConfig "https://github.com/pateldev01/araamifrontend/blob/main/tailwind.config.js"
    click postcssConfig "https://github.com/pateldev01/araamifrontend/blob/main/postcss.config.js"

    %% Styles
    classDef client fill:#BBEFFF,stroke:#2E86C1
    classDef service fill:#AED6F1,stroke:#1B4F72
    classDef middleware fill:#D5DBDB,stroke:#566573
    classDef frontend fill:#ABEBC6,stroke:#1D8348
    classDef data fill:#F9E79F,stroke:#B9770E
    classDef utility fill:#FAD7A0,stroke:#B9770E
    classDef cdn fill:#D7DBDD,stroke:#616A6B
    classDef external fill:#F5CBA7,stroke:#9C640C
    classDef logic fill:#F6DDCC,stroke:#A04000
```
