# gochalamvinod/marketmind-ai architecture

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

- Interactive diagram: https://gitdiagram.com/gochalamvinod/marketmind-ai
- Repository: https://github.com/gochalamvinod/marketmind-ai

## Overview

MarketMind AI is a merchant-facing mandi price intelligence and inventory ERP. A trader authenticates, then uses the protected dashboard and workspaces to manage products, record inward purchases, review market benchmarks, and respond to alerts; a persistent assistant also accepts natural-language commands. The backend exposes REST routes to controllers, which coordinate MongoDB models, external price feeds, and monitoring. The README documents sales/profit insights and settings as further capabilities. Unsampled page and controller internals are represented at their exact paths; edges are limited to source-index references or explicit README relationships.

Main entry points: [`server/server.js`](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/server.js) (REST routes), [`server/controllers/chatbotController.js`](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/chatbotController.js) (Command assistant), [`client/src/components/layout/Layout.jsx`](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/components/layout/Layout.jsx) (App shell), [`server/services/priceMonitor.js`](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/services/priceMonitor.js) (Price monitor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Merchant workspace"]
  node_spa["Protected app<br/>[App.jsx]"]
  node_authui["Session state<br/>[AuthContext.jsx]"]
  node_shell["App shell<br/>[Layout.jsx]"]
  node_assistantui["Floating assistant"]
  node_dashboard["Dashboard<br/>[Dashboard.jsx]"]
  node_catalogui["Products<br/>[Products.jsx]"]
  node_purchasesui["Purchases<br/>[Purchases.jsx]"]
  node_pricesui["Market prices<br/>[MarketPrices.jsx]"]
  node_alertsui["Alerts<br/>[Notifications.jsx]"]
  node_settingsui["Store settings<br/>[Settings.jsx]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["API and domain actions"]
  node_routes["REST routes<br/>[server.js]"]
  node_auth["JWT verification<br/>[auth.js]"]
  node_chatbot["Command assistant"]
  node_products["Catalog operations"]
  node_purchases["Purchase ledger"]
  node_sales["Sales and profit<br/>[salesController.js]"]
  node_dashboard_api["Dashboard metrics"]
  node_alert_api["Alert management<br/>[alertController.js]"]
  node_settings_api["Settings management"]
end

subgraph group_market["Market intelligence"]
  node_market_api["Price endpoints"]
  node_monitor["Price monitor<br/>[priceMonitor.js]"]
  node_poller["Scheduled polling<br/>[priceChecker.js]"]
  node_govfeed["AGMARKNET feed<br/>[govApiService.js]"]
  node_gemini["Gemini service<br/>[gemini.js]"]
end

subgraph group_data["ERP records"]
  node_users[("Users<br/>[User.js]")]
  node_product_data[("Products<br/>[Product.js]")]
  node_purchase_data[("Purchases<br/>[Purchase.js]")]
  node_sales_data[("Sales<br/>[Sale.js]")]
  node_price_data[("Market history<br/>[MarketPrice.js]")]
  node_alert_data[("Alerts<br/>[Alert.js]")]
  node_settings_data[("Settings<br/>[Settings.js]")]
  node_supplier_data[("Suppliers<br/>[Supplier.js]")]
end

node_trader(("Merchant"))

node_trader -->|"uses"| node_spa
node_spa -->|"provides session"| node_authui
node_spa -->|"mounts"| node_shell
node_shell -->|"renders"| node_assistantui
node_shell -->|"hosts"| node_dashboard
node_shell -->|"hosts"| node_catalogui
node_shell -->|"hosts"| node_purchasesui
node_shell -->|"hosts"| node_pricesui
node_shell -->|"hosts"| node_alertsui
node_shell -->|"hosts"| node_settingsui
node_authui -->|"uses"| node_api_client
node_catalogui -->|"requests data"| node_api_client
node_assistantui -.->|"sends commands"| node_api_client
node_api_client -.->|"calls API"| node_routes
node_routes -->|"protects endpoints"| node_auth
node_routes -->|"dispatches"| node_products
node_routes -->|"dispatches"| node_chatbot
node_routes -->|"dispatches"| node_alert_api
node_routes -->|"dispatches"| node_market_api
node_routes -->|"dispatches"| node_dashboard_api
node_routes -.->|"dispatches"| node_purchases
node_routes -.->|"dispatches"| node_sales
node_routes -.->|"dispatches"| node_settings_api
node_products -->|"reads/writes"| node_product_data
node_products -->|"records prices"| node_price_data
node_products -->|"fetches benchmarks"| node_govfeed
node_chatbot -->|"reads/writes"| node_product_data
node_chatbot -->|"creates receipts"| node_purchase_data
node_chatbot -->|"reads sales"| node_sales_data
node_chatbot -->|"reads prices"| node_price_data
node_chatbot -->|"creates alerts"| node_alert_data
node_chatbot -->|"reads suppliers"| node_supplier_data
node_chatbot -->|"checks prices"| node_monitor
node_chatbot -.->|"generates replies"| node_gemini
node_purchases -.->|"records purchases"| node_purchase_data
node_purchases -.->|"updates stock"| node_product_data
node_sales -.->|"records sales"| node_sales_data
node_dashboard_api -.->|"summarizes"| node_product_data
node_dashboard_api -.->|"summarizes"| node_purchase_data
node_dashboard_api -.->|"summarizes"| node_sales_data
node_alert_api -->|"reads/writes"| node_alert_data
node_market_api -->|"reads prices"| node_price_data
node_market_api -->|"triggers checks"| node_monitor
node_monitor -->|"reads preferences"| node_settings_data
node_monitor -->|"updates benchmarks"| node_product_data
node_monitor -->|"stores observations"| node_price_data
node_monitor -->|"creates alerts"| node_alert_data
node_monitor -->|"fetches prices"| node_govfeed

click node_spa "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/App.jsx"
click node_authui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/context/AuthContext.jsx"
click node_shell "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/components/layout/Layout.jsx"
click node_assistantui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/components/chat/FloatingChatbot.jsx"
click node_dashboard "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Dashboard.jsx"
click node_catalogui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Products.jsx"
click node_purchasesui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Purchases.jsx"
click node_pricesui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/MarketPrices.jsx"
click node_alertsui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Notifications.jsx"
click node_settingsui "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Settings.jsx"
click node_api_client "https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/services/api.js"
click node_routes "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/server.js"
click node_auth "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/middleware/auth.js"
click node_chatbot "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/chatbotController.js"
click node_products "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/productController.js"
click node_purchases "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/purchaseController.js"
click node_sales "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/salesController.js"
click node_dashboard_api "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/dashboardController.js"
click node_alert_api "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/alertController.js"
click node_settings_api "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/settingsController.js"
click node_market_api "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/marketPriceController.js"
click node_monitor "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/services/priceMonitor.js"
click node_poller "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/jobs/priceChecker.js"
click node_govfeed "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/services/govApiService.js"
click node_gemini "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/config/gemini.js"
click node_users "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/User.js"
click node_product_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Product.js"
click node_purchase_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Purchase.js"
click node_sales_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Sale.js"
click node_price_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/MarketPrice.js"
click node_alert_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Alert.js"
click node_settings_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Settings.js"
click node_supplier_data "https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Supplier.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_spa,node_authui,node_shell,node_assistantui,node_dashboard,node_catalogui,node_purchasesui,node_pricesui,node_alertsui,node_settingsui,node_api_client toneBlue
class node_routes,node_auth,node_chatbot,node_products,node_purchases,node_sales,node_dashboard_api,node_alert_api,node_settings_api toneAmber
class node_market_api,node_monitor,node_poller,node_govfeed,node_gemini toneMint
class node_users,node_product_data,node_purchase_data,node_sales_data,node_price_data,node_alert_data,node_settings_data,node_supplier_data toneRose
class node_trader toneIndigo
```

## Components

### Merchant workspace

- [Protected app](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/App.jsx): `client/src/App.jsx`
- [Session state](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/context/AuthContext.jsx): `client/src/context/AuthContext.jsx`
- [App shell](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/components/layout/Layout.jsx): `client/src/components/layout/Layout.jsx`
- [Floating assistant](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/components/chat/FloatingChatbot.jsx): `client/src/components/chat/FloatingChatbot.jsx`
- [Dashboard](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Dashboard.jsx): `client/src/pages/Dashboard.jsx`
- [Products](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Products.jsx): `client/src/pages/Products.jsx`
- [Purchases](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Purchases.jsx): `client/src/pages/Purchases.jsx`
- [Market prices](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/MarketPrices.jsx): `client/src/pages/MarketPrices.jsx`
- [Alerts](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Notifications.jsx): `client/src/pages/Notifications.jsx`
- [Store settings](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/pages/Settings.jsx): `client/src/pages/Settings.jsx`
- [API client](https://github.com/gochalamvinod/marketmind-ai/blob/main/client/src/services/api.js): `client/src/services/api.js`

### API and domain actions

- [REST routes](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/server.js): `server/server.js`
- [JWT verification](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/middleware/auth.js): `server/middleware/auth.js`
- [Command assistant](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/chatbotController.js): `server/controllers/chatbotController.js`
- [Catalog operations](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/productController.js): `server/controllers/productController.js`
- [Purchase ledger](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/purchaseController.js): `server/controllers/purchaseController.js`
- [Sales and profit](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/salesController.js): `server/controllers/salesController.js`
- [Dashboard metrics](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/dashboardController.js): `server/controllers/dashboardController.js`
- [Alert management](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/alertController.js): `server/controllers/alertController.js`
- [Settings management](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/settingsController.js): `server/controllers/settingsController.js`

### Market intelligence

- [Price endpoints](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/controllers/marketPriceController.js): `server/controllers/marketPriceController.js`
- [Price monitor](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/services/priceMonitor.js): `server/services/priceMonitor.js`
- [Scheduled polling](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/jobs/priceChecker.js): `server/jobs/priceChecker.js`
- [AGMARKNET feed](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/services/govApiService.js): `server/services/govApiService.js`
- [Gemini service](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/config/gemini.js): `server/config/gemini.js`

### ERP records

- [Users](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/User.js): `server/models/User.js`
- [Products](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Product.js): `server/models/Product.js`
- [Purchases](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Purchase.js): `server/models/Purchase.js`
- [Sales](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Sale.js): `server/models/Sale.js`
- [Market history](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/MarketPrice.js): `server/models/MarketPrice.js`
- [Alerts](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Alert.js): `server/models/Alert.js`
- [Settings](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Settings.js): `server/models/Settings.js`
- [Suppliers](https://github.com/gochalamvinod/marketmind-ai/blob/main/server/models/Supplier.js): `server/models/Supplier.js`

### Other components

- **Merchant**

## Connections

- Merchant → Protected app: uses (evidence: `README.md`)
- Protected app → Session state: provides session (evidence: `client/src/App.jsx`)
- Protected app → App shell: mounts (evidence: `client/src/App.jsx`)
- App shell → Floating assistant: renders (evidence: `client/src/components/layout/Layout.jsx`)
- App shell → Dashboard: hosts (evidence: `client/src/App.jsx`)
- App shell → Products: hosts (evidence: `client/src/App.jsx`)
- App shell → Purchases: hosts (evidence: `client/src/App.jsx`)
- App shell → Market prices: hosts (evidence: `client/src/App.jsx`)
- App shell → Alerts: hosts (evidence: `client/src/App.jsx`)
- App shell → Store settings: hosts (evidence: `client/src/App.jsx`)
- Session state → API client: uses (evidence: `client/src/context/AuthContext.jsx`)
- Products → API client: requests data (evidence: `client/src/pages/Products.jsx`)
- Floating assistant → API client: sends commands
- API client → REST routes: calls API
- REST routes → JWT verification: protects endpoints
- REST routes → Catalog operations: dispatches
- REST routes → Command assistant: dispatches
- REST routes → Alert management: dispatches
- REST routes → Price endpoints: dispatches (evidence: `server/server.js`)
- REST routes → Dashboard metrics: dispatches (evidence: `server/server.js`)
- REST routes → Purchase ledger: dispatches
- REST routes → Sales and profit: dispatches
- REST routes → Settings management: dispatches
- Catalog operations → Products: reads/writes (evidence: `server/controllers/productController.js`)
- Catalog operations → Market history: records prices (evidence: `server/controllers/productController.js`)
- Catalog operations → AGMARKNET feed: fetches benchmarks (evidence: `server/controllers/productController.js`)
- Command assistant → Products: reads/writes (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Purchases: creates receipts (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Sales: reads sales (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Market history: reads prices (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Alerts: creates alerts (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Suppliers: reads suppliers (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Price monitor: checks prices (evidence: `server/controllers/chatbotController.js`)
- Command assistant → Gemini service: generates replies
- Purchase ledger → Purchases: records purchases
- Purchase ledger → Products: updates stock
- Sales and profit → Sales: records sales
- Dashboard metrics → Products: summarizes
- Dashboard metrics → Purchases: summarizes
- Dashboard metrics → Sales: summarizes
- Alert management → Alerts: reads/writes (evidence: `server/controllers/alertController.js`)
- Price endpoints → Market history: reads prices (evidence: `server/controllers/marketPriceController.js`)
- Price endpoints → Price monitor: triggers checks (evidence: `server/controllers/marketPriceController.js`)
- Price monitor → Settings: reads preferences (evidence: `server/services/priceMonitor.js`)
- Price monitor → Products: updates benchmarks (evidence: `server/services/priceMonitor.js`)
- Price monitor → Market history: stores observations (evidence: `server/services/priceMonitor.js`)
- Price monitor → Alerts: creates alerts (evidence: `server/services/priceMonitor.js`)
- Price monitor → AGMARKNET feed: fetches prices (evidence: `server/services/priceMonitor.js`)
