# bhavana23jagadeesan/mongo_db architecture

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

- Interactive diagram: https://gitdiagram.com/bhavana23jagadeesan/mongo_db
- Repository: https://github.com/bhavana23jagadeesan/mongo_db

## Overview

AgriLink is a two-sided agricultural marketplace for buyers and farmers. Buyers authenticate, browse and filter approved produce, manage a cart, and access order tracking; farmers manage listings, orders, returns, payments, inventory, and business insights. The sampled backend routes implement authentication, product listings, order lifecycle, and analytics over MongoDB models. Several seller views and client API interactions were not excerpted, so their internal data flows are not asserted.

Main entry points: [`client/src/App.jsx`](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/App.jsx) (Role-based app), [`server/server.js`](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/server.js) (HTTP server), [`server/middleware/authMiddleware.js`](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/middleware/authMiddleware.js) (Token and role checks), [`server/routes/orderRoutes.js`](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/orderRoutes.js) (Order API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Marketplace client"]
  node_app["Role-based app<br/>[App.jsx]"]
  node_authui["Authentication dialog<br/>[AuthModal.jsx]"]
  node_authstate["Auth state<br/>[AuthContext.jsx]"]
  node_browse["Browse and filter<br/>[CategoryBar.jsx]"]
  node_productcard["Product cards<br/>[ProductCard.jsx]"]
  node_productdetail["Product details"]
  node_cartstate["Cart state<br/>[CartContext.jsx]"]
  node_cart["Cart and checkout<br/>[CartDrawer.jsx]"]
  node_buyerorders["Buyer orders<br/>[MyOrders.jsx]"]
end

subgraph group_seller["Farmer workspace"]
  node_sellerlist["Listings management<br/>[MyListings.jsx]"]
  node_listingedit["Listing editor"]
  node_sellerorders["Active orders"]
  node_sellerinsights["Seller insights<br/>[SellerSubViews.jsx]"]
  node_payments["Payments overview"]
end

subgraph group_api["API services"]
  node_server["HTTP server<br/>[server.js]"]
  node_authroutes["Authentication API<br/>[authRoutes.js]"]
  node_productsapi["Product API<br/>[productRoutes.js]"]
  node_ordersapi["Order API<br/>[orderRoutes.js]"]
  node_analyticsapi["Analytics API<br/>[analyticsRoutes.js]"]
  node_authmiddleware["Token and role checks<br/>[authMiddleware.js]"]
end

subgraph group_domain["Domain and persistence"]
  node_users[("User records<br/>[User.js]")]
  node_products[("Product records<br/>[Product.js]")]
  node_orders[("Order records<br/>[Order.js]")]
  node_dbconfig["Database connection<br/>[db.js]"]
end

node_buyer(("Buyer"))
node_farmer(("Farmer"))
node_mongo[("MongoDB")]

node_buyer -->|"uses marketplace"| node_app
node_farmer -->|"uses workspace"| node_app
node_app -->|"renders"| node_authui
node_app -->|"renders"| node_browse
node_app -->|"renders"| node_productcard
node_app -->|"renders"| node_productdetail
node_app -->|"renders"| node_cart
node_app -->|"renders"| node_buyerorders
node_app -->|"renders"| node_sellerlist
node_app -->|"renders"| node_listingedit
node_app -->|"renders"| node_sellerorders
node_app -->|"renders"| node_sellerinsights
node_app -->|"renders"| node_payments
node_app -->|"reads user"| node_authstate
node_app -->|"fetches products"| node_productsapi
node_authui -->|"uses auth"| node_authstate
node_productcard -->|"adds products"| node_cartstate
node_productdetail -->|"adds products"| node_cartstate
node_cart -->|"uses cart"| node_cartstate
node_buyerorders -->|"uses auth"| node_authstate
node_server -->|"mounts routes"| node_authroutes
node_server -->|"mounts routes"| node_productsapi
node_server -->|"mounts routes"| node_ordersapi
node_server -->|"mounts routes"| node_analyticsapi
node_authroutes -->|"reads and writes"| node_users
node_authroutes -->|"protects profile"| node_authmiddleware
node_productsapi -->|"reads and writes"| node_products
node_productsapi -->|"checks farmer"| node_authmiddleware
node_ordersapi -->|"reads and writes"| node_orders
node_ordersapi -->|"looks up product"| node_products
node_ordersapi -->|"checks access"| node_authmiddleware
node_analyticsapi -->|"queries analytics"| node_orders
node_analyticsapi -->|"queries analytics"| node_products
node_analyticsapi -->|"checks access"| node_authmiddleware
node_authmiddleware -->|"loads user"| node_users
node_server -->|"connects database"| node_dbconfig
node_dbconfig -->|"opens connection"| node_mongo

click node_app "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/App.jsx"
click node_authui "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/AuthModal.jsx"
click node_authstate "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/context/AuthContext.jsx"
click node_browse "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/CategoryBar.jsx"
click node_productcard "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/ProductCard.jsx"
click node_productdetail "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/ProductDetailModal.jsx"
click node_cartstate "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/context/CartContext.jsx"
click node_cart "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/CartDrawer.jsx"
click node_buyerorders "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/MyOrders.jsx"
click node_sellerlist "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/MyListings.jsx"
click node_listingedit "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/AddListingModal.jsx"
click node_sellerorders "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/ActiveOrdersView.jsx"
click node_sellerinsights "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/SellerSubViews.jsx"
click node_payments "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/PaymentsOverview.jsx"
click node_server "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/server.js"
click node_authroutes "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/authRoutes.js"
click node_productsapi "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/productRoutes.js"
click node_ordersapi "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/orderRoutes.js"
click node_analyticsapi "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/analyticsRoutes.js"
click node_authmiddleware "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/middleware/authMiddleware.js"
click node_users "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/models/User.js"
click node_products "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/models/Product.js"
click node_orders "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/models/Order.js"
click node_dbconfig "https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/config/db.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_authui,node_authstate,node_browse,node_productcard,node_productdetail,node_cartstate,node_cart,node_buyerorders toneBlue
class node_sellerlist,node_listingedit,node_sellerorders,node_sellerinsights,node_payments,node_mongo toneAmber
class node_server,node_authroutes,node_productsapi,node_ordersapi,node_analyticsapi,node_authmiddleware toneMint
class node_users,node_products,node_orders,node_dbconfig toneRose
class node_buyer,node_farmer toneIndigo
```

## Components

### Marketplace client

- [Role-based app](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Authentication dialog](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/AuthModal.jsx): `client/src/components/AuthModal.jsx`
- [Auth state](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/context/AuthContext.jsx): `client/src/context/AuthContext.jsx`
- [Browse and filter](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/CategoryBar.jsx): `client/src/components/buyer/CategoryBar.jsx`
- [Product cards](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/ProductCard.jsx): `client/src/components/buyer/ProductCard.jsx`
- [Product details](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/ProductDetailModal.jsx): `client/src/components/buyer/ProductDetailModal.jsx`
- [Cart state](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/context/CartContext.jsx): `client/src/context/CartContext.jsx`
- [Cart and checkout](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/CartDrawer.jsx): `client/src/components/buyer/CartDrawer.jsx`
- [Buyer orders](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/buyer/MyOrders.jsx): `client/src/components/buyer/MyOrders.jsx`

### Farmer workspace

- [Listings management](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/MyListings.jsx): `client/src/components/seller/MyListings.jsx`
- [Listing editor](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/AddListingModal.jsx): `client/src/components/seller/AddListingModal.jsx`
- [Active orders](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/ActiveOrdersView.jsx): `client/src/components/seller/ActiveOrdersView.jsx`
- [Seller insights](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/SellerSubViews.jsx): `client/src/components/seller/SellerSubViews.jsx`
- [Payments overview](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/client/src/components/seller/PaymentsOverview.jsx): `client/src/components/seller/PaymentsOverview.jsx`

### API services

- [HTTP server](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/server.js): `server/server.js`
- [Authentication API](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/authRoutes.js): `server/routes/authRoutes.js`
- [Product API](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/productRoutes.js): `server/routes/productRoutes.js`
- [Order API](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/orderRoutes.js): `server/routes/orderRoutes.js`
- [Analytics API](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/routes/analyticsRoutes.js): `server/routes/analyticsRoutes.js`
- [Token and role checks](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/middleware/authMiddleware.js): `server/middleware/authMiddleware.js`

### Domain and persistence

- [User records](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/models/User.js): `server/models/User.js`
- [Product records](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/models/Product.js): `server/models/Product.js`
- [Order records](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/models/Order.js): `server/models/Order.js`
- [Database connection](https://github.com/bhavana23jagadeesan/mongo_db/blob/main/server/config/db.js): `server/config/db.js`

### Other components

- **Buyer**
- **Farmer**
- **MongoDB**

## Connections

- Buyer → Role-based app: uses marketplace (evidence: `client/src/App.jsx`)
- Farmer → Role-based app: uses workspace (evidence: `client/src/App.jsx`)
- Role-based app → Authentication dialog: renders (evidence: `client/src/App.jsx`)
- Role-based app → Browse and filter: renders (evidence: `client/src/App.jsx`)
- Role-based app → Product cards: renders (evidence: `client/src/App.jsx`)
- Role-based app → Product details: renders (evidence: `client/src/App.jsx`)
- Role-based app → Cart and checkout: renders (evidence: `client/src/App.jsx`)
- Role-based app → Buyer orders: renders (evidence: `client/src/App.jsx`)
- Role-based app → Listings management: renders (evidence: `client/src/App.jsx`)
- Role-based app → Listing editor: renders (evidence: `client/src/App.jsx`)
- Role-based app → Active orders: renders (evidence: `client/src/App.jsx`)
- Role-based app → Seller insights: renders (evidence: `client/src/App.jsx`)
- Role-based app → Payments overview: renders (evidence: `client/src/App.jsx`)
- Role-based app → Auth state: reads user (evidence: `client/src/App.jsx`)
- Role-based app → Product API: fetches products (evidence: `client/src/App.jsx`)
- Authentication dialog → Auth state: uses auth (evidence: `client/src/components/AuthModal.jsx`)
- Product cards → Cart state: adds products (evidence: `client/src/components/buyer/ProductCard.jsx`)
- Product details → Cart state: adds products (evidence: `client/src/components/buyer/ProductDetailModal.jsx`)
- Cart and checkout → Cart state: uses cart (evidence: `client/src/components/buyer/CartDrawer.jsx`)
- Buyer orders → Auth state: uses auth (evidence: `client/src/components/buyer/MyOrders.jsx`)
- HTTP server → Authentication API: mounts routes (evidence: `server/server.js`)
- HTTP server → Product API: mounts routes (evidence: `server/server.js`)
- HTTP server → Order API: mounts routes (evidence: `server/server.js`)
- HTTP server → Analytics API: mounts routes (evidence: `server/server.js`)
- Authentication API → User records: reads and writes (evidence: `server/routes/authRoutes.js`)
- Authentication API → Token and role checks: protects profile (evidence: `server/routes/authRoutes.js`)
- Product API → Product records: reads and writes (evidence: `server/routes/productRoutes.js`)
- Product API → Token and role checks: checks farmer (evidence: `server/routes/productRoutes.js`)
- Order API → Order records: reads and writes (evidence: `server/routes/orderRoutes.js`)
- Order API → Product records: looks up product (evidence: `server/routes/orderRoutes.js`)
- Order API → Token and role checks: checks access (evidence: `server/routes/orderRoutes.js`)
- Analytics API → Order records: queries analytics (evidence: `server/routes/analyticsRoutes.js`)
- Analytics API → Product records: queries analytics (evidence: `server/routes/analyticsRoutes.js`)
- Analytics API → Token and role checks: checks access (evidence: `server/routes/analyticsRoutes.js`)
- Token and role checks → User records: loads user (evidence: `server/middleware/authMiddleware.js`)
- HTTP server → Database connection: connects database (evidence: `server/server.js`)
- Database connection → MongoDB: opens connection (evidence: `server/config/db.js`)
