# minhhkhoa/next_bazaar architecture

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

- Interactive diagram: https://gitdiagram.com/minhhkhoa/next_bazaar
- Repository: https://github.com/minhhkhoa/next_bazaar

## Overview

##### Project type and purpose
- From the README (“bootstrapped with create-next-app”) and the file tree (`next.config.ts`, `src/app/...`, `src/api/...`, `public/`, etc.), this is a Next.js full-stack (frontend-centric) application.
- The directory names (`dien-thoai`, `laptop`, `serum`, `thoi-trang`, `tin-tuc`, `auth`, etc.) and components (`Products`, `News`, `Contact`) indicate an e-commerce/news portal with server-rendered pages, client-side interactivity, and simple API routes serving local JSON data.

##### File structure
- Top-level config+meta: `.gitignore`, `package.json`/`lock`, `tsconfig.json`, `next.config.ts`, `postcss.config.mjs`, `eslint.config.mjs`.
- `public/`: static assets (images, banner files).
- `src/app/`: Next.js App Router pages, sub-folders represent route segments, each with `page.tsx` for SSR/SSG.
- `src/api/`: Next.js API routes (`News/getDetailNews.ts`, `Products/getProductByCategoryId.tsx`) providing JSON data to pages.
- `src/components/`: Reusable UI components (Header, Footer, Products, News, Contact, Swiper, etc.).
- `src/redux/`: Redux Toolkit store and slices for global state (newsSlice, productSlice).
- `src/data/`: Local JSON files for news and product/category data.
- `src/hook/`: Custom hooks (scroll, window size).
- `src/ultils/`: Utility functions for menu building and price formatting.
- Build and styling: `postcss`, SCSS, global CSS in `src/app`.

##### README for additional insights
- No external database: data is local JSON under `src/data`.

- Client → App Router (page request)
- App Router → API Route (fetch data)
- API Route → Data Store (read JSON) → API Route (return JSON) → App Router → Client
- Blue for server-side components (Next.js, API routes)
- Green for client-side components (React UI, Redux)
- Gray for data (JSON files, public assets)
- Rectangles for modules/services

##### Final advice
- Be exhaustive: break the system into all logical parts (routing, data, UI, state) but avoid clutter.
- Flow of a single page request, then overlay client-side navigation and data fetching.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client (Browser)" 
        direction TB
        Browser["Browser"]:::client
        ReactUI["React UI Components"]:::client
        ReduxClient["Redux Store (Client Init)"]:::client
        Browser -->|"Request Page"| ReactUI
        ReactUI -->|"Hydrate & Init State"| ReduxClient
    end

    %% Next.js Server
    subgraph "Next.js Server" 
        direction TB
        AppRouter["Next.js App Router"]:::server
        LayoutProviders["Global Layout & Providers"]:::server
        Pages["Page Routes"]:::server
        API["Next.js API Router"]:::server
        AppRouter --> LayoutProviders
        LayoutProviders --> Pages
        AppRouter --> API
    end

    %% Application Pages
    subgraph "Page Routes" 
        direction TB
        Home["Home Page"]:::server
        AuthLogin["Login Page"]:::server
        AuthRegister["Register Page"]:::server
        ProductsCat["Product Category Pages"]:::server
        NewsList["News List Page"]:::server
        NewsDetail["News Detail Page"]:::server
        ContactPage["Contact Page"]:::server
        Pages --> Home
        Pages --> AuthLogin
        Pages --> AuthRegister
        Pages --> ProductsCat
        Pages --> NewsList
        Pages --> NewsDetail
        Pages --> ContactPage
    end

    %% API Routes
    subgraph "API Routes" 
        direction TB
        NewsAPI["News API Route"]:::server
        ProductsAPI["Products API Route"]:::server
        API --> NewsAPI
        API --> ProductsAPI
    end

    %% Data Layer
    subgraph "Data Store" 
        direction TB
        NewsData["News JSON Data"]:::data
        ProductsData["Products JSON Data"]:::data
        CategoryData["Product Category JSON"]:::data
        Assets["Static Assets (public/)"]:::data
        NewsAPI -->|"Read JSON"| NewsData
        ProductsAPI -->|"Read JSON"| ProductsData
        ProductsAPI -->|"Read JSON"| CategoryData
        Browser -->|"Load Assets"| Assets
    end

    %% Server to Client Response
    AppRouter -->|"Render HTML + JS"| Browser
    AppRouter -->|"Embed Initial State"| ReduxClient

    %% Client-side Nav & Data Fetch
    ReactUI -->|"Client Navigation"| AppRouter
    ReactUI -->|"Fetch Data via API"| API

    %% Redux Store (Server & Client)
    subgraph "State Management" 
        direction TB
        StoreConfig["Redux Store Configuration"]:::util
        NewsSlice["News Slice"]:::util
        ProductSlice["Product Slice"]:::util
        LayoutProviders --> StoreConfig
        StoreConfig --> NewsSlice
        StoreConfig --> ProductSlice
    end

    %% UI Components
    subgraph "UI Component Library" 
        direction TB
        Header["Header"]:::component
        Footer["Footer"]:::component
        ProductsComp["Products Components"]:::component
        NewsComp["News Components"]:::component
        ContactComp["Contact Components"]:::component
        GoogleMap["Google Maps"]:::component
        SwiperComp["Swiper"]:::component
        NotifyComp["Notify"]:::component
        SearchComp["Search"]:::component
        LoaderComp["Loader"]:::component
    end

    ReactUI --> Header
    ReactUI --> Footer
    ReactUI --> ProductsComp
    ReactUI --> NewsComp
    ReactUI --> ContactComp
    ReactUI --> GoogleMap
    ReactUI --> SwiperComp
    ReactUI --> NotifyComp
    ReactUI --> SearchComp
    ReactUI --> LoaderComp

    %% Hooks & Utils
    subgraph "Custom Hooks & Utilities"
        direction TB
        ScrollHook["Scroll To Top Hook"]:::util
        WindowHook["Window Size Hook"]:::util
        MenuUtil["Menu Builder Util"]:::util
        PriceUtil["Price Formatting Util"]:::util
        TreeHelper["Tree Helpers"]:::util
    end
    ReactUI --> ScrollHook
    ReactUI --> WindowHook
    ProductsComp --> MenuUtil
    ProductsComp --> PriceUtil
    ProductsComp --> TreeHelper

    %% Click Events
    click AppRouter "https://github.com/minhhkhoa/next_bazaar/tree/master/src/app/"
    click LayoutProviders "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/layout.tsx"
    click StoreConfig "https://github.com/minhhkhoa/next_bazaar/blob/master/src/redux/store.ts"
    click NewsSlice "https://github.com/minhhkhoa/next_bazaar/blob/master/src/redux/features/newsSlice.ts"
    click ProductSlice "https://github.com/minhhkhoa/next_bazaar/blob/master/src/redux/features/productSlice.ts"
    click Home "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/page.tsx"
    click AuthLogin "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/(auth)/login/page.tsx"
    click AuthRegister "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/(auth)/register/page.tsx"
    click ProductsCat "https://github.com/minhhkhoa/next_bazaar/tree/master/src/app/(allproducts)/"
    click NewsList "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/tin-tuc/page.tsx"
    click NewsDetail "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/tin-tuc/[id]/page.tsx"
    click ContactPage "https://github.com/minhhkhoa/next_bazaar/blob/master/src/app/lien-he/page.tsx"
    click NewsAPI "https://github.com/minhhkhoa/next_bazaar/blob/master/src/api/News/getDetailNews.ts"
    click ProductsAPI "https://github.com/minhhkhoa/next_bazaar/blob/master/src/api/Products/getProductByCategoryId.tsx"
    click NewsData "https://github.com/minhhkhoa/next_bazaar/blob/master/src/data/news/new.ts"
    click ProductsData "https://github.com/minhhkhoa/next_bazaar/blob/master/src/data/products/products.ts"
    click CategoryData "https://github.com/minhhkhoa/next_bazaar/blob/master/src/data/product-category/products-category.ts"
    click Header "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Header/Header.tsx"
    click Footer "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Footer/Footer.tsx"
    click ProductsComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Products/ListProducts.tsx"
    click NewsComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/News/LeftNews/FeaturedNews.tsx"
    click ContactComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Contact/InfoContact.tsx"
    click GoogleMap "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/GoogleMap/ContactMap.tsx"
    click SwiperComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Swiper/Swiper.tsx"
    click NotifyComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Notify/Notifycation.tsx"
    click SearchComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Search/SearchProduct.tsx"
    click LoaderComp "https://github.com/minhhkhoa/next_bazaar/blob/master/src/components/Uiverse/Loader.tsx"
    click ScrollHook "https://github.com/minhhkhoa/next_bazaar/blob/master/src/hook/Scroll/ScrollToTop.ts"
    click WindowHook "https://github.com/minhhkhoa/next_bazaar/blob/master/src/hook/WindowSize/useWindowSize.tsx"
    click MenuUtil "https://github.com/minhhkhoa/next_bazaar/blob/master/src/ultils/menuUtils.ts"
    click PriceUtil "https://github.com/minhhkhoa/next_bazaar/blob/master/src/ultils/newPrice.ts"
    click TreeHelper "https://github.com/minhhkhoa/next_bazaar/blob/master/src/ultils/treeParent.ts"
    click TreeHelper "https://github.com/minhhkhoa/next_bazaar/blob/master/src/ultils/removeEmptyChildren.ts"
    click Assets "https://github.com/minhhkhoa/next_bazaar/tree/master/public/"

    %% Styles
    classDef client fill:#98FB98,stroke:#333,stroke-width:1px
    classDef server fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef data fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef component fill:#FFFACD,stroke:#333,stroke-width:1px
    classDef util fill:#E6E6FA,stroke:#333,stroke-width:1px
```
