# minhwuan1309/techstore architecture

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

## Overview

##### Major Components
- Frontend Application: Built with ReactJS. It is clearly structured into pages (client, admin, public), components (e.g., headers, footers, products, charts), state management (Redux slices for products and user), and various utilities. The frontend is responsible for displaying the UI on both client and admin sides.
- Backend API Server: Implemented with Express.js. Within the backend, you have a clear separation of controllers (handling business logic), models (Mongoose schemas for Product, User, Order, etc.), routes (mapping endpoints), services (business logic that may be shared), and utilities/middleware (JWT, error handling, socket configurations).
- Database: MongoDB is used for persistent data storage (customers, orders, products, blogs). It connects through Mongoose.
- Cloud Services: Cloudinary is integrated for media (image) storage; MongoDB Atlas for hosting the database; and external APIs like TinyMCE for rich text editing.
- Real-time Communication: Socket.IO is integrated on both frontend and backend to support chat functionality.
- Security & Authentication: Uses JWT (access/refresh) with middleware to enforce role-based access (admin, member).

##### Relationships & Data Flow
- JWT tokens are exchanged during user authentication. This flow should be depicted by showing an authentication process (login) between the frontend and the backend.
- A live chat feature utilizing Socket.IO runs between the frontend’s Socket.IO Client and the backend’s Socket.IO server (configured under backend/config/socket.js). Represent this as a bidirectional communication channel.
- Email notifications are managed via Nodemailer, so you might include a small component for “Email Service,” triggered by backend events.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Application Subgraph
    subgraph "Frontend Application"
        FP["Pages"]:::frontend
        FC["Components"]:::frontend
        FS["State Management (Redux)"]:::frontend
        FA["React App"]:::frontend
    end

    %% Backend API Server Subgraph
    subgraph "Backend API Server"
        BE["Server Entry Point"]:::backend
        BR["Routes"]:::backend
        BC["Controllers"]:::backend
        BS["Services"]:::backend
        BM["Models"]:::backend
        BJ["JWT Middleware"]:::backend
        BV["VerifyToken Middleware"]:::backend
        BSock["Socket.IO Config"]:::backend
        DBC["DB Connector"]:::backend
    end

    %% External and Database Nodes
    DB(("Database (MongoDB)")):::db
    CLD["Cloud Services (Cloudinary)"]:::external
    ES["Email Service"]:::external
    SIO["Socket.IO (Real-time Chat)"]:::external

    %% Connections between Frontend and Backend
    FA -->|"HTTPRequests"| BR
    %% Backend internal flow
    BE -->|"initRoutes"| BR
    BR -->|"calls"| BC
    BC -->|"invokes"| BS
    BS -->|"interacts"| BM
    BM -->|"persistsData"| DB
    BE -->|"applies"| BJ
    BE -->|"applies"| BV
    BE -->|"connects"| DBC
    DBC -->|"connectsTo"| DB
    BE -->|"uploads"| CLD
    BE -->|"notifies"| ES
    BE -->|"configures"| BSock

    %% Socket.IO bidirectional communication
    FA <-->|"RealtimeChat"| SIO
    BSock <-->|"syncs"| SIO

    %% Click Events for Frontend
    click FP "https://github.com/minhwuan1309/techstore/tree/main/frontend/src/pages/"
    click FC "https://github.com/minhwuan1309/techstore/tree/main/frontend/src/components/"
    click FS "https://github.com/minhwuan1309/techstore/tree/main/frontend/src/store/"
    %% Click Events for Backend
    click BC "https://github.com/minhwuan1309/techstore/tree/main/backend/controllers/"
    click BR "https://github.com/minhwuan1309/techstore/tree/main/backend/routes/"
    click BM "https://github.com/minhwuan1309/techstore/tree/main/backend/models/"
    click BS "https://github.com/minhwuan1309/techstore/tree/main/backend/services/"
    click BE "https://github.com/minhwuan1309/techstore/blob/main/backend/server.js"
    click DBC "https://github.com/minhwuan1309/techstore/blob/main/backend/config/dbconnect.js"
    click BSock "https://github.com/minhwuan1309/techstore/blob/main/backend/config/socket.js"
    click BJ "https://github.com/minhwuan1309/techstore/blob/main/backend/middlewares/jwt.js"
    click BV "https://github.com/minhwuan1309/techstore/blob/main/backend/middlewares/verifyToken.js"
    %% Click Events for External/Config Components
    click CLD "https://github.com/minhwuan1309/techstore/blob/main/backend/config/cloudinary.config.js"
    click ES "https://github.com/minhwuan1309/techstore/blob/main/backend/utils/sendMail.js"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#00008B,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#006400,stroke-width:2px;
    classDef db fill:#FFD700,stroke:#B8860B,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#FF4500,stroke-width:2px;
```
