# vigneshssuvarna/marketwatch architecture

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

- Interactive diagram: https://gitdiagram.com/vigneshssuvarna/marketwatch
- Repository: https://github.com/vigneshssuvarna/marketwatch

## Overview

MarketWatch tracks mandi commodity prices, lets users browse market history and forecasts, maintain watchlists, and manage price alerts; administrators can import CSV price data. The principal workflow runs from authenticated frontend pages through service calls and backend routes/controllers to MongoDB, with forecasting delegated to the ML service. The README identifies the three services and major capabilities; the graph uses indexed references and shown excerpts for internal links, while cross-service HTTP wiring is not fully sampled and is marked unverified where appropriate.

Main entry points: [`frontend/src/App.jsx`](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/App.jsx) (Routes and providers), [`backend/server.js`](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/server.js) (Express API), [`frontend/src/services/api.js`](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/api.js) (HTTP client), [`backend/models/Commodity.js`](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/Commodity.js) (Commodity records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_webapp["Routes and providers<br/>[App.jsx]"]
  node_authui["Authentication state<br/>[AuthContext.jsx]"]
  node_dashboard["Dashboard<br/>[DashboardPage.jsx]"]
  node_commoditydetail["Commodity detail"]
  node_alertsui["Alert management<br/>[AlertsPage.jsx]"]
  node_adminui["Admin import<br/>[AdminPage.jsx]"]
  node_profileui["Profile<br/>[ProfilePage.jsx]"]
  node_commoditycards["Commodity cards<br/>[CommodityCard.jsx]"]
  node_charts["Price visualizations<br/>[PriceChart.jsx]"]
  node_navbar["Navigation<br/>[Navbar.jsx]"]
  node_commodityservice["Commodity client"]
  node_authservice["Auth client<br/>[authService.js]"]
  node_alertservice["Alert client<br/>[alertService.js]"]
  node_forecastservice["Forecast client<br/>[forecastService.js]"]
  node_apiclient["HTTP client<br/>[api.js]"]
end

subgraph group_backend["API and data"]
  node_backendserver["Express API<br/>[server.js]"]
  node_authroutes["Auth routes<br/>[authRoutes.js]"]
  node_commodityroutes["Commodity routes<br/>[commodityRoutes.js]"]
  node_alertroutes["Alert routes<br/>[alertRoutes.js]"]
  node_adminroutes["Admin routes<br/>[adminRoutes.js]"]
  node_forecastroutes["Forecast routes<br/>[forecastRoutes.js]"]
  node_authcontroller["Accounts and watchlists<br/>[authController.js]"]
  node_commoditycontroller["Commodity queries"]
  node_alertcontroller["Alert evaluation<br/>[alertController.js]"]
  node_admincontroller["CSV ingestion<br/>[adminController.js]"]
  node_forecastcontroller["Forecast requests"]
  node_authmiddleware["Authentication guard<br/>[authMiddleware.js]"]
  node_commoditymodel[("Commodity records<br/>[Commodity.js]")]
  node_usermodel[("User records<br/>[User.js]")]
  node_alertmodel[("Alert records<br/>[Alert.js]")]
  node_csvparser["Price CSV parser<br/>[parsePriceCsv.js]"]
  node_mlclient["ML service client<br/>[mlServiceClient.js]"]
end

subgraph group_ml["Forecasting service"]
  node_mlapp["Prediction API<br/>[app.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_webapp
node_webapp -->|"provides auth"| node_authui
node_webapp -->|"routes"| node_dashboard
node_webapp -->|"routes"| node_commoditydetail
node_webapp -->|"routes"| node_alertsui
node_webapp -->|"routes"| node_adminui
node_webapp -->|"routes"| node_profileui
node_dashboard -->|"requests data"| node_commodityservice
node_dashboard -->|"renders"| node_commoditycards
node_commoditydetail -->|"requests data"| node_commodityservice
node_commoditydetail -->|"requests forecasts"| node_forecastservice
node_commoditydetail -->|"renders"| node_charts
node_alertsui -->|"manages alerts"| node_alertservice
node_alertsui -->|"loads commodities"| node_commodityservice
node_adminui -->|"sends requests"| node_apiclient
node_authui -->|"authenticates"| node_authservice
node_commodityservice -->|"sends requests"| node_apiclient
node_authservice -->|"sends requests"| node_apiclient
node_alertservice -->|"sends requests"| node_apiclient
node_apiclient -.->|"HTTP requests"| node_backendserver
node_backendserver -->|"mounts"| node_authroutes
node_backendserver -->|"mounts"| node_commodityroutes
node_backendserver -->|"mounts"| node_forecastroutes
node_backendserver -->|"mounts"| node_adminroutes
node_backendserver -->|"mounts"| node_alertroutes
node_authroutes -->|"dispatches"| node_authcontroller
node_authroutes -->|"guards"| node_authmiddleware
node_commodityroutes -->|"dispatches"| node_commoditycontroller
node_alertroutes -->|"dispatches"| node_alertcontroller
node_alertroutes -->|"guards"| node_authmiddleware
node_adminroutes -->|"dispatches"| node_admincontroller
node_adminroutes -->|"guards"| node_authmiddleware
node_forecastroutes -->|"dispatches"| node_forecastcontroller
node_authmiddleware -->|"loads user"| node_usermodel
node_authcontroller -->|"reads and writes"| node_usermodel
node_authcontroller -->|"reads"| node_commoditymodel
node_commoditycontroller -->|"queries"| node_commoditymodel
node_alertcontroller -->|"reads and writes"| node_alertmodel
node_alertcontroller -->|"reads prices"| node_commoditymodel
node_admincontroller -->|"parses upload"| node_csvparser
node_admincontroller -->|"updates prices"| node_commoditymodel
node_forecastcontroller -->|"reads commodity"| node_commoditymodel
node_forecastcontroller -->|"requests forecast"| node_mlclient
node_mlclient -.->|"HTTP request"| node_mlapp

click node_webapp "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/App.jsx"
click node_authui "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/context/AuthContext.jsx"
click node_dashboard "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/DashboardPage.jsx"
click node_commoditydetail "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/CommodityDetailPage.jsx"
click node_alertsui "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/AlertsPage.jsx"
click node_adminui "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/AdminPage.jsx"
click node_profileui "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/ProfilePage.jsx"
click node_commoditycards "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/components/CommodityCard.jsx"
click node_charts "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/components/PriceChart.jsx"
click node_navbar "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/components/Navbar.jsx"
click node_commodityservice "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/commodityService.js"
click node_authservice "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/authService.js"
click node_alertservice "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/alertService.js"
click node_forecastservice "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/forecastService.js"
click node_apiclient "https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/api.js"
click node_backendserver "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/server.js"
click node_authroutes "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/authRoutes.js"
click node_commodityroutes "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/commodityRoutes.js"
click node_alertroutes "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/alertRoutes.js"
click node_adminroutes "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/adminRoutes.js"
click node_forecastroutes "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/forecastRoutes.js"
click node_authcontroller "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/authController.js"
click node_commoditycontroller "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/commodityController.js"
click node_alertcontroller "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/alertController.js"
click node_admincontroller "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/adminController.js"
click node_forecastcontroller "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/forecastController.js"
click node_authmiddleware "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/middleware/authMiddleware.js"
click node_commoditymodel "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/Commodity.js"
click node_usermodel "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/User.js"
click node_alertmodel "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/Alert.js"
click node_csvparser "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/utils/parsePriceCsv.js"
click node_mlclient "https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/services/mlServiceClient.js"
click node_mlapp "https://github.com/vigneshssuvarna/marketwatch/blob/main/ml-service/app.py"

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_webapp,node_authui,node_dashboard,node_commoditydetail,node_alertsui,node_adminui,node_profileui,node_commoditycards,node_charts,node_navbar,node_commodityservice,node_authservice,node_alertservice,node_forecastservice,node_apiclient,node_user toneBlue
class node_backendserver,node_authroutes,node_commodityroutes,node_alertroutes,node_adminroutes,node_forecastroutes,node_authcontroller,node_commoditycontroller,node_alertcontroller,node_admincontroller,node_forecastcontroller,node_authmiddleware,node_commoditymodel,node_usermodel,node_alertmodel,node_csvparser,node_mlclient toneAmber
class node_mlapp toneMint
```

## Components

### Web application

- [Routes and providers](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Authentication state](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Dashboard](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/DashboardPage.jsx): `frontend/src/pages/DashboardPage.jsx`
- [Commodity detail](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/CommodityDetailPage.jsx): `frontend/src/pages/CommodityDetailPage.jsx`
- [Alert management](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/AlertsPage.jsx): `frontend/src/pages/AlertsPage.jsx`
- [Admin import](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/AdminPage.jsx): `frontend/src/pages/AdminPage.jsx`
- [Profile](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/pages/ProfilePage.jsx): `frontend/src/pages/ProfilePage.jsx`
- [Commodity cards](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/components/CommodityCard.jsx): `frontend/src/components/CommodityCard.jsx`
- [Price visualizations](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/components/PriceChart.jsx): `frontend/src/components/PriceChart.jsx`
- [Navigation](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/components/Navbar.jsx): `frontend/src/components/Navbar.jsx`
- [Commodity client](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/commodityService.js): `frontend/src/services/commodityService.js`
- [Auth client](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/authService.js): `frontend/src/services/authService.js`
- [Alert client](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/alertService.js): `frontend/src/services/alertService.js`
- [Forecast client](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/forecastService.js): `frontend/src/services/forecastService.js`
- [HTTP client](https://github.com/vigneshssuvarna/marketwatch/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### API and data

- [Express API](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/server.js): `backend/server.js`
- [Auth routes](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [Commodity routes](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/commodityRoutes.js): `backend/routes/commodityRoutes.js`
- [Alert routes](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/alertRoutes.js): `backend/routes/alertRoutes.js`
- [Admin routes](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/adminRoutes.js): `backend/routes/adminRoutes.js`
- [Forecast routes](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/routes/forecastRoutes.js): `backend/routes/forecastRoutes.js`
- [Accounts and watchlists](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/authController.js): `backend/controllers/authController.js`
- [Commodity queries](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/commodityController.js): `backend/controllers/commodityController.js`
- [Alert evaluation](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/alertController.js): `backend/controllers/alertController.js`
- [CSV ingestion](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/adminController.js): `backend/controllers/adminController.js`
- [Forecast requests](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/controllers/forecastController.js): `backend/controllers/forecastController.js`
- [Authentication guard](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/middleware/authMiddleware.js): `backend/middleware/authMiddleware.js`
- [Commodity records](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/Commodity.js): `backend/models/Commodity.js`
- [User records](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/User.js): `backend/models/User.js`
- [Alert records](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/models/Alert.js): `backend/models/Alert.js`
- [Price CSV parser](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/utils/parsePriceCsv.js): `backend/utils/parsePriceCsv.js`
- [ML service client](https://github.com/vigneshssuvarna/marketwatch/blob/main/backend/services/mlServiceClient.js): `backend/services/mlServiceClient.js`

### Forecasting service

- [Prediction API](https://github.com/vigneshssuvarna/marketwatch/blob/main/ml-service/app.py): `ml-service/app.py`

### Other components

- **User**

## Connections

- User → Routes and providers: uses (evidence: `frontend/src/App.jsx`)
- Routes and providers → Authentication state: provides auth (evidence: `frontend/src/App.jsx`)
- Routes and providers → Dashboard: routes (evidence: `frontend/src/App.jsx`)
- Routes and providers → Commodity detail: routes (evidence: `frontend/src/App.jsx`)
- Routes and providers → Alert management: routes (evidence: `frontend/src/App.jsx`)
- Routes and providers → Admin import: routes (evidence: `frontend/src/App.jsx`)
- Routes and providers → Profile: routes (evidence: `frontend/src/App.jsx`)
- Dashboard → Commodity client: requests data (evidence: `frontend/src/pages/DashboardPage.jsx`)
- Dashboard → Commodity cards: renders (evidence: `frontend/src/pages/DashboardPage.jsx`)
- Commodity detail → Commodity client: requests data (evidence: `frontend/src/pages/CommodityDetailPage.jsx`)
- Commodity detail → Forecast client: requests forecasts (evidence: `frontend/src/pages/CommodityDetailPage.jsx`)
- Commodity detail → Price visualizations: renders (evidence: `frontend/src/pages/CommodityDetailPage.jsx`)
- Alert management → Alert client: manages alerts (evidence: `frontend/src/pages/AlertsPage.jsx`)
- Alert management → Commodity client: loads commodities (evidence: `frontend/src/pages/AlertsPage.jsx`)
- Admin import → HTTP client: sends requests (evidence: `frontend/src/pages/AdminPage.jsx`)
- Authentication state → Auth client: authenticates (evidence: `frontend/src/context/AuthContext.jsx`)
- Commodity client → HTTP client: sends requests (evidence: `frontend/src/services/commodityService.js`)
- Auth client → HTTP client: sends requests (evidence: `frontend/src/services/authService.js`)
- Alert client → HTTP client: sends requests (evidence: `frontend/src/services/alertService.js`)
- HTTP client → Express API: HTTP requests
- Express API → Auth routes: mounts (evidence: `backend/server.js`)
- Express API → Commodity routes: mounts (evidence: `backend/server.js`)
- Express API → Forecast routes: mounts (evidence: `backend/server.js`)
- Express API → Admin routes: mounts (evidence: `backend/server.js`)
- Express API → Alert routes: mounts (evidence: `backend/server.js`)
- Auth routes → Accounts and watchlists: dispatches (evidence: `backend/routes/authRoutes.js`)
- Auth routes → Authentication guard: guards (evidence: `backend/routes/authRoutes.js`)
- Commodity routes → Commodity queries: dispatches (evidence: `backend/routes/commodityRoutes.js`)
- Alert routes → Alert evaluation: dispatches (evidence: `backend/routes/alertRoutes.js`)
- Alert routes → Authentication guard: guards (evidence: `backend/routes/alertRoutes.js`)
- Admin routes → CSV ingestion: dispatches (evidence: `backend/routes/adminRoutes.js`)
- Admin routes → Authentication guard: guards (evidence: `backend/routes/adminRoutes.js`)
- Forecast routes → Forecast requests: dispatches (evidence: `backend/routes/forecastRoutes.js`)
- Authentication guard → User records: loads user (evidence: `backend/middleware/authMiddleware.js`)
- Accounts and watchlists → User records: reads and writes (evidence: `backend/controllers/authController.js`)
- Accounts and watchlists → Commodity records: reads (evidence: `backend/controllers/authController.js`)
- Commodity queries → Commodity records: queries (evidence: `backend/controllers/commodityController.js`)
- Alert evaluation → Alert records: reads and writes (evidence: `backend/controllers/alertController.js`)
- Alert evaluation → Commodity records: reads prices (evidence: `backend/controllers/alertController.js`)
- CSV ingestion → Price CSV parser: parses upload (evidence: `backend/controllers/adminController.js`)
- CSV ingestion → Commodity records: updates prices (evidence: `backend/controllers/adminController.js`)
- Forecast requests → Commodity records: reads commodity (evidence: `backend/controllers/forecastController.js`)
- Forecast requests → ML service client: requests forecast (evidence: `backend/controllers/forecastController.js`)
- ML service client → Prediction API: HTTP request
