# thong8888/shoppingonline architecture

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

## Overview

##### Client Admin Application
- Located under the "client-admin" directory.
- Built using React (as seen by the typical React files like index.js, App.js, and a variety of components).
- Manages administrative functionality such as handling categories, products, customers, and orders – indicated by components like CategoryComponent, ProductComponent, and OrderComponent.

##### Client Customer Application
- Located under the "client-customer" directory.
- Also built with React. This client focuses on the customer-facing interface with components such as HomeComponent, LoginComponent, SignupComponent, MycartComponent, and ProductDetailComponent.
- Includes utility functions (e.g., CartUtil) that support customer-specific actions like managing a shopping cart.

##### Server Application
- Found in the "server" directory.
- Implemented in Node.js as indicated by the various JavaScript files and package.json.
- Exposes REST API endpoints under server/api (with separate endpoints for admin and customer: admin.js and customer.js).
- Contains models (data access objects like AdminDAO, CustomerDAO, CategoryDAO, OrderDAO, ProductDAO) that abstract database interactions.
- Utility modules such as JwtUtil, CryptoUtil, MongooseUtil, etc., suggest usage of authentication (JWT), encryption, and MongoDB/Mongoose for database operations.

##### Main Components
- Client Admin Frontend: Represented as a React application handling administrative tasks.
- Client Customer Frontend: Represented as a React application focused on the sales and shopping experience.
- Server Backend: The central Node.js REST API that interacts with both client applications and manages business logic.
- Database (implied via server/models and MongooseUtil): While not explicitly shown by a “db” directory, the presence of MongooseUtil hints at MongoDB usage.
- External Services: Although not detailed in the tree, utilities like EmailUtil suggest the potential integration with an email service for notifications or confirmations.

##### Relationships and Interactions
- Internally, the Server is organized into API endpoints for admin and customer functions and uses various Data Access Objects (DAOs) to handle database operations.

##### Architectural Patterns or Design Principles
- Separation of Concerns: Different client applications for admin and customer roles.
- RESTful API Architecture: Clear division in server/api for admin and customer endpoints.
- Modular Design: The use of contexts in the React applications and DAOs/utilities in the server for clear modularity.
- Security Practices: Utilization of JwtUtil for authentication and CryptoUtil for data security.

##### Relevant Technologies, Frameworks, and Libraries
- React.js for frontend interfaces.
- Node.js and Express (implied by the API structure) for the backend.
- MongoDB (inferred from MongooseUtil) for persistent data storage.
- Utility libraries for authentication (JWT), encryption, and email handling.
- Possibly CSS frameworks or libraries for styling (as there are CSS files in the client folders).

##### Essential Elements
- Annotations that explain key responsibilities (like “Handles Authentication via JWT” next to the server’s security utilities).

- Two distinct frontends (admin and customer) developed in React.
- A centralized Node.js backend that exposes RESTful APIs partitioned into admin and customer sections.
- A database service that the backend communicates with (using DAOs, Mongoose, etc.).
- Auxiliary utilities/components that manage authentication, encryption, and other services.

This detailed, componential approach will effectively communicate the overall architecture and essential interdependencies within the online shopping system.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Frontend Layer
    subgraph "Frontend"
        A["Client Admin UI (React)"]:::frontend
        AComp["Admin UI Components\n(Category, Product, Order)"]:::frontend
        B["Client Customer UI (React)"]:::frontend
        BComp["Customer UI Components\n(Home, Login, Signup, Mycart, ProductDetail)"]:::frontend
        CartUtil["Cart Utility"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend"
        Server["Server Backend (Node.js REST API)"]:::backend
        AAPI["Admin API Endpoints"]:::backend
        CAPI["Customer API Endpoints"]:::backend
        DAOs["Data Access Objects\n(Admin, Customer, Category, Order, Product)"]:::backend
        Utils["Security & Utility Modules\n(JwtUtil, CryptoUtil, MongooseUtil)"]:::backend
        Email["Email Integration Utility"]:::backend
    end

    %% Database and External Services
    DB["Database (MongoDB)"]:::database
    Ext["Email/ThirdParty Services"]:::external

    %% Relationships in Frontend
    A -->|"contains"| AComp
    B -->|"contains"| BComp
    B -->|"uses"| CartUtil

    %% Client to Server interactions
    A -->|"REST_call"| Server
    B -->|"REST_call"| Server

    %% Internal Server Structure
    Server -->|"exposes"| AAPI
    Server -->|"exposes"| CAPI
    Server -->|"uses"| DAOs
    Server -->|"uses"| Utils
    Server -->|"uses"| Email

    %% Server interactions with Database and External Services
    Server -->|"DB_operations"| DB
    Email -->|"sends_notifications"| Ext

    %% Click Events
    click A "https://github.com/thong8888/shoppingonline/tree/main/client-admin/"
    click AComp "https://github.com/thong8888/shoppingonline/tree/main/client-admin/src/components/"
    click B "https://github.com/thong8888/shoppingonline/tree/main/client-customer/"
    click BComp "https://github.com/thong8888/shoppingonline/tree/main/client-customer/src/components/"
    click CartUtil "https://github.com/thong8888/shoppingonline/blob/main/client-customer/src/utils/CartUtil.js"
    click Server "https://github.com/thong8888/shoppingonline/tree/main/server/"
    click AAPI "https://github.com/thong8888/shoppingonline/blob/main/server/api/admin.js"
    click CAPI "https://github.com/thong8888/shoppingonline/blob/main/server/api/customer.js"
    click DAOs "https://github.com/thong8888/shoppingonline/tree/main/server/models/"
    click Utils "https://github.com/thong8888/shoppingonline/tree/main/server/utils/"
    click Email "https://github.com/thong8888/shoppingonline/blob/main/server/utils/EmailUtil.js"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef database fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef external fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
```
