# ngonguyenthanhdam/smart-retail-mvp architecture

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

- Interactive diagram: https://gitdiagram.com/ngonguyenthanhdam/smart-retail-mvp
- Repository: https://github.com/ngonguyenthanhdam/smart-retail-mvp

## Overview

RetailSense AI is a small-chain retail operations app with a Next.js interface, NestJS business API, PostgreSQL persistence, and a separate experimental forecasting service. The main workflow is staff or managers using the frontend to record and review store operations; the backend applies business rules and stores results. Managers can also review forecast-driven replenishment recommendations and create purchase drafts. The README documents imports, alerts, reporting, and administration, but several of their internal links are not shown in the sampled source; those branches are represented without speculative call chains.

Main entry points: [`frontend/src/lib/api.ts`](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/lib/api.ts) (API client), [`ml-service/src/features.py`](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/features.py) (Feature engineering), [`backend/src/forecasts/forecast-data.service.ts`](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/forecasts/forecast-data.service.ts) (Forecast data and history), [`backend/src/replenishment/replenishment.service.ts`](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/replenishment/replenishment.service.ts) (Replenishment decisions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_web["Retail screens"]
  node_web_auth["Login and session<br/>[auth-provider.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_forecast_ui["Forecast screens<br/>[forecasts-page.tsx]"]
end

subgraph group_operations["Retail operations"]
  node_auth["Authentication<br/>[auth.service.ts]"]
  node_auth_scope["Role and store scope<br/>[location-scope.ts]"]
  node_catalog["Product catalog"]
  node_locations["Store administration"]
  node_purchases["Purchases and receiving"]
  node_sales["Sales and lot use<br/>[sales.service.ts]"]
  node_inventory["Inventory and lots"]
  node_expenses["Operating expenses"]
  node_imports["Data imports<br/>[imports.service.ts]"]
  node_reports_alerts["Reports and alerts<br/>[reports.service.ts]"]
end

subgraph group_forecast["Forecasting and replenishment"]
  node_forecast_data["Forecast data and history"]
  node_prediction_client["Prediction client"]
  node_replenishment["Replenishment decisions"]
end

subgraph group_ml["Prediction service"]
  node_ml_api["Prediction API<br/>[app.py]"]
  node_ml_history["History preparation<br/>[forecasting.py]"]
  node_ml_features["Feature engineering<br/>[features.py]"]
  node_ml_preprocess["Preprocessing<br/>[preprocessing.py]"]
  node_ml_quantity["Quantity model<br/>[quantity_model.py]"]
  node_ml_dataset["Training datasets<br/>[dataset.py]"]
end

node_user(("Store user"))
node_database[("PostgreSQL")]

node_user -->|"uses"| node_web
node_user -->|"signs in"| node_web_auth
node_web_auth -.->|"requests API"| node_api_client
node_web -.->|"loads and submits"| node_api_client
node_api_client -.->|"calls backend"| node_auth
node_api_client -.->|"calls backend"| node_catalog
node_api_client -.->|"calls backend"| node_purchases
node_api_client -.->|"calls backend"| node_sales
node_api_client -.->|"calls backend"| node_inventory
node_api_client -.->|"calls backend"| node_imports
node_api_client -.->|"calls backend"| node_forecast_data
node_api_client -.->|"calls backend"| node_replenishment
node_api_client -.->|"calls backend"| node_reports_alerts
node_api_client -.->|"calls backend"| node_expenses
node_api_client -.->|"calls backend"| node_locations
node_auth -->|"reads accounts"| node_database
node_auth_scope -.->|"limits access"| node_catalog
node_purchases -.->|"stores purchase data"| node_database
node_sales -.->|"stores sales data"| node_database
node_inventory -.->|"reads stock"| node_database
node_expenses -.->|"stores expenses"| node_database
node_imports -.->|"imports records"| node_database
node_reports_alerts -.->|"reads operations"| node_database
node_forecast_ui -.->|"requests forecasts"| node_api_client
node_forecast_data -->|"reads sales history"| node_database
node_forecast_data -->|"requests predictions"| node_prediction_client
node_prediction_client -.->|"sends forecast request"| node_ml_api
node_ml_api -->|"builds history panel"| node_ml_history
node_ml_api -->|"loads quantity model"| node_ml_quantity
node_ml_history -->|"builds features"| node_ml_features
node_ml_features -->|"uses preprocessing"| node_ml_preprocess
node_ml_quantity -->|"uses features"| node_ml_features
node_ml_quantity -->|"uses forecasting"| node_ml_history
node_ml_dataset -.->|"training data"| node_ml_features
node_replenishment -.->|"stores reviewed drafts"| node_database
node_replenishment -.->|"creates purchase draft"| node_purchases

click node_web "https://github.com/ngonguyenthanhdam/smart-retail-mvp/tree/smart-retail-mvp/frontend/src/components"
click node_web_auth "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/components/auth-provider.tsx"
click node_api_client "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/lib/api.ts"
click node_auth "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/auth/auth.service.ts"
click node_auth_scope "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/auth/location-scope.ts"
click node_catalog "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/products/products.service.ts"
click node_locations "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/locations/locations.service.ts"
click node_purchases "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/purchases/purchases.service.ts"
click node_sales "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/sales/sales.service.ts"
click node_inventory "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/inventory/inventory.service.ts"
click node_expenses "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/expenses/expenses.service.ts"
click node_imports "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/imports/imports.service.ts"
click node_reports_alerts "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/reports/reports.service.ts"
click node_forecast_data "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/forecasts/forecast-data.service.ts"
click node_prediction_client "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/forecasts/prediction-client.ts"
click node_forecast_ui "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/components/forecasts-page.tsx"
click node_replenishment "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/replenishment/replenishment.service.ts"
click node_ml_api "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/app.py"
click node_ml_history "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/forecasting.py"
click node_ml_features "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/features.py"
click node_ml_preprocess "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/preprocessing.py"
click node_ml_quantity "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/quantity_model.py"
click node_ml_dataset "https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/dataset.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_web,node_web_auth,node_api_client,node_forecast_ui,node_user toneBlue
class node_auth,node_auth_scope,node_catalog,node_locations,node_purchases,node_sales,node_inventory,node_expenses,node_imports,node_reports_alerts,node_database toneAmber
class node_forecast_data,node_prediction_client,node_replenishment toneMint
class node_ml_api,node_ml_history,node_ml_features,node_ml_preprocess,node_ml_quantity,node_ml_dataset toneRose
```

## Components

### Web application

- [Retail screens](https://github.com/ngonguyenthanhdam/smart-retail-mvp/tree/smart-retail-mvp/frontend/src/components): `frontend/src/components`
- [Login and session](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/components/auth-provider.tsx): `frontend/src/components/auth-provider.tsx`
- [API client](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`
- [Forecast screens](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/frontend/src/components/forecasts-page.tsx): `frontend/src/components/forecasts-page.tsx`

### Retail operations

- [Authentication](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/auth/auth.service.ts): `backend/src/auth/auth.service.ts`
- [Role and store scope](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/auth/location-scope.ts): `backend/src/auth/location-scope.ts`
- [Product catalog](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/products/products.service.ts): `backend/src/products/products.service.ts`
- [Store administration](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/locations/locations.service.ts): `backend/src/locations/locations.service.ts`
- [Purchases and receiving](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/purchases/purchases.service.ts): `backend/src/purchases/purchases.service.ts`
- [Sales and lot use](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/sales/sales.service.ts): `backend/src/sales/sales.service.ts`
- [Inventory and lots](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/inventory/inventory.service.ts): `backend/src/inventory/inventory.service.ts`
- [Operating expenses](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/expenses/expenses.service.ts): `backend/src/expenses/expenses.service.ts`
- [Data imports](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/imports/imports.service.ts): `backend/src/imports/imports.service.ts`
- [Reports and alerts](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/reports/reports.service.ts): `backend/src/reports/reports.service.ts`

### Forecasting and replenishment

- [Forecast data and history](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/forecasts/forecast-data.service.ts): `backend/src/forecasts/forecast-data.service.ts`
- [Prediction client](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/forecasts/prediction-client.ts): `backend/src/forecasts/prediction-client.ts`
- [Replenishment decisions](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/backend/src/replenishment/replenishment.service.ts): `backend/src/replenishment/replenishment.service.ts`

### Prediction service

- [Prediction API](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/app.py): `ml-service/app.py`
- [History preparation](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/forecasting.py): `ml-service/src/forecasting.py`
- [Feature engineering](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/features.py): `ml-service/src/features.py`
- [Preprocessing](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/preprocessing.py): `ml-service/src/preprocessing.py`
- [Quantity model](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/quantity_model.py): `ml-service/src/quantity_model.py`
- [Training datasets](https://github.com/ngonguyenthanhdam/smart-retail-mvp/blob/smart-retail-mvp/ml-service/src/dataset.py): `ml-service/src/dataset.py`

### Other components

- **Store user**
- **PostgreSQL**

## Connections

- Store user → Retail screens: uses
- Store user → Login and session: signs in
- Login and session → API client: requests API
- Retail screens → API client: loads and submits
- API client → Authentication: calls backend
- API client → Product catalog: calls backend
- API client → Purchases and receiving: calls backend
- API client → Sales and lot use: calls backend
- API client → Inventory and lots: calls backend
- API client → Data imports: calls backend
- API client → Forecast data and history: calls backend
- API client → Replenishment decisions: calls backend
- API client → Reports and alerts: calls backend
- API client → Operating expenses: calls backend
- API client → Store administration: calls backend
- Authentication → PostgreSQL: reads accounts (evidence: `backend/src/auth/auth.service.ts`)
- Role and store scope → Product catalog: limits access
- Purchases and receiving → PostgreSQL: stores purchase data
- Sales and lot use → PostgreSQL: stores sales data
- Inventory and lots → PostgreSQL: reads stock
- Operating expenses → PostgreSQL: stores expenses
- Data imports → PostgreSQL: imports records
- Reports and alerts → PostgreSQL: reads operations
- Forecast screens → API client: requests forecasts
- Forecast data and history → PostgreSQL: reads sales history (evidence: `backend/src/forecasts/forecast-data.service.ts`)
- Forecast data and history → Prediction client: requests predictions (evidence: `backend/src/forecasts/forecast-data.controller.ts`)
- Prediction client → Prediction API: sends forecast request
- Prediction API → History preparation: builds history panel (evidence: `ml-service/app.py`)
- Prediction API → Quantity model: loads quantity model (evidence: `ml-service/app.py`)
- History preparation → Feature engineering: builds features (evidence: `ml-service/src/forecasting.py`)
- Feature engineering → Preprocessing: uses preprocessing (evidence: `ml-service/src/features.py`)
- Quantity model → Feature engineering: uses features (evidence: `ml-service/src/quantity_model.py`)
- Quantity model → History preparation: uses forecasting (evidence: `ml-service/src/quantity_model.py`)
- Training datasets → Feature engineering: training data
- Replenishment decisions → PostgreSQL: stores reviewed drafts
- Replenishment decisions → Purchases and receiving: creates purchase draft
