# hongphuc-ng24/doan_reactjs architecture

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

## Overview

##### Project type and purpose
- This is a full-stack e-commerce / content site with a React-based front end and a Node.js/Express back end.
- The front end has both public (user) pages and an admin interface; the back end exposes REST endpoints for products, news, users, carts, and handles file uploads and static asset serving.

##### File structure
- Top level splits into `front-end/` and `back-end/`.
- `front-end/src/`: React components organized by feature (layouts, pages, components, services, utils, routes).
- `back-end/src/`: Express server (`server.js`); configuration (`config/db.js`); route modules, controllers, models, and middlewares.
- Static assets: `front-end/public/` and `back-end/public/` + `back-end/src/uploads`.
- Deployment/build scripts: package.json in each directory; `npm run dev`, `npm start` in README.

##### README
- Minimal: start commands. Assumes dev mode spins up front- and back-end.

##### Main components of the system
a. Front-end application (React SPA)
- User-facing pages: Home, Product listing/detail, News, Cart, Contact
- Authentication pages: Login, SignUp
- Admin pages: Product management, News management, User management
- Client-side services: `productServices.js`, `userServices.js`, `newServices.js` calling the API via `httpRequest.js`.
b. Back-end API (Node.js + Express)
- Router layer: `src/routes/*.js`
- Controller layer: `src/controllers/*.js`
- Data layer: Mongoose models (`src/models/*.js`) connecting to MongoDB via `src/config/db.js`
- Middlewares: `authMiddleware.js`, file upload handler (`upload.js`)
- Static file serving: Express hosts `public/products/*` and `uploads`
c. Database
- MongoDB (implied by `.env` and `config/db.js`)
d. Static asset storage
- A local filesystem directory for product images (`back-end/src/uploads/products`) and public assets.
e. Optional external services
- Could include third-party authentication (JWT in `authMiddleware`), email or chat services (UI has Chatbox component).

##### Relationships and interactions
- React UI issues HTTP(S) requests to Express API endpoints.
- Express controllers validate/authenticate via middleware, then invoke model operations on MongoDB.
- On product upload, Express writes files to `uploads` and persists metadata in MongoDB.
- MongoDB returns data to controllers, which send JSON back to React.
- React updates UI state accordingly.

##### Architectural patterns & design principles
- Client–server separation (React front end vs. RESTful back end)
- Layered back-end: routing → controller → service/data → DB
- Single-page application with client-side routing (`react-router`)
- MVC-like structure in back end (models, views=JSON, controllers)
- Use of middleware for cross-cutting concerns (authentication, file uploads)

##### Detail
- Every subsystem: client routing, API endpoints, business logic, data persistence, static asset pipeline.
- Build steps/triggers if needed (e.g. `npm run build` → CI/CD pipeline → static host).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Front-end
    subgraph "Front-end (React SPA)"
        direction TB
        App["App.js"]:::frontend
        subgraph "User Pages"
            direction TB
            Home["Home.jsx"]:::frontend
            ProductList["Product.jsx"]:::frontend
            ProductDetail["ProductDetail.jsx"]:::frontend
            SearchComponent["searchProduct.jsx"]:::frontend
            NewsList["new.jsx"]:::frontend
            NewsDetail["NewsDetail.jsx"]:::frontend
            Cart["Cart.jsx"]:::frontend
            Contact["Contact.jsx"]:::frontend
        end
        subgraph "Authentication Pages"
            direction TB
            Login["Login.jsx"]:::frontend
            SignUp["SignUp.jsx"]:::frontend
        end
        subgraph "Admin Pages"
            direction TB
            ProdMgmt["Product.jsx"]:::frontend
            NewsMgmt["index.jsx"]:::frontend
            UserMgmt["Users.jsx"]:::frontend
        end
        subgraph "Services & Utils"
            direction TB
            ProductService["productServices.js"]:::frontend
            NewsService["newServices.js"]:::frontend
            UserService["userServices.js"]:::frontend
            HTTPRequest["httpRequest.js"]:::frontend
        end
        subgraph "Routing"
            direction TB
            Routes["rout.jsx"]:::frontend
            PrivateRoute["PrivateRoute.jsx"]:::frontend
        end
        Chatbox["chatbox.jsx"]:::frontend
    end

    %% Back-end
    subgraph "Back-end (Node/Express)"
        direction TB
        Server["server.js"]:::backend
        AppConfig["app.js"]:::backend
        subgraph "Router Layer"
            direction TB
            IndexRoutes["index.js"]:::backend
            ProductRoutes["productRoutes.js"]:::backend
            NewsRoutes["newsRoutes.js"]:::backend
            UserRoutes["userRoutes.js"]:::backend
            CartRoutes["cartRoutes.js"]:::backend
            HomeRoutes["homeRoutes.js"]:::backend
        end
        subgraph "Controller Layer"
            direction TB
            ProductController["productController.js"]:::backend
            NewsController["newController.js"]:::backend
            UserController["userController.js"]:::backend
            CartController["cartController.js"]:::backend
            HomeController["homeController.js"]:::backend
        end
        subgraph "Middleware"
            direction TB
            AuthMiddleware["authMiddleware.js"]:::backend
            UploadMiddleware["upload.js"]:::backend
        end
        subgraph "Data Models"
            direction TB
            ProductModel["Product.js"]:::backend
            NewsModel["news.js"]:::backend
            UserModel["User.js"]:::backend
            CartModel["Cart.js"]:::backend
            HomeModel["home.js"]:::backend
        end
        DBConfig["db.js"]:::backend
    end

    %% Database and Storage
    MongoDB["MongoDB"]:::db
    FileStore["File Storage"]:::storage

    %% Connections
    App -->|imports| Routes
    App -->|renders| Home & ProductList & ProductDetail & NewsList & NewsDetail & Cart & Contact & Login & SignUp & ProdMgmt & NewsMgmt & UserMgmt & Chatbox
    Routes -->|uses| PrivateRoute
    App -->|calls| ProductService & NewsService & UserService & HTTPRequest
    ProductService & NewsService & UserService & HTTPRequest -->|HTTP JSON| IndexRoutes
    IndexRoutes -->|forwards /api/products| ProductRoutes
    IndexRoutes -->|forwards /api/news| NewsRoutes
    IndexRoutes -->|forwards /api/users| UserRoutes
    IndexRoutes -->|forwards /api/cart| CartRoutes
    IndexRoutes -->|forwards /api/home| HomeRoutes
    ProductRoutes -->|calls| AuthMiddleware & UploadMiddleware & ProductController
    NewsRoutes -->|calls| AuthMiddleware & NewsController
    UserRoutes -->|calls| AuthMiddleware & UserController
    CartRoutes -->|calls| AuthMiddleware & CartController
    HomeRoutes -->|calls| HomeController
    ProductController & NewsController & UserController & CartController & HomeController -->|use| DBConfig
    DBConfig -->|connects| MongoDB
    ProductController -->|reads/writes| ProductModel
    NewsController -->|reads/writes| NewsModel
    UserController -->|reads/writes| UserModel
    CartController -->|reads/writes| CartModel
    HomeController -->|reads/writes| HomeModel
    UploadMiddleware -->|stores files| FileStore
    AppConfig -->|serves static| FileStore
    FileStore -->|serves assets| App

    %% Click Events Front-end
    click App "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/App.js"
    click Home "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/Home/Home.jsx"
    click ProductList "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/Product/Product.jsx"
    click ProductDetail "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/Product/ProductDetail.jsx"
    click SearchComponent "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/Product/searchProduct.jsx"
    click NewsList "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/News/new.jsx"
    click NewsDetail "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/News/NewsDetail.jsx"
    click Cart "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/Cart/Cart.jsx"
    click Contact "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/UserPage/Contact/Contact.jsx"
    click Login "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/Authentication/Login/Login.jsx"
    click SignUp "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/Authentication/SignUp/SignUp.jsx"
    click ProdMgmt "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/AdminPage/ProductManagement/Product.jsx"
    click NewsMgmt "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/AdminPage/NewPage/index.jsx"
    click UserMgmt "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/pages/AdminPage/UserManagement/Users.jsx"
    click ProductService "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/services/productServices.js"
    click NewsService "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/services/newServices.js"
    click UserService "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/services/userServices.js"
    click HTTPRequest "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/utils/httpRequest.js"
    click Routes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/routes/rout.jsx"
    click PrivateRoute "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/routes/PrivateRoute.jsx"
    click Chatbox "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/front-end/src/components/Chatbox/chatbox.jsx"

    %% Click Events Back-end
    click Server "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/server.js"
    click AppConfig "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/app.js"
    click DBConfig "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/config/db.js"
    click ProductRoutes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/routes/productRoutes.js"
    click NewsRoutes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/routes/newsRoutes.js"
    click UserRoutes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/routes/userRoutes.js"
    click CartRoutes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/routes/cartRoutes.js"
    click HomeRoutes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/routes/homeRoutes.js"
    click IndexRoutes "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/routes/index.js"
    click ProductController "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/controllers/productController.js"
    click NewsController "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/controllers/newController.js"
    click UserController "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/controllers/userController.js"
    click CartController "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/controllers/cartController.js"
    click HomeController "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/controllers/homeController.js"
    click ProductModel "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/models/Product.js"
    click NewsModel "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/models/news.js"
    click UserModel "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/models/User.js"
    click CartModel "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/models/Cart.js"
    click HomeModel "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/models/home.js"
    click AuthMiddleware "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/middlewares/authMiddleware.js"
    click UploadMiddleware "https://github.com/hongphuc-ng24/doan_reactjs/blob/main/back-end/src/middlewares/upload.js"
    click FileStore "https://github.com/hongphuc-ng24/doan_reactjs/tree/main/back-end/src/uploads/products"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef db fill:#FFA500,stroke:#000
    classDef storage fill:#D3D3D3,stroke:#000
```
