BMS AI Assistant: End-to-End Process Flow

01

User Input Acquisition

Component: Frontend (index.html)
Trigger: User submits query via chat interface

The user enters a natural language query regarding demand, inventory, or supplier data.

userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
02

API Payload Construction

Component: Client-Side Logic (JavaScript)
Action: POST /api/chat

Input is validated, sanitized, and packaged into a JSON payload for the backend API.

fetch('/api/chat', { method: 'POST', body: JSON.stringify({message: text}) });
03

Intent Recognition & Entity Extraction

Component: Intent Parser (intent_parser.py)
Method: Regex / Pattern Matching

The system analyzes the text string to determine the user's objective (Intent) and extracts specific parameters (Item Codes, Dates, Locations).

parsed = parser.parse(message) # Output: {'intent': 'forecast', 'item': 'BMS0015'}
04

Business Logic Routing

Component: Main Controller (main.py)

Based on the identified intent, the request is routed to the specific handler module (Forecasting, Inventory, Supplier, or LLM).

05

Data Processing & Computation

Component: Backend Modules (forecasting.py, data_loader.py)

Scenario A (Forecast): ARIMA model generates 30-day demand prediction.
Scenario B (Inventory): System queries CSV database for real-time stock levels.

forecast_data = forecast_demand(item_code, horizon)
06

Response Serialization

Component: Response Formatter

Computed data is structured into a standardized JSON format, including text summaries and raw data arrays for visualization.

return {"intent": "forecast", "answer": "...", "data": [...]}
07

Client-Side Rendering

Component: Frontend UI

The browser receives the JSON response and dynamically renders the chat bubble, data tables, and interactive elements.