# abisek-ux/agrinew architecture

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

- Interactive diagram: https://gitdiagram.com/abisek-ux/agrinew
- Repository: https://github.com/abisek-ux/agrinew

## Overview

AgriLink is a farm-to-table marketplace with farmer, customer, and delivery portals. Users select a portal, authenticate, and then use role-specific workflows for listing and discovering produce, bargaining, ordering, and delivery. The React client calls an Express API; controllers coordinate domain logic and persist through MongoDB models or in-memory fallbacks. The source index documents additional AI, review, notification, and bargaining capabilities. Some client components and server routes were not excerpted, so those links rely on index references; other uncertain connections are omitted.

Main entry points: [`server/server.js`](https://github.com/abisek-ux/agrinew/blob/main/server/server.js) (Express API), [`client/src/App.jsx`](https://github.com/abisek-ux/agrinew/blob/main/client/src/App.jsx) (Portal router), [`client/src/services/api.js`](https://github.com/abisek-ux/agrinew/blob/main/client/src/services/api.js) (API client), [`server/controllers/orderController.js`](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/orderController.js) (Order management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client experience"]
  node_app["Portal router<br/>[App.jsx]"]
  node_portalchoice["Role selection"]
  node_customer["Customer portal<br/>[CustomerPortal.jsx]"]
  node_farmer["Farmer portal<br/>[FarmerPortal.jsx]"]
  node_delivery["Delivery portal<br/>[DeliveryPortal.jsx]"]
  node_tracking["Live tracking map"]
end

subgraph group_identity["Identity and access"]
  node_authui["Sign-in and registration<br/>[LandscapeAuth.jsx]"]
  node_authstate["Auth state<br/>[AuthContext.jsx]"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_authcontroller["Auth controller<br/>[authController.js]"]
  node_authguard["Token guard<br/>[authMiddleware.js]"]
end

subgraph group_commerce["Marketplace operations"]
  node_products["Product catalog"]
  node_orders["Order management<br/>[orderController.js]"]
  node_bargains["Price bargaining"]
  node_reviews["Product reviews"]
end

subgraph group_platform["API and persistence"]
  node_clientapi["API client<br/>[api.js]"]
  node_api["Express API<br/>[server.js]"]
  node_productmodel["Product records<br/>[Product.js]"]
  node_ordermodel["Order records<br/>[Order.js]"]
  node_database[("MongoDB connection<br/>[db.js]")]
end

subgraph group_support["Assistance and communication"]
  node_otp["Phone OTP service<br/>[phoneOtpService.js]"]
  node_ai["AgriLink AI<br/>[aiController.js]"]
  node_notifications["Notifications"]
end

node_actor(("Portal user"))

node_actor -->|"selects role"| node_portalchoice
node_portalchoice -->|"sets role"| node_app
node_app -->|"opens sign-in"| node_authui
node_app -->|"renders customer"| node_customer
node_app -->|"renders farmer"| node_farmer
node_app -->|"renders delivery"| node_delivery
node_app -->|"provides auth"| node_authstate
node_authui -->|"uses auth"| node_authstate
node_authstate -->|"calls auth"| node_clientapi
node_customer -->|"requests data"| node_clientapi
node_farmer -->|"requests data"| node_clientapi
node_delivery -->|"requests data"| node_clientapi
node_delivery -->|"uses map"| node_tracking
node_customer -->|"uses map"| node_tracking
node_clientapi -->|"sends auth requests"| node_authroutes
node_clientapi -.->|"sends API requests"| node_api
node_api -->|"mounts routes"| node_authroutes
node_api -.->|"mounts product routes"| node_products
node_api -.->|"mounts order routes"| node_orders
node_api -.->|"mounts bargain routes"| node_bargains
node_api -.->|"mounts review routes"| node_reviews
node_api -->|"mounts AI routes"| node_ai
node_authroutes -->|"dispatches handlers"| node_authcontroller
node_authroutes -->|"uses guard"| node_authguard
node_authcontroller -->|"uses phone OTP"| node_otp
node_authcontroller -->|"checks connection"| node_database
node_products -->|"reads and writes"| node_productmodel
node_products -->|"checks connection"| node_database
node_orders -->|"reads and writes"| node_ordermodel
node_orders -->|"updates stock"| node_productmodel
node_orders -->|"uses phone OTP"| node_otp
node_orders -->|"checks connection"| node_database
node_reviews -->|"checks order"| node_ordermodel
node_reviews -->|"updates ratings"| node_productmodel
node_reviews -->|"checks connection"| node_database
node_bargains -->|"uses notifications"| node_notifications

click node_app "https://github.com/abisek-ux/agrinew/blob/main/client/src/App.jsx"
click node_portalchoice "https://github.com/abisek-ux/agrinew/blob/main/client/src/components/PortalSelection.jsx"
click node_authui "https://github.com/abisek-ux/agrinew/blob/main/client/src/components/LandscapeAuth.jsx"
click node_authstate "https://github.com/abisek-ux/agrinew/blob/main/client/src/context/AuthContext.jsx"
click node_clientapi "https://github.com/abisek-ux/agrinew/blob/main/client/src/services/api.js"
click node_customer "https://github.com/abisek-ux/agrinew/blob/main/client/src/components/CustomerPortal.jsx"
click node_farmer "https://github.com/abisek-ux/agrinew/blob/main/client/src/components/FarmerPortal.jsx"
click node_delivery "https://github.com/abisek-ux/agrinew/blob/main/client/src/components/DeliveryPortal.jsx"
click node_tracking "https://github.com/abisek-ux/agrinew/blob/main/client/src/components/LiveTrackingMap.jsx"
click node_api "https://github.com/abisek-ux/agrinew/blob/main/server/server.js"
click node_authroutes "https://github.com/abisek-ux/agrinew/blob/main/server/routes/authRoutes.js"
click node_authcontroller "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/authController.js"
click node_authguard "https://github.com/abisek-ux/agrinew/blob/main/server/middleware/authMiddleware.js"
click node_otp "https://github.com/abisek-ux/agrinew/blob/main/server/services/phoneOtpService.js"
click node_products "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/productController.js"
click node_productmodel "https://github.com/abisek-ux/agrinew/blob/main/server/models/Product.js"
click node_orders "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/orderController.js"
click node_ordermodel "https://github.com/abisek-ux/agrinew/blob/main/server/models/Order.js"
click node_bargains "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/bargainController.js"
click node_reviews "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/reviewController.js"
click node_ai "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/aiController.js"
click node_notifications "https://github.com/abisek-ux/agrinew/blob/main/server/controllers/notificationController.js"
click node_database "https://github.com/abisek-ux/agrinew/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_portalchoice,node_customer,node_farmer,node_delivery,node_tracking,node_actor toneBlue
class node_authui,node_authstate,node_authroutes,node_authcontroller,node_authguard toneAmber
class node_products,node_orders,node_bargains,node_reviews toneMint
class node_clientapi,node_api,node_productmodel,node_ordermodel,node_database toneRose
class node_otp,node_ai,node_notifications toneIndigo
```

## Components

### Client experience

- [Portal router](https://github.com/abisek-ux/agrinew/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Role selection](https://github.com/abisek-ux/agrinew/blob/main/client/src/components/PortalSelection.jsx): `client/src/components/PortalSelection.jsx`
- [Customer portal](https://github.com/abisek-ux/agrinew/blob/main/client/src/components/CustomerPortal.jsx): `client/src/components/CustomerPortal.jsx`
- [Farmer portal](https://github.com/abisek-ux/agrinew/blob/main/client/src/components/FarmerPortal.jsx): `client/src/components/FarmerPortal.jsx`
- [Delivery portal](https://github.com/abisek-ux/agrinew/blob/main/client/src/components/DeliveryPortal.jsx): `client/src/components/DeliveryPortal.jsx`
- [Live tracking map](https://github.com/abisek-ux/agrinew/blob/main/client/src/components/LiveTrackingMap.jsx): `client/src/components/LiveTrackingMap.jsx`

### Identity and access

- [Sign-in and registration](https://github.com/abisek-ux/agrinew/blob/main/client/src/components/LandscapeAuth.jsx): `client/src/components/LandscapeAuth.jsx`
- [Auth state](https://github.com/abisek-ux/agrinew/blob/main/client/src/context/AuthContext.jsx): `client/src/context/AuthContext.jsx`
- [Auth routes](https://github.com/abisek-ux/agrinew/blob/main/server/routes/authRoutes.js): `server/routes/authRoutes.js`
- [Auth controller](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/authController.js): `server/controllers/authController.js`
- [Token guard](https://github.com/abisek-ux/agrinew/blob/main/server/middleware/authMiddleware.js): `server/middleware/authMiddleware.js`

### Marketplace operations

- [Product catalog](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/productController.js): `server/controllers/productController.js`
- [Order management](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/orderController.js): `server/controllers/orderController.js`
- [Price bargaining](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/bargainController.js): `server/controllers/bargainController.js`
- [Product reviews](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/reviewController.js): `server/controllers/reviewController.js`

### API and persistence

- [API client](https://github.com/abisek-ux/agrinew/blob/main/client/src/services/api.js): `client/src/services/api.js`
- [Express API](https://github.com/abisek-ux/agrinew/blob/main/server/server.js): `server/server.js`
- [Product records](https://github.com/abisek-ux/agrinew/blob/main/server/models/Product.js): `server/models/Product.js`
- [Order records](https://github.com/abisek-ux/agrinew/blob/main/server/models/Order.js): `server/models/Order.js`
- [MongoDB connection](https://github.com/abisek-ux/agrinew/blob/main/server/config/db.js): `server/config/db.js`

### Assistance and communication

- [Phone OTP service](https://github.com/abisek-ux/agrinew/blob/main/server/services/phoneOtpService.js): `server/services/phoneOtpService.js`
- [AgriLink AI](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/aiController.js): `server/controllers/aiController.js`
- [Notifications](https://github.com/abisek-ux/agrinew/blob/main/server/controllers/notificationController.js): `server/controllers/notificationController.js`

### Other components

- **Portal user**

## Connections

- Portal user → Role selection: selects role
- Role selection → Portal router: sets role (evidence: `client/src/App.jsx`)
- Portal router → Sign-in and registration: opens sign-in (evidence: `client/src/App.jsx`)
- Portal router → Customer portal: renders customer (evidence: `client/src/App.jsx`)
- Portal router → Farmer portal: renders farmer (evidence: `client/src/App.jsx`)
- Portal router → Delivery portal: renders delivery (evidence: `client/src/App.jsx`)
- Portal router → Auth state: provides auth (evidence: `client/src/App.jsx`)
- Sign-in and registration → Auth state: uses auth (evidence: `client/src/components/LandscapeAuth.jsx`)
- Auth state → API client: calls auth (evidence: `client/src/context/AuthContext.jsx`)
- Customer portal → API client: requests data (evidence: `client/src/components/CustomerPortal.jsx`)
- Farmer portal → API client: requests data (evidence: `client/src/components/FarmerPortal.jsx`)
- Delivery portal → API client: requests data (evidence: `client/src/components/DeliveryPortal.jsx`)
- Delivery portal → Live tracking map: uses map (evidence: `client/src/components/DeliveryPortal.jsx`)
- Customer portal → Live tracking map: uses map (evidence: `client/src/components/CustomerPortal.jsx`)
- API client → Auth routes: sends auth requests (evidence: `client/src/services/api.js`)
- API client → Express API: sends API requests
- Express API → Auth routes: mounts routes (evidence: `server/server.js`)
- Express API → Product catalog: mounts product routes (evidence: `server/server.js`)
- Express API → Order management: mounts order routes (evidence: `server/server.js`)
- Express API → Price bargaining: mounts bargain routes (evidence: `server/server.js`)
- Express API → Product reviews: mounts review routes (evidence: `server/server.js`)
- Express API → AgriLink AI: mounts AI routes (evidence: `server/server.js`)
- Auth routes → Auth controller: dispatches handlers (evidence: `server/routes/authRoutes.js`)
- Auth routes → Token guard: uses guard (evidence: `server/routes/authRoutes.js`)
- Auth controller → Phone OTP service: uses phone OTP (evidence: `server/controllers/authController.js`)
- Auth controller → MongoDB connection: checks connection (evidence: `server/controllers/authController.js`)
- Product catalog → Product records: reads and writes (evidence: `server/controllers/productController.js`)
- Product catalog → MongoDB connection: checks connection (evidence: `server/controllers/productController.js`)
- Order management → Order records: reads and writes (evidence: `server/controllers/orderController.js`)
- Order management → Product records: updates stock (evidence: `server/controllers/orderController.js`)
- Order management → Phone OTP service: uses phone OTP (evidence: `server/controllers/orderController.js`)
- Order management → MongoDB connection: checks connection (evidence: `server/controllers/orderController.js`)
- Product reviews → Order records: checks order (evidence: `server/controllers/reviewController.js`)
- Product reviews → Product records: updates ratings (evidence: `server/controllers/reviewController.js`)
- Product reviews → MongoDB connection: checks connection (evidence: `server/controllers/reviewController.js`)
- Price bargaining → Notifications: uses notifications (evidence: `server/controllers/bargainController.js`)
