# hau2223/k-mgear_website architecture

> Architecture diagram of the GitHub repository hau2223/k-mgear_website, 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/hau2223/k-mgear_website
- Repository: https://github.com/hau2223/k-mgear_website

## Overview

##### Project Type and Purpose
- The project is a full-stack web application.
- The backend (located in the “api” directory) provides REST API endpoints for various resources (cart, comments, products, brands, types, and users).
- The frontend (inside “src” and “public”) is built with React, containing multiple pages (like HomePage, ProductPage, CartPage, etc.), along with services that communicate with the API.
- The README mostly covers client-side bootstrapping via Create React App, but the overall structure reveals a separate API layer.

##### Main Components
a. Frontend:
- React Application: Show components like “Pages” (with sub-components for CartPage, HomePage, ProductDetailPage, etc.), “assets”, and “services” (which use axios defined in “src/utils/axios.js”).
- Components: Illustrate shared components (Header, Footer, Card, Router, etc.) and supporting pages.
b. Backend (API):
- API Server: Represent the entry point (api/index.js).
- Routers: Map out the routers (cartRouter, commentRouter, productRouter, etc.), which expose REST endpoints.
c. Data & Utilities:
- That the API interacts with a data layer through models (even if a specific database isn’t listed explicitly, these model definitions suggest persistence are involved).
- “utils” folder in the frontend which provides shared resources like axios instance configuration and constants.

##### Relationships and Data Flow
- Separation of concerns: the frontend handles presentation and user interactions (client-side routing, page management), while the API handles business logic and data management.
- If applicable, include external integrations or libraries used (for example, axios for HTTP communication, tailwindcss for styling configured via tailwind.config.js, and any dependencies in the package.json files).

##### Architectural Patterns and Design Principles
- MVC-like splitting on the backend: models for representing data structures, routers for handling request routing, and the index.js file serving as the server startup script.
- A component-based architecture in the frontend, adhering to modern React practices.
- Clear separation between the client and server sides, potentially suggesting a RESTful API design.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FA["React App (Create React App)"]:::frontend
        subgraph "Components"
            FP["React Pages (Multiple Pages)"]:::frontend
            SC["Shared Components (Header,Footer,Card,Router)"]:::frontend
        end
        subgraph "Services & Utilities"
            FS["Frontend Services (cartService,commentService,productService)"]:::frontend
            AC["Axios Config"]:::utility
        end
    end

    %% Backend Subgraph
    subgraph "Backend API"
        API["API Server"]:::backend
        subgraph "Routers"
            CR["Cart Router"]:::backend
            CCR["Comment Router"]:::backend
            PR["Product Router"]:::backend
            PBR["Product Brand Router"]:::backend
            PTR["Product Type Router"]:::backend
            UR["User Router"]:::backend
        end
        subgraph "Models"
            CM["Cart Model"]:::backend
            COM["Comment Model"]:::backend
            PM["Product Model"]:::backend
            PBM["Product Brand Model"]:::backend
            PTM["Product Type Model"]:::backend
            UM["User Model"]:::backend
        end
    end

    %% Frontend Internal Connections
    FA --> FP
    FP --> FS
    AC --> FS

    %% Frontend to Backend API Connections
    FS -->|"calls"| CR
    FS -->|"calls"| CCR
    FS -->|"calls"| PR

    %% Backend Internal Connections: Routers to Models
    CR -->|"delegates to"| CM
    CCR -->|"delegates to"| COM
    PR -->|"delegates to"| PM
    PBR -->|"delegates to"| PBM
    PTR -->|"delegates to"| PTM
    UR -->|"delegates to"| UM

    %% Click Events
    click FA "https://github.com/hau2223/k-mgear_website/tree/staging/src"
    click FP "https://github.com/hau2223/k-mgear_website/tree/staging/src/Pages"
    click SC "https://github.com/hau2223/k-mgear_website/tree/staging/src/utils/components"
    click FS "https://github.com/hau2223/k-mgear_website/tree/staging/src/services"
    click AC "https://github.com/hau2223/k-mgear_website/blob/staging/src/utils/axios.js"
    click API "https://github.com/hau2223/k-mgear_website/blob/staging/api/index.js"
    click CR "https://github.com/hau2223/k-mgear_website/blob/staging/api/routers/cartRouter.js"
    click CCR "https://github.com/hau2223/k-mgear_website/blob/staging/api/routers/commentRouter.js"
    click PR "https://github.com/hau2223/k-mgear_website/blob/staging/api/routers/productRouter.js"
    click PBR "https://github.com/hau2223/k-mgear_website/blob/staging/api/routers/productBrandRouter.js"
    click PTR "https://github.com/hau2223/k-mgear_website/blob/staging/api/routers/productTypeRouter.js"
    click UR "https://github.com/hau2223/k-mgear_website/blob/staging/api/routers/userRouter.js"
    click CM "https://github.com/hau2223/k-mgear_website/blob/staging/api/models/cartModel.js"
    click COM "https://github.com/hau2223/k-mgear_website/blob/staging/api/models/comentModel.js"
    click PM "https://github.com/hau2223/k-mgear_website/blob/staging/api/models/productModel.js"
    click PBM "https://github.com/hau2223/k-mgear_website/blob/staging/api/models/productBrandModel.js"
    click PTM "https://github.com/hau2223/k-mgear_website/blob/staging/api/models/productTypeModel.js"
    click UM "https://github.com/hau2223/k-mgear_website/blob/staging/api/models/userModel.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef utility fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
