# duybui2608bku/clone-shoppe architecture

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

- Interactive diagram: https://gitdiagram.com/duybui2608bku/clone-shoppe
- Repository: https://github.com/duybui2608bku/clone-shoppe

## Overview

##### Main Components
- UI Layer – Includes all visual components and pages. Organize this layer by:
- Pages: Home, Cart, Login, Register, Profile, ProductDetail, ProductsList, etc.
- Components: Reusable pieces like ButtonShoppe, HeaderMain, Footer, InputNumber, Paginate, ProductRating, QuantityController, and various Popovers.
- Layouts: MainLayout, RegisterLayout, and UserLayout that wrap around pages to provide a consistent look and navigation.
- Application State Management – The Context folder (App.context.tsx) shows that the app uses React Context API to manage global state.
- API/Service Layer – The Services folder encapsulates communication with back-end endpoints. This includes API calls for categories, products, login/logout, purchases, and user operations.
- Custom Hooks – Provided in the Hooks folder (e.g., useQueryConfig, useQueryParams) to encapsulate reusable logic and interactions.
- Utility and Constants Modules – The Utils and constants folders provide helper functions (Auth, axios, ruls etc.) and configuration values (paths, HTTP status codes, product/purchase settings).

##### Relationships and Interactions
- The UI Layer (Pages and Components) “talks” to the API/Service layer by invoking functions from the Services folder.
- The Context layer integrates with both UI components and Service calls to manage and propagate state (e.g., logged-in user, items in the cart, etc.).
- Custom Hooks act as intermediaries to extract query data and other logic from the URL or other sources, thereby influencing component behavior.
- Layouts wrap around pages, providing common navigation (such as Header or Footer) and an overall structure to the UI.
- The constants and types files ensure consistency in data types and configuration throughout the application.

##### Important Architectural Patterns
- Component-Based Architecture: Separating visual and reusable code into discrete components.
- Separation of Concerns: Dividing the system into UI, state management, and service/API layers.
- Modular Organization: Specific directories for hooks, services, context, constants, and utilities allow the project to remain maintainable and scalable.
- Use of Custom Hooks and Context API: For managing and sharing state logic across various parts of the application.

##### Relevant Technologies and Libraries
- React with TypeScript – Main framework and typing system.
- SCSS – For styling components with organized style files.
- Vite – Likely used as the build tool (as seen from vite.config.ts and vite-env.d.ts).
- ESLint and Prettier – For code quality and formatting.
- Axios – Presumably wrapped within the Utils/axios.ts for API requests.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer (React/SCSS)"
        subgraph "Pages"
            UI_Pages["Pages"]
        end
        subgraph "Components"
            Button["ButtonShoppe"]
            Header["HeaderMain"]
            Footer["Footer"]
            Input["InputNumber"]
            Paginate["Paginate"]
            Rating["ProductRating"]
            Quantity["QuantityController"]
            Popover["Popovers"]
        end
        subgraph "Layouts"
            MainLayout["MainLayout"]
            RegisterLayout["RegisterLayout"]
            UserLayout["UserLayout"]
        end
    end

    %% State Management Layer
    subgraph "State Management"
        Context["Context (React Context API)"]
        subgraph "Custom Hooks"
            QueryConfig["useQueryConfig"]
            QueryParams["useQueryParams"]
        end
    end

    %% API/Service Layer
    subgraph "API/Service Layer (Axios)"
        Category["Category API"]
        AuthApi["Login/Logout API"]
        Products["Products API"]
        Purchase["Purchase API"]
        UserApi["User API"]
    end

    %% Utility and Configuration
    subgraph "Utility & Configuration"
        subgraph "Utils"
            AxiosWrapper["Axios Wrapper"]
            OtherUtils["Utils"]
            AuthUtils["Auth Utils"]
            Ruls["Ruls"]
        end
        subgraph "Constants"
            Config["Config"]
            HTTP["HTTPStatusCodes"]
            Paths["Paths"]
            ProductConst["Product Settings"]
            PurchaseConst["Purchase Settings"]
        end
        Types["Types"]
    end

    %% Relationships between UI sublayers
    MainLayout -->|"wraps"| UI_Pages
    RegisterLayout -->|"wraps"| UI_Pages
    UserLayout -->|"wraps"| UI_Pages

    %% UI and State Management interactions
    UI_Pages -->|"consumesUserData"| Context
    Button -->|"triggersAction"| Context
    Header -->|"displaysUserInfo"| Context
    QueryConfig -->|"providesQuery"| UI_Pages
    QueryParams -->|"parsesParams"| UI_Pages

    %% UI Components interacting with API layer
    Button -->|"callsAPI"| Products
    Input -->|"updatesQty"| Products
    Paginate -->|"handlesPagination"| Products
    Rating -->|"fetchesRating"| Products
    Popover -->|"userInteraction"| AuthApi

    %% State Management interacting with API layer
    Context -->|"fetchCategories"| Category
    Context -->|"authCalls"| AuthApi
    Context -->|"fetchProducts"| Products
    Context -->|"processPurchase"| Purchase
    Context -->|"fetchUserDetails"| UserApi

    %% API layer using Axios Wrapper
    Category -->|"apiRequest"| AxiosWrapper
    AuthApi -->|"apiRequest"| AxiosWrapper
    Products -->|"apiRequest"| AxiosWrapper
    Purchase -->|"apiRequest"| AxiosWrapper
    UserApi -->|"apiRequest"| AxiosWrapper

    %% Data typing relations
    UI_Pages -->|"typedData"| Types
    Context -->|"typedState"| Types
    Products -->|"typedResponse"| Types

    %% Styling Classes
    class UI_Pages,Button,Header,Footer,Input,Paginate,Rating,Quantity,Popover,MainLayout,RegisterLayout,UserLayout ui;
    class Context,QueryConfig,QueryParams state;
    class Category,AuthApi,Products,Purchase,UserApi api;
    class AxiosWrapper,OtherUtils,AuthUtils,Ruls,Config,HTTP,Paths,ProductConst,PurchaseConst,Types util;

    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef state fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef api fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef util fill:#fff3cd,stroke:#856404,stroke-width:2px;

    %% Click Events for UI Layer
    click UI_Pages "https://github.com/duybui2608bku/clone-shoppe/tree/main/src/Pages"
    click Button "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/ButtonShoppe/ButtonShoppe.tsx"
    click Header "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/HeaderMain/HeaderMain.tsx"
    click Footer "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/Footer/Footer.tsx"
    click Input "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/InputNumber/InputNumber.tsx"
    click Paginate "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/Paginate/Pagination.tsx"
    click Rating "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/ProductRating/ProductRating.tsx"
    click Quantity "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Components/QuantityController/QuantityController.tsx"
    click Popover "https://github.com/duybui2608bku/clone-shoppe/tree/main/src/Components/Popover"
    click MainLayout "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Layout/MainLayout/MainLayout.tsx"
    click RegisterLayout "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Layout/RegisterLayout/RegisterLayout.tsx"
    click UserLayout "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Pages/User/Layout/UserLayout/UserLayout.scss"

    %% Click Event for State Management
    click Context "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Context/App.context.tsx"
    click QueryConfig "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Hooks/useQueryConfig.tsx"
    click QueryParams "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Hooks/useQueryParams.tsx"

    %% Click Events for API/Service Layer
    click Category "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Services/CategotyApi.api.ts"
    click AuthApi "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Services/LogInLogOut.api.ts"
    click Products "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Services/Products.api.ts"
    click Purchase "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Services/Purchase.api.ts"
    click UserApi "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Services/User.api.ts"

    %% Click Events for Utility & Configuration
    click AxiosWrapper "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Utils/axios.ts"
    click OtherUtils "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Utils/Utils.ts"
    click AuthUtils "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Utils/Auth.ts"
    click Ruls "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/Utils/ruls.ts"
    click Config "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/constants/config.ts"
    click HTTP "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/constants/httpStatusCode.enum.ts"
    click Paths "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/constants/path.ts"
    click ProductConst "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/constants/product.ts"
    click PurchaseConst "https://github.com/duybui2608bku/clone-shoppe/blob/main/src/constants/purchase.ts"
    click Types "https://github.com/duybui2608bku/clone-shoppe/tree/main/src/Types"
```
