The user enters a natural language query regarding demand, inventory, or supplier data.
userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });
Input is validated, sanitized, and packaged into a JSON payload for the backend API.
fetch('/api/chat', { method: 'POST', body: JSON.stringify({message: text}) });
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'}
Based on the identified intent, the request is routed to the specific handler module (Forecasting, Inventory, Supplier, or LLM).
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)
Computed data is structured into a standardized JSON format, including text summaries and raw data arrays for visualization.
return {"intent": "forecast", "answer": "...", "data": [...]}
The browser receives the JSON response and dynamically renders the chat bubble, data tables, and interactive elements.