# phucthinh2704/agri-ecommerce architecture

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

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

## Overview

FarmFresh is a full-stack produce-commerce application with a customer storefront and an admin panel. The main customer journey is browsing products, managing a cart, checking out, and reviewing orders; account access gates cart and order actions. Admins manage catalog, categories, users, and orders, with dashboard reporting. The backend exposes these domains through Express routes and MongoDB models. The README documents PayPal, Google OAuth, and Cloudinary capabilities; sampled source is incomplete, so some integration and route-to-client links are not asserted.

Main entry points: [`client/src/App.jsx`](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/App.jsx) (Route application), [`server/controllers/order.controller.js`](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/order.controller.js) (Order service), [`server/routes/index.js`](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/routes/index.js) (API route dispatch), [`server/controllers/chatbot.controller.js`](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/chatbot.controller.js) (AI assistant service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_storefront["Customer storefront"]
  node_app["Route application<br/>[App.jsx]"]
  node_login["Account access<br/>[Login.jsx]"]
  node_catalog["Product discovery<br/>[AllProducts.jsx]"]
  node_category["Category browsing<br/>[Category.jsx]"]
  node_detail["Product details<br/>[ProductDetail.jsx]"]
  node_cart["Shopping cart<br/>[Cart.jsx]"]
  node_checkout["Checkout<br/>[Checkout.jsx]"]
  node_orders["Order history<br/>[MyOrders.jsx]"]
  node_chat["Shopping assistant<br/>[Chatbot.jsx]"]
end

subgraph group_admin["Admin operations"]
  node_adminui["Admin dashboard<br/>[Dashboard.jsx]"]
  node_productadmin["Product management<br/>[ManageProducts.jsx]"]
  node_productedit["Product editor<br/>[UpdateProduct.jsx]"]
  node_categoryadmin["Category management"]
  node_orderadmin["Order management<br/>[ManageOrders.jsx]"]
  node_useradmin["User management<br/>[ManageUsers.jsx]"]
end

subgraph group_backend["Backend services"]
  node_routes["API route dispatch<br/>[index.js]"]
  node_authsvc["Identity service<br/>[user.controller.js]"]
  node_products["Catalog service"]
  node_cartsvc["Cart service<br/>[cart.controller.js]"]
  node_ordersvc["Order service"]
  node_categories["Category service"]
  node_chatbot["AI assistant service"]
  node_upload["Image upload"]
end

subgraph group_data["MongoDB data"]
  node_authmodel[("User records<br/>[User.js]")]
  node_productmodel[("Product records<br/>[Product.js]")]
  node_cartmodel[("Cart records<br/>[Cart.js]")]
  node_ordermodel[("Order records<br/>[Order.js]")]
  node_categorymodel[("Category records<br/>[Category.js]")]
end

node_customer(("Customer"))
node_google["Google OAuth"]
node_paypal["PayPal Sandbox"]
node_cloudinary["Cloudinary"]

node_customer -->|"browses"| node_app
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_catalog
node_app -->|"routes to"| node_category
node_app -->|"routes to"| node_detail
node_app -->|"protects route"| node_cart
node_app -->|"protects route"| node_checkout
node_app -->|"protects route"| node_orders
node_app -->|"routes to"| node_adminui
node_app -->|"routes to"| node_productadmin
node_app -->|"routes to"| node_categoryadmin
node_app -->|"routes to"| node_orderadmin
node_app -->|"routes to"| node_useradmin
node_catalog -.->|"requests catalog"| node_products
node_category -.->|"requests categories"| node_categories
node_cart -.->|"updates cart"| node_cartsvc
node_checkout -->|"places order"| node_ordersvc
node_orders -->|"loads history"| node_ordersvc
node_login -->|"authenticates"| node_authsvc
node_login -->|"supports sign-in"| node_google
node_checkout -->|"offers payment"| node_paypal
node_productedit -.->|"uploads images"| node_upload
node_upload -->|"stores images"| node_cloudinary
node_routes -.->|"mounts user routes"| node_authsvc
node_routes -.->|"mounts product routes"| node_products
node_routes -.->|"mounts category routes"| node_categories
node_routes -.->|"mounts order routes"| node_ordersvc
node_routes -.->|"mounts cart routes"| node_cartsvc
node_routes -->|"mounts chat routes"| node_chatbot
node_authsvc -->|"reads and writes"| node_authmodel
node_products -->|"queries products"| node_productmodel
node_cartsvc -->|"reads and writes"| node_cartmodel
node_cartsvc -->|"loads products"| node_productmodel
node_ordersvc -->|"creates and queries"| node_ordermodel
node_ordersvc -->|"reads cart"| node_cartmodel
node_ordersvc -->|"adjusts stock"| node_productmodel
node_ordersvc -->|"searches users"| node_authmodel
node_chatbot -->|"searches products"| node_productmodel
node_chatbot -->|"checks orders"| node_ordermodel
node_chatbot -->|"queries categories"| node_categorymodel
node_chatbot -->|"reads cart"| node_cartmodel
node_categories -.->|"manages categories"| node_categorymodel
node_chat -.->|"sends messages"| node_chatbot

click node_app "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/App.jsx"
click node_login "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Login.jsx"
click node_catalog "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/AllProducts.jsx"
click node_category "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Category.jsx"
click node_detail "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/ProductDetail.jsx"
click node_cart "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Cart.jsx"
click node_checkout "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Checkout.jsx"
click node_orders "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/MyOrders.jsx"
click node_chat "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/components/Chatbot.jsx"
click node_adminui "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/Dashboard.jsx"
click node_productadmin "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageProducts.jsx"
click node_productedit "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/UpdateProduct.jsx"
click node_categoryadmin "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageCategories.jsx"
click node_orderadmin "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageOrders.jsx"
click node_useradmin "https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageUsers.jsx"
click node_routes "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/routes/index.js"
click node_authsvc "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/user.controller.js"
click node_products "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/product.controller.js"
click node_cartsvc "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/cart.controller.js"
click node_ordersvc "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/order.controller.js"
click node_categories "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/category.controller.js"
click node_chatbot "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/chatbot.controller.js"
click node_upload "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/upload.controller.js"
click node_authmodel "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/User.js"
click node_productmodel "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Product.js"
click node_cartmodel "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Cart.js"
click node_ordermodel "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Order.js"
click node_categorymodel "https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Category.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_login,node_catalog,node_category,node_detail,node_cart,node_checkout,node_orders,node_chat toneBlue
class node_adminui,node_productadmin,node_productedit,node_categoryadmin,node_orderadmin,node_useradmin toneAmber
class node_routes,node_authsvc,node_products,node_cartsvc,node_ordersvc,node_categories,node_chatbot,node_upload toneMint
class node_authmodel,node_productmodel,node_cartmodel,node_ordermodel,node_categorymodel toneRose
class node_customer,node_google,node_paypal,node_cloudinary toneIndigo
```

## Components

### Customer storefront

- [Route application](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/App.jsx): `client/src/App.jsx`
- [Account access](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Login.jsx): `client/src/pages/Login.jsx`
- [Product discovery](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/AllProducts.jsx): `client/src/pages/AllProducts.jsx`
- [Category browsing](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Category.jsx): `client/src/pages/Category.jsx`
- [Product details](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/ProductDetail.jsx): `client/src/pages/ProductDetail.jsx`
- [Shopping cart](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Cart.jsx): `client/src/pages/Cart.jsx`
- [Checkout](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/Checkout.jsx): `client/src/pages/Checkout.jsx`
- [Order history](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/MyOrders.jsx): `client/src/pages/MyOrders.jsx`
- [Shopping assistant](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/components/Chatbot.jsx): `client/src/components/Chatbot.jsx`

### Admin operations

- [Admin dashboard](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/Dashboard.jsx): `client/src/pages/admin/Dashboard.jsx`
- [Product management](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageProducts.jsx): `client/src/pages/admin/ManageProducts.jsx`
- [Product editor](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/UpdateProduct.jsx): `client/src/pages/admin/UpdateProduct.jsx`
- [Category management](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageCategories.jsx): `client/src/pages/admin/ManageCategories.jsx`
- [Order management](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageOrders.jsx): `client/src/pages/admin/ManageOrders.jsx`
- [User management](https://github.com/phucthinh2704/agri-ecommerce/blob/master/client/src/pages/admin/ManageUsers.jsx): `client/src/pages/admin/ManageUsers.jsx`

### Backend services

- [API route dispatch](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/routes/index.js): `server/routes/index.js`
- [Identity service](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/user.controller.js): `server/controllers/user.controller.js`
- [Catalog service](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/product.controller.js): `server/controllers/product.controller.js`
- [Cart service](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/cart.controller.js): `server/controllers/cart.controller.js`
- [Order service](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/order.controller.js): `server/controllers/order.controller.js`
- [Category service](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/category.controller.js): `server/controllers/category.controller.js`
- [AI assistant service](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/chatbot.controller.js): `server/controllers/chatbot.controller.js`
- [Image upload](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/controllers/upload.controller.js): `server/controllers/upload.controller.js`

### MongoDB data

- [User records](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/User.js): `server/models/User.js`
- [Product records](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Product.js): `server/models/Product.js`
- [Cart records](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Cart.js): `server/models/Cart.js`
- [Order records](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Order.js): `server/models/Order.js`
- [Category records](https://github.com/phucthinh2704/agri-ecommerce/blob/master/server/models/Category.js): `server/models/Category.js`

### Other components

- **Customer**
- **Google OAuth**
- **PayPal Sandbox**
- **Cloudinary**

## Connections

- Customer → Route application: browses
- Route application → Account access: routes to (evidence: `client/src/App.jsx`)
- Route application → Product discovery: routes to (evidence: `client/src/App.jsx`)
- Route application → Category browsing: routes to (evidence: `client/src/App.jsx`)
- Route application → Product details: routes to (evidence: `client/src/App.jsx`)
- Route application → Shopping cart: protects route (evidence: `client/src/App.jsx`)
- Route application → Checkout: protects route (evidence: `client/src/App.jsx`)
- Route application → Order history: protects route (evidence: `client/src/App.jsx`)
- Route application → Admin dashboard: routes to (evidence: `client/src/App.jsx`)
- Route application → Product management: routes to (evidence: `client/src/App.jsx`)
- Route application → Category management: routes to (evidence: `client/src/App.jsx`)
- Route application → Order management: routes to (evidence: `client/src/App.jsx`)
- Route application → User management: routes to (evidence: `client/src/App.jsx`)
- Product discovery → Catalog service: requests catalog
- Category browsing → Category service: requests categories
- Shopping cart → Cart service: updates cart
- Checkout → Order service: places order (evidence: `client/src/pages/Checkout.jsx`)
- Order history → Order service: loads history (evidence: `client/src/pages/MyOrders.jsx`)
- Account access → Identity service: authenticates
- Account access → Google OAuth: supports sign-in
- Checkout → PayPal Sandbox: offers payment
- Product editor → Image upload: uploads images
- Image upload → Cloudinary: stores images
- API route dispatch → Identity service: mounts user routes
- API route dispatch → Catalog service: mounts product routes
- API route dispatch → Category service: mounts category routes
- API route dispatch → Order service: mounts order routes
- API route dispatch → Cart service: mounts cart routes
- API route dispatch → AI assistant service: mounts chat routes (evidence: `server/routes/index.js`)
- Identity service → User records: reads and writes (evidence: `server/controllers/user.controller.js`)
- Catalog service → Product records: queries products (evidence: `server/controllers/product.controller.js`)
- Cart service → Cart records: reads and writes (evidence: `server/controllers/cart.controller.js`)
- Cart service → Product records: loads products (evidence: `server/controllers/cart.controller.js`)
- Order service → Order records: creates and queries (evidence: `server/controllers/order.controller.js`)
- Order service → Cart records: reads cart (evidence: `server/controllers/order.controller.js`)
- Order service → Product records: adjusts stock (evidence: `server/controllers/order.controller.js`)
- Order service → User records: searches users (evidence: `server/controllers/order.controller.js`)
- AI assistant service → Product records: searches products (evidence: `server/controllers/chatbot.controller.js`)
- AI assistant service → Order records: checks orders (evidence: `server/controllers/chatbot.controller.js`)
- AI assistant service → Category records: queries categories (evidence: `server/controllers/chatbot.controller.js`)
- AI assistant service → Cart records: reads cart (evidence: `server/controllers/chatbot.controller.js`)
- Category service → Category records: manages categories
- Shopping assistant → AI assistant service: sends messages
