# codervu/capstoneproject-fe architecture

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

- Interactive diagram: https://gitdiagram.com/codervu/capstoneproject-fe
- Repository: https://github.com/codervu/capstoneproject-fe

## Overview

##### Project type and purpose
- This is a single-page e-commerce web application built with Create React App. It combines both a public storefront (product listings, shopping cart, checkout, chat, notifications) and an admin portal (category, product, order, discount, customer, statistics management). It uses React for UI, Redux for state, Axios-based services for API calls, and WebSockets for live notifications. It is deployed as a static app (Azure Static Web Apps).

##### File structure
- Top-level “public”/“build”: static hosting assets
- src/
- components & pages: UI layer (organized by feature and layout)
- redux: actions, reducers, services, store—state management and API integration
- ws: WebSocket configuration and notification service
- lib, constants, assets: utilities and static resources
- GitHub Actions workflow and staticwebapp.config.json: CI/CD & hosting config
- tailwind.config.js & postcss.config.js: styling pipeline

##### README for additional insights
- Bootstrapped by Create React App
- Standard scripts (start, build, test, eject)
- Deployment target is Azure Static Web Apps

a. Main components
- Browser/Client
- Static Hosting (Azure Static Web Apps + CDN)
- React SPA (UI Layer)
- Redux Store & Middleware
- HTTP API Services (auth, products, cart, orders, chat, etc.)
- WebSocket Service (orderNotificationService)
- External Backend Services (REST API server, WebSocket server, Database)
- CI/CD Pipeline (GitHub Actions → Azure)

b. Relationships & interactions
- Browser loads index.html from Azure Static Web Apps / CDN.
- React App initializes Redux store and WebSocket connection.
- UI components dispatch Redux actions → invoke redux/services → send HTTP requests (via Axios) to Backend REST endpoints.
- redux/services receive responses → dispatch reducers → update store → UI re-renders.
- ws/orderNotificationService opens socket to backend WebSocket server → receives push events → dispatches store updates → UI notifications.
- GitHub Actions triggers on push → npm run build → deploys build/ to Azure Static Web Apps.

c. Architectural patterns & design principles
- Layered architecture: Presentation (React components/pages), Application State (Redux store/slices), Integration (Axios services, WebSocket), Infrastructure (static hosting, CI/CD).
- Feature-based folder structure for scalability.
- Single source of truth: Redux.
- Separation of concerns: components are “dumb” and receive data/dispatch actions, business logic lives in redux/services and slices.

d. Technologies & frameworks
- React (UI)
- Redux (state management)
- Axios (HTTP client via redux/setup/axios.js)
- WebSocket (ws/configSocket.js & orderNotificationService)
- Tailwind CSS & PostCSS (styling)
- Azure Static Web Apps (hosting)
- GitHub Actions (CI/CD workflow)

##### Detail level
- Include:
- Client startup → loads index.html & JS bundles
- React Router handling for public vs. admin routes
- Redux store initialization (orebiSlice, rootReducer, store.js)
- Middleware layers (redux/setup/ai.js for AI features)
- Service modules calling endpoints (e.g., productService, cartService)
- WebSocket handshake and event flow
- CI/CD: GitHub Actions job → staticwebapp.config.json rules → Azure deployment

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Browser["Browser/Client"]:::frontend
    click Browser "https://github.com/codervu/capstoneproject-fe/blob/develop/public/index.html"
    Azure["Azure Static Web Apps + CDN"]:::infra
    click Azure "https://github.com/codervu/capstoneproject-fe/blob/develop/staticwebapp.config.json"
    CI["GitHub Actions CI/CD"]:::infra
    click CI "https://github.com/codervu/capstoneproject-fe/blob/develop/.github/workflows/azure-static-web-apps-polite-plant-004c99b1e.yml"
    
    Browser -->|"GET index.html & bundles"| Azure
    CI -->|"Deploy build/ to"| Azure
    Azure --> Browser

    %% Frontend Application
    ReactBootstrap["React Application Bootstrap\n(src/index.js & src/App.js)"]:::frontend
    click ReactBootstrap "https://github.com/codervu/capstoneproject-fe/blob/develop/src/index.js"
    click ReactBootstrap "https://github.com/codervu/capstoneproject-fe/blob/develop/src/App.js"

    Azure -->|"Serve JS"| ReactBootstrap

    subgraph "UI Layer"
        Components["UI Components (src/components)"]:::frontend
        click Components "https://github.com/codervu/capstoneproject-fe/tree/develop/src/components"
        Pages["Pages (Public & Admin) (src/pages)"]:::frontend
        click Pages "https://github.com/codervu/capstoneproject-fe/tree/develop/src/pages"
    end

    ReactBootstrap --> Components
    ReactBootstrap --> Pages

    %% State Management
    subgraph "State Management"
        Store["Redux Store & Init (src/redux/store.js)"]:::state
        click Store "https://github.com/codervu/capstoneproject-fe/blob/develop/src/redux/store.js"
        Slice["orebiSlice (src/redux/orebiSlice.js)"]:::state
        click Slice "https://github.com/codervu/capstoneproject-fe/blob/develop/src/redux/orebiSlice.js"
        Reducers["Root Reducer & Slices (src/redux/reducers)"]:::state
        click Reducers "https://github.com/codervu/capstoneproject-fe/blob/develop/src/redux/reducers/rootReducer.js"
        Actions["Redux Actions (src/redux/actions)"]:::state
        click Actions "https://github.com/codervu/capstoneproject-fe/tree/develop/src/redux/actions"
    end

    Components -->|"dispatch action"| Actions
    Pages -->|"dispatch action"| Actions
    Actions -->|"invoke service"| Store

    Store --> Reducers
    Reducers --> Slice

    %% Integration Layer
    subgraph "Integration Layer"
        Services["Redux Services (HTTP API) (src/redux/service/*.js)"]:::integration
        click Services "https://github.com/codervu/capstoneproject-fe/tree/develop/src/redux/service"
        AxiosSetup["Axios HTTP Client Setup\n(src/redux/setup/axios.js)"]:::integration
        click AxiosSetup "https://github.com/codervu/capstoneproject-fe/blob/develop/src/redux/setup/axios.js"
        AISetup["AI Middleware Setup\n(src/redux/setup/ai.js)"]:::integration
        click AISetup "https://github.com/codervu/capstoneproject-fe/blob/develop/src/redux/setup/ai.js"
        WSConfig["WebSocket Config (src/ws/configSocket.js)"]:::integration
        click WSConfig "https://github.com/codervu/capstoneproject-fe/blob/develop/src/ws/configSocket.js"
        OrderNS["Order Notification Service\n(src/ws/orderNotificationService.js)"]:::integration
        click OrderNS "https://github.com/codervu/capstoneproject-fe/blob/develop/src/ws/orderNotificationService.js"
    end

    Store --> Services
    Services -->|"HTTP GET/POST"| REST
    Services --> AxiosSetup
    Store --> AISetup

    ReactBootstrap -->|"WS connect"| WSConfig
    WSConfig --> OrderNS
    OrderNS -->|"dispatch WS events"| Store

    %% Backend Services
    subgraph "External Backend Services"
        REST["REST API Server"]:::infra
        WSrv["WebSocket Server"]:::infra
        DB["Database"]:::infra
    end

    REST --> DB
    WSrv --> DB
    OrderNS <-->|"WS subscribe/emit"| WSrv

    %% Styles & Assets
    Assets["Static Assets (src/assets)"]:::frontend
    click Assets "https://github.com/codervu/capstoneproject-fe/tree/develop/src/assets"
    Constants["Application Constants\n(src/constants/index.js)"]:::integration
    click Constants "https://github.com/codervu/capstoneproject-fe/blob/develop/src/constants/index.js"
    Utils["Utility Library (src/lib/utils.js)"]:::integration
    click Utils "https://github.com/codervu/capstoneproject-fe/blob/develop/src/lib/utils.js"
    Tailwind["Tailwind Config (tailwind.config.js)"]:::infra
    click Tailwind "https://github.com/codervu/capstoneproject-fe/blob/develop/tailwind.config.js"
    PostCSS["PostCSS Config (postcss.config.js)"]:::infra
    click PostCSS "https://github.com/codervu/capstoneproject-fe/blob/develop/postcss.config.js"

    ReactBootstrap --> Assets
    ReactBootstrap --> Constants
    ReactBootstrap --> Utils

    %% Class Definitions
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef state fill:#E6F4EA,stroke:#28A745,color:#28A745;
    classDef integration fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00;
    classDef infra fill:#F0F0F0,stroke:#6A737D,color:#6A737D;
```
