1 User Input
Component: Frontend UI (index.html)
Action: User types query in chat interface
Example: "What is the forecast for BMS0015 next month?"
2 Client Processing
Component: JavaScript
Action: Validate input, display user message, prepare API call
3 HTTP POST Request
Endpoint: /api/chat
Method: POST
Payload: {"message": "user query"}
4 Server Receives Request
Component: FastAPI (main.py)
Server: Uvicorn ASGI
5 Intent Parsing
Component: intent_parser.py
Method: Regex pattern matching
Extracts: Intent, Item code, Quantity, Location, Horizon
6 Intent Routing
Decision Point: Route to appropriate handler
Forecast
forecasting.py
Item Details
data_loader.py
Inventory
data_loader.py
Supplier
data_loader.py
Requisition
data_loader.py
Status
data_loader.py
pdf_generator.py
Chat
llm_engine.py
7 Business Logic Execution
Example: Demand Forecast
1. Load demand_history.csv
2. Filter by item_code
3. Fit ARIMA model
4. Generate forecast
5. Format as JSON
8 Data Retrieval
Component: data_loader.py
Sources: items.csv, inventory.csv, suppliers.csv, etc.
Technology: Pandas DataFrames
9 LLM Processing (if needed)
Component: llm_engine.py
Trigger: Only for general_chat intent
Model: TinyLlama 1.1B
Time: 5-15 seconds
10 Response Formatting
Component: main.py
Format: JSON
11 HTTP Response
Status: 200 OK
Content-Type: application/json
Sent to: Client browser
12 Client Receives Response
Component: JavaScript Fetch API
Action: Parse JSON response
13 UI Rendering
Component: JavaScript DOM manipulation
Actions:
1. Create message bubble
2. Add bot icon
3. Render forecast table (if present)
4. Add download button (if PDF)
5. Scroll to bottom
14 User Sees Response
Display: Chat bubble with bot icon
Features: Formatted text, tables, download links
Animation: Fade-in effect
Interaction: User can copy text, download PDFs, ask follow-up
✅ Flow Complete
Total Steps: 14
Average Time: 2-15 seconds (depending on intent)
Technologies Used: HTML/JS, FastAPI, Pandas, ARIMA, TinyLlama