# ramkalyan10/smartmerchantappplication architecture

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

- Interactive diagram: https://gitdiagram.com/ramkalyan10/smartmerchantappplication
- Repository: https://github.com/ramkalyan10/smartmerchantappplication

## Overview

Smart Merchant is a merchant operations and business-intelligence platform: staff manage sales, products, inventory, customers, suppliers, and expenses, then use analytics and forecasts to guide decisions. The documented runtime is a React frontend, Express business API, database, and separate FastAPI ML service. The graph preserves the major operational and prediction stages; several page and controller implementations are unsampled, so their internal calls are not inferred.

Main entry points: [`frontend/src/App.jsx`](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/App.jsx) (App and navigation), [`backend/src/app.js`](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/app.js) (Express API router), [`backend/src/config/db.js`](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/config/db.js) (Database adapter), [`frontend/src/services/api.js`](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/services/api.js) (REST client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Merchant interface"]
  node_app_ui["App and navigation<br/>[App.jsx]"]
  node_auth_ui["Sign-in state<br/>[AuthContext.jsx]"]
  node_sales_ui["Invoices and POS<br/>[InvoicesPage.jsx]"]
  node_catalog_ui["Products and inventory"]
  node_operations_ui["Business operations<br/>[CustomersPage.jsx]"]
  node_insights_ui["Analytics and forecasts"]
  node_api_client["REST client<br/>[api.js]"]
end

subgraph group_api["Business API"]
  node_express["Express API router<br/>[app.js]"]
  node_auth_routes["Authentication routes<br/>[auth.routes.js]"]
  node_product_routes["Product routes<br/>[product.routes.js]"]
  node_inventory_routes["Inventory routes"]
  node_domain_routes["Other domain routes"]
  node_auth_controller["Authentication<br/>[authController.js]"]
  node_product_controller["Product catalog"]
  node_inventory_controller["Stock and purchasing"]
  node_domain_controllers["Sales and business domains"]
  node_access_control["Authentication and roles<br/>[authMiddleware.js]"]
  node_ml_client["ML service client<br/>[mlClient.js]"]
end

subgraph group_data["Business data"]
  node_store[("Database adapter<br/>[db.js]")]
  node_postgres[("PostgreSQL client<br/>[pgClient.js]")]
end

subgraph group_ml["ML intelligence"]
  node_ml_api["Prediction API<br/>[main.py]"]
  node_ml_models["Prediction models"]
  node_ml_training["Model training"]
end

node_merchant(("Merchant or staff"))

node_merchant -->|"uses"| node_app_ui
node_app_ui -->|"routes to"| node_sales_ui
node_app_ui -->|"routes to"| node_catalog_ui
node_app_ui -->|"routes to"| node_operations_ui
node_app_ui -->|"routes to"| node_insights_ui
node_app_ui -->|"provides context"| node_auth_ui
node_auth_ui -->|"calls"| node_api_client
node_sales_ui -->|"uses"| node_api_client
node_catalog_ui -->|"uses"| node_api_client
node_api_client -->|"REST requests"| node_express
node_express -->|"mounts"| node_auth_routes
node_express -->|"mounts"| node_product_routes
node_express -->|"mounts"| node_inventory_routes
node_express -->|"mounts"| node_domain_routes
node_auth_routes -->|"dispatches"| node_auth_controller
node_product_routes -->|"dispatches"| node_product_controller
node_inventory_routes -->|"dispatches"| node_inventory_controller
node_domain_routes -->|"dispatches"| node_domain_controllers
node_auth_routes -->|"applies"| node_access_control
node_product_routes -->|"applies"| node_access_control
node_inventory_routes -->|"applies"| node_access_control
node_auth_controller -->|"reads and writes"| node_store
node_product_controller -->|"reads and writes"| node_store
node_inventory_controller -->|"reads and writes"| node_store
node_domain_controllers -->|"uses"| node_store
node_store -->|"uses when connected"| node_postgres
node_domain_controllers -->|"requests forecasts"| node_ml_client
node_ml_client -->|"calls prediction service"| node_ml_api
node_ml_api -->|"dispatches predictions"| node_ml_models
node_ml_training -.->|"trains models"| node_ml_models

click node_app_ui "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/App.jsx"
click node_auth_ui "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/context/AuthContext.jsx"
click node_sales_ui "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/InvoicesPage.jsx"
click node_catalog_ui "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/ProductsInventoryPage.jsx"
click node_operations_ui "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/CustomersPage.jsx"
click node_insights_ui "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/ForecastingPage.jsx"
click node_api_client "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/services/api.js"
click node_express "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/app.js"
click node_auth_routes "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/routes/auth.routes.js"
click node_product_routes "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/routes/product.routes.js"
click node_inventory_routes "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/routes/inventory.routes.js"
click node_domain_routes "https://github.com/ramkalyan10/smartmerchantappplication/tree/master/backend/src/routes"
click node_auth_controller "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/controllers/authController.js"
click node_product_controller "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/controllers/productController.js"
click node_inventory_controller "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/controllers/inventoryController.js"
click node_domain_controllers "https://github.com/ramkalyan10/smartmerchantappplication/tree/master/backend/src/controllers"
click node_access_control "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/middleware/authMiddleware.js"
click node_store "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/config/db.js"
click node_postgres "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/config/pgClient.js"
click node_ml_client "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/services/mlClient.js"
click node_ml_api "https://github.com/ramkalyan10/smartmerchantappplication/blob/master/ml-service/api/main.py"
click node_ml_models "https://github.com/ramkalyan10/smartmerchantappplication/tree/master/ml-service/prediction"
click node_ml_training "https://github.com/ramkalyan10/smartmerchantappplication/tree/master/ml-service/training"

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_ui,node_auth_ui,node_sales_ui,node_catalog_ui,node_operations_ui,node_insights_ui,node_api_client toneBlue
class node_express,node_auth_routes,node_product_routes,node_inventory_routes,node_domain_routes,node_auth_controller,node_product_controller,node_inventory_controller,node_domain_controllers,node_access_control,node_ml_client toneAmber
class node_store,node_postgres toneMint
class node_ml_api,node_ml_models,node_ml_training toneRose
class node_merchant toneIndigo
```

## Components

### Merchant interface

- [App and navigation](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Sign-in state](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Invoices and POS](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/InvoicesPage.jsx): `frontend/src/pages/InvoicesPage.jsx`
- [Products and inventory](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/ProductsInventoryPage.jsx): `frontend/src/pages/ProductsInventoryPage.jsx`
- [Business operations](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/CustomersPage.jsx): `frontend/src/pages/CustomersPage.jsx`
- [Analytics and forecasts](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/pages/ForecastingPage.jsx): `frontend/src/pages/ForecastingPage.jsx`
- [REST client](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/frontend/src/services/api.js): `frontend/src/services/api.js`

### Business API

- [Express API router](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/app.js): `backend/src/app.js`
- [Authentication routes](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/routes/auth.routes.js): `backend/src/routes/auth.routes.js`
- [Product routes](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/routes/product.routes.js): `backend/src/routes/product.routes.js`
- [Inventory routes](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/routes/inventory.routes.js): `backend/src/routes/inventory.routes.js`
- [Other domain routes](https://github.com/ramkalyan10/smartmerchantappplication/tree/master/backend/src/routes): `backend/src/routes`
- [Authentication](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/controllers/authController.js): `backend/src/controllers/authController.js`
- [Product catalog](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/controllers/productController.js): `backend/src/controllers/productController.js`
- [Stock and purchasing](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/controllers/inventoryController.js): `backend/src/controllers/inventoryController.js`
- [Sales and business domains](https://github.com/ramkalyan10/smartmerchantappplication/tree/master/backend/src/controllers): `backend/src/controllers`
- [Authentication and roles](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/middleware/authMiddleware.js): `backend/src/middleware/authMiddleware.js`
- [ML service client](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/services/mlClient.js): `backend/src/services/mlClient.js`

### Business data

- [Database adapter](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/config/db.js): `backend/src/config/db.js`
- [PostgreSQL client](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/backend/src/config/pgClient.js): `backend/src/config/pgClient.js`

### ML intelligence

- [Prediction API](https://github.com/ramkalyan10/smartmerchantappplication/blob/master/ml-service/api/main.py): `ml-service/api/main.py`
- [Prediction models](https://github.com/ramkalyan10/smartmerchantappplication/tree/master/ml-service/prediction): `ml-service/prediction`
- [Model training](https://github.com/ramkalyan10/smartmerchantappplication/tree/master/ml-service/training): `ml-service/training`

### Other components

- **Merchant or staff**

## Connections

- Merchant or staff → App and navigation: uses (evidence: `frontend/src/App.jsx`)
- App and navigation → Invoices and POS: routes to (evidence: `frontend/src/App.jsx`)
- App and navigation → Products and inventory: routes to (evidence: `frontend/src/App.jsx`)
- App and navigation → Business operations: routes to (evidence: `frontend/src/App.jsx`)
- App and navigation → Analytics and forecasts: routes to (evidence: `frontend/src/App.jsx`)
- App and navigation → Sign-in state: provides context (evidence: `frontend/src/App.jsx`)
- Sign-in state → REST client: calls (evidence: `frontend/src/context/AuthContext.jsx`)
- Invoices and POS → REST client: uses (evidence: `frontend/src/pages/InvoicesPage.jsx`)
- Products and inventory → REST client: uses (evidence: `frontend/src/pages/ProductsInventoryPage.jsx`)
- REST client → Express API router: REST requests (evidence: `README.md`)
- Express API router → Authentication routes: mounts (evidence: `backend/src/app.js`)
- Express API router → Product routes: mounts (evidence: `backend/src/app.js`)
- Express API router → Inventory routes: mounts (evidence: `backend/src/app.js`)
- Express API router → Other domain routes: mounts (evidence: `backend/src/app.js`)
- Authentication routes → Authentication: dispatches (evidence: `backend/src/routes/auth.routes.js`)
- Product routes → Product catalog: dispatches (evidence: `backend/src/routes/product.routes.js`)
- Inventory routes → Stock and purchasing: dispatches (evidence: `backend/src/routes/inventory.routes.js`)
- Other domain routes → Sales and business domains: dispatches (evidence: `backend/src/routes/analytics.routes.js`)
- Authentication routes → Authentication and roles: applies (evidence: `backend/src/routes/auth.routes.js`)
- Product routes → Authentication and roles: applies (evidence: `backend/src/routes/product.routes.js`)
- Inventory routes → Authentication and roles: applies (evidence: `backend/src/routes/inventory.routes.js`)
- Authentication → Database adapter: reads and writes (evidence: `backend/src/controllers/authController.js`)
- Product catalog → Database adapter: reads and writes (evidence: `backend/src/controllers/productController.js`)
- Stock and purchasing → Database adapter: reads and writes (evidence: `backend/src/controllers/inventoryController.js`)
- Sales and business domains → Database adapter: uses (evidence: `backend/src/controllers/invoiceController.js`)
- Database adapter → PostgreSQL client: uses when connected (evidence: `backend/src/config/db.js`)
- Sales and business domains → ML service client: requests forecasts (evidence: `backend/src/controllers/forecastController.js`)
- ML service client → Prediction API: calls prediction service (evidence: `README.md`)
- Prediction API → Prediction models: dispatches predictions (evidence: `ml-service/api/main.py`)
- Model training → Prediction models: trains models (evidence: `ml-service/prediction/predict_clustering.py`)
