# zlix1214/ecommerce architecture

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

- Interactive diagram: https://gitdiagram.com/zlix1214/ecommerce
- Repository: https://github.com/zlix1214/ecommerce

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) e-commerce application with two React front ends (a customer-facing storefront and an admin dashboard) and a Node/Express backend.
- Purpose:
– Frontend: users browse products, manage shopping cart, place orders, view order history.
– Admin: authorized personnel add/edit/delete products, manage orders, view statistics.
– Backend: exposes RESTful APIs for authentication, product catalog, cart, order processing; persists data in MongoDB; stores images in Cloudinary.

##### File structure
Top-level directories:
- frontend/ – React/Vite customer UI
- admin/ – React/Vite admin dashboard
- backend/ – Node/Express API server
Key substructures:
- frontend/src and admin/src: component hierarchies, pages, shared assets.
- backend/controllers, routes, models, middleware, config: standard MVC pattern.
- config/coludinary.js and config/mongodb.js: external service configs.
- Vercel configuration files in each folder: indicates deployment on Vercel (static hosting for front ends, serverless or Node process for backend).

##### Extract insights from the README
- Technologies: React + Tailwind + Vite, Express, MongoDB Atlas, Cloudinary, JWT auth.
- Features: separate user/admin flows, full CRUD for products and orders, authentication/authorization, image upload.
- Deployment: front ends on Vercel, backend on Vercel or an equivalent cloud provider.

##### Main components
- Customer Frontend (React/Vite)
- Admin Frontend (React/Vite)
- API Gateway / Backend (Node.js + Express)
- Authentication (JWT middleware)
- Database (MongoDB Atlas)
- Image Storage (Cloudinary)
- Hosting/Deployment (Vercel static for UIs, Vercel serverless/functions or Node server for API)

##### Relationships and interactions
- Backend → MongoDB Atlas for CRUD operations on user, product, order collections.
- Backend → Cloudinary for image upload/download.
- Auth flow: backend issues JWT; UIs attach JWT in Authorization header; backend middleware validates.
- Deployment: show that frontends are built and served as static assets; backend runs as serverless functions or Node process.

##### Architectural patterns and design principles
- MVC within backend: models, controllers, routes, middleware
- Component-based UI in React, separation of pages and shared components
- Context API (ShopContext) in customer UI for state management
- Environment-driven configuration (.env) for secrets and service URLs
- Layered security: auth middleware, adminAuth middleware

##### Detail and clarity
- Major folder as a component when relevant (e.g., ShopContext in frontend).
- Middleware (auth and adminAuth) as part of request flow in the API.
- Environment variables feeding into services.
- Keep labels concise but precise.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Vercel("Vercel"):::external

    subgraph "Customer Frontend (React/Vite)"
        direction TB
        CF_Main["Entry Point: main.jsx"]:::frontend
        CF_App["Root Component: App.jsx"]:::frontend
        CF_Pages["Pages Directory"]:::frontend
        CF_Components["Shared Components"]:::frontend
        CF_Context["ShopContext"]:::frontend
        CF_Assets["Assets"]:::frontend
        CF_ViteConfig["Build Config: vite.config.js"]:::frontend
        CF_VercelConfig["Deployment Config: vercel.json"]:::frontend
    end

    subgraph "Admin Dashboard (React/Vite)"
        direction TB
        AD_Main["Entry Point: main.jsx"]:::frontend
        AD_App["Root Component: App.jsx"]:::frontend
        AD_Pages["Pages Directory"]:::frontend
        AD_Components["Shared Components"]:::frontend
        AD_Assets["Assets"]:::frontend
        AD_ViteConfig["Build Config: vite.config.js"]:::frontend
        AD_VercelConfig["Deployment Config: vercel.json"]:::frontend
    end

    subgraph "Backend API (Node.js + Express)"
        direction TB
        BE_Server["Server Entry: server.js"]:::backend
        subgraph "Config"
            BE_MongoCfg["MongoDB Config"]:::backend
            BE_CloudCfg["Cloudinary Config"]:::backend
        end
        subgraph "Controllers"
            direction TB
            BE_ProductCtrl["Product Controller"]:::backend
            BE_CartCtrl["Cart Controller"]:::backend
            BE_OrderCtrl["Order Controller"]:::backend
            BE_UserCtrl["User Controller"]:::backend
        end
        subgraph "Routes"
            direction TB
            BE_ProductRoute["Product Routes"]:::backend
            BE_CartRoute["Cart Routes"]:::backend
            BE_OrderRoute["Order Routes"]:::backend
            BE_UserRoute["User Routes"]:::backend
        end
        subgraph "Models"
            direction TB
            BE_ProductModel["Product Model"]:::data
            BE_OrderModel["Order Model"]:::data
            BE_UserModel["User Model"]:::data
        end
        subgraph "Middleware"
            direction TB
            BE_Auth["JWT Auth Middleware"]:::backend
            BE_AdminAuth["Admin Auth Middleware"]:::backend
            BE_Multer["File Upload Middleware"]:::backend
        end
        BE_VercelConfig["Deployment Config: vercel.json"]:::backend
    end

    subgraph "Data & External Services"
        direction TB
        MongoDB["MongoDB Atlas"]:::data
        Cloudinary["Cloudinary"]:::external
    end

    Vercel -->|deploys| CF_Main
    Vercel -->|deploys| AD_Main
    Vercel -->|deploys| BE_Server

    CF_Main -->|imports App.jsx| CF_App
    AD_Main -->|imports App.jsx| AD_App

    CF_App --> CF_Pages
    CF_App --> CF_Components
    CF_App --> CF_Context
    CF_App --> CF_Assets

    AD_App --> AD_Pages
    AD_App --> AD_Components
    AD_App --> AD_Assets

    CF_ViteConfig -.-> CF_Main
    CF_VercelConfig -.-> CF_Main

    AD_ViteConfig -.-> AD_Main
    AD_VercelConfig -.-> AD_Main

    BE_MongoCfg -.-> BE_Server
    BE_CloudCfg -.-> BE_Server
    BE_VercelConfig -.-> BE_Server

    BE_Server --> BE_ProductRoute
    BE_Server --> BE_CartRoute
    BE_Server --> BE_OrderRoute
    BE_Server --> BE_UserRoute

    BE_ProductRoute --> BE_ProductCtrl
    BE_CartRoute --> BE_CartCtrl
    BE_OrderRoute --> BE_OrderCtrl
    BE_UserRoute --> BE_UserCtrl

    BE_ProductCtrl --> BE_ProductModel
    BE_CartCtrl --> BE_OrderModel
    BE_OrderCtrl --> BE_OrderModel
    BE_UserCtrl --> BE_UserModel

    BE_Server --> BE_Auth
    BE_Server --> BE_AdminAuth
    BE_Server --> BE_Multer

    CF_Main -->|REST calls/JWT| BE_Server
    AD_Main -->|REST calls/JWT| BE_Server

    BE_Server -->|CRUD operations| MongoDB
    BE_Server -->|Image upload/download| Cloudinary

    classDef frontend fill:#CCE5FF,stroke:#0366d6,color:#000
    classDef backend fill:#CCFFCC,stroke:#228B22,color:#000
    classDef data fill:#FFECB3,stroke:#FF8C00,color:#000
    classDef external fill:#E2D5F8,stroke:#7D3C98,color:#000

    click CF_Main "https://github.com/zlix1214/ecommerce/blob/main/frontend/src/main.jsx"
    click CF_App "https://github.com/zlix1214/ecommerce/blob/main/frontend/src/App.jsx"
    click CF_Pages "https://github.com/zlix1214/ecommerce/tree/main/frontend/src/pages/"
    click CF_Components "https://github.com/zlix1214/ecommerce/tree/main/frontend/src/components/"
    click CF_Context "https://github.com/zlix1214/ecommerce/blob/main/frontend/src/context/ShopContext.jsx"
    click CF_Assets "https://github.com/zlix1214/ecommerce/blob/main/frontend/src/assets/assets.js"
    click CF_ViteConfig "https://github.com/zlix1214/ecommerce/blob/main/frontend/vite.config.js"
    click CF_VercelConfig "https://github.com/zlix1214/ecommerce/blob/main/frontend/vercel.json"

    click AD_Main "https://github.com/zlix1214/ecommerce/blob/main/admin/src/main.jsx"
    click AD_App "https://github.com/zlix1214/ecommerce/blob/main/admin/src/App.jsx"
    click AD_Pages "https://github.com/zlix1214/ecommerce/tree/main/admin/src/pages/"
    click AD_Components "https://github.com/zlix1214/ecommerce/tree/main/admin/src/components/"
    click AD_Assets "https://github.com/zlix1214/ecommerce/blob/main/admin/src/assets/assets.js"
    click AD_ViteConfig "https://github.com/zlix1214/ecommerce/blob/main/admin/vite.config.js"
    click AD_VercelConfig "https://github.com/zlix1214/ecommerce/blob/main/admin/vercel.json"

    click BE_Server "https://github.com/zlix1214/ecommerce/blob/main/backend/server.js"
    click BE_MongoCfg "https://github.com/zlix1214/ecommerce/blob/main/backend/config/mongodb.js"
    click BE_CloudCfg "https://github.com/zlix1214/ecommerce/blob/main/backend/config/coludinary.js"
    click BE_ProductCtrl "https://github.com/zlix1214/ecommerce/blob/main/backend/controllers/productController.js"
    click BE_CartCtrl "https://github.com/zlix1214/ecommerce/blob/main/backend/controllers/cartController.js"
    click BE_OrderCtrl "https://github.com/zlix1214/ecommerce/blob/main/backend/controllers/orderController.js"
    click BE_UserCtrl "https://github.com/zlix1214/ecommerce/blob/main/backend/controllers/userController.js"
    click BE_ProductRoute "https://github.com/zlix1214/ecommerce/blob/main/backend/routes/productRoute.js"
    click BE_CartRoute "https://github.com/zlix1214/ecommerce/blob/main/backend/routes/cartRoute.js"
    click BE_OrderRoute "https://github.com/zlix1214/ecommerce/blob/main/backend/routes/orderRoute.js"
    click BE_UserRoute "https://github.com/zlix1214/ecommerce/blob/main/backend/routes/userRoute.js"
    click BE_ProductModel "https://github.com/zlix1214/ecommerce/blob/main/backend/models/productModel.js"
    click BE_OrderModel "https://github.com/zlix1214/ecommerce/blob/main/backend/models/orderModel.js"
    click BE_UserModel "https://github.com/zlix1214/ecommerce/blob/main/backend/models/userModel.js"
    click BE_Auth "https://github.com/zlix1214/ecommerce/blob/main/backend/middleware/auth.js"
    click BE_AdminAuth "https://github.com/zlix1214/ecommerce/blob/main/backend/middleware/adminAuth.js"
    click BE_Multer "https://github.com/zlix1214/ecommerce/blob/main/backend/middleware/multer.js"
    click BE_VercelConfig "https://github.com/zlix1214/ecommerce/blob/main/backend/vercel.json"
```
