How skr2rathishan-oss/ecommerceaiagent works
1. Purpose and Deployment Shape
Velora is a decoupled conversational shopping assistant for Kapruka. A React client renders chat, voice, commerce cards, carts, and workflow panels; a Node/Express agent exposes REST and SSE APIs, orchestrates LLM-guided commerce workflows, and integrates with Kapruka through MCP. Local multi-container operation is defined in docker-compose.yml; production frontend delivery uses Nginx in frontend/nginx.conf.
2. Entry Points and API Boundary
The browser application starts at frontend/src/main.tsx, with composition and top-level UI behavior in frontend/src/app/App.tsx. Frontend hooks/services call the backend through its API boundary, principally frontend/src/app/services/api.ts and frontend/src/app/services/chatServices.ts.
The backend entry point is kapruka-ai-agent/src/server.mjs. Express routes separate chat/streaming, products, delivery, orders, tracking, admin, and voice concerns; representative boundaries are kapruka-ai-agent/src/routes/chat.routes.mjs, kapruka-ai-agent/src/routes/products.routes.mjs, and kapruka-ai-agent/src/routes/voice.routes.mjs.
3. Conversational Request Pipeline
Chat requests flow from controllers into a seven-stage pipeline coordinated by kapruka-ai-agent/src/services/core/requestPipeline.service.mjs:
1. Load persistent/session context.
2. Understand intent, entities, sentiment, and language.
3. Detect/manage multi-turn workflow state.
4. Resolve product/UI references.
5. Apply pre-workflow validation/interceptions.
6. Invoke commerce operations.
7. Build a textual and structured UI response.
Stage modules make the ordered control flow explicit under kapruka-ai-agent/src/services/core/requestPipeline/01_contextLoader.mjs, kapruka-ai-agent/src/services/core/requestPipeline/03_workflowManager.mjs, and kapruka-ai-agent/src/services/core/requestPipeline/07_responseEngine.mjs. Streaming follows the chat SSE controller path in kapruka-ai-agent/src/controllers/chatStream.controller.mjs.
4. Prompt OS, LLM Decisioning, and Agent State
The agent assembles a modular system prompt from core, intelligence, commerce, and communication prompt packs via kapruka-ai-agent/src/agent/system/buildSystemPrompt.mjs and kapruka-ai-agent/src/agent/prompts/index.mjs. Prompt caching/versioning and runtime construction are isolated in kapruka-ai-agent/src/agent/core/promptCache.mjs and kapruka-ai-agent/src/agent/builders/runtimeBuilder.mjs.
LLM access, model selection, and streaming are bounded behind kapruka-ai-agent/src/services/ai/llm.service.mjs, kapruka-ai-agent/src/services/ai/modelRouter.mjs, and kapruka-ai-agent/src/services/ai/llmStream.service.mjs. Workflow definitions/transitions and reference resolution prevent the LLM from directly owning transactional state: kapruka-ai-agent/src/agent/workflow/05_workflowManager.mjs, kapruka-ai-agent/src/agent/reference/05_referenceManager.mjs.
5. Commerce and External Integrations
Commerce services execute product discovery, recommendations, delivery, order creation, and tracking, including structured data for frontend cards. Core examples are kapruka-ai-agent/src/services/commerce/concierge.service.mjs, kapruka-ai-agent/src/services/commerce/deliveryFlowService.mjs, and kapruka-ai-agent/src/services/commerce/order.service.mjs.
The Kapruka catalog/action boundary is MCP, encapsulated by kapruka-ai-agent/src/services/integration/mcp.service.mjs and kapruka-ai-agent/src/services/integration/mcp.client.mjs. Google Maps supports address/delivery capabilities through kapruka-ai-agent/src/services/integration/googleMapsService.mjs. Voice is similarly isolated in kapruka-ai-agent/src/services/media/voiceService.js.
6. Persistence, Cache, and Context
MongoDB/Mongoose stores conversations, workflow state, orders, user/product insights, delivery sessions, and summaries; key models include kapruka-ai-agent/src/database/Conversation.mjs, kapruka-ai-agent/src/database/ConversationState.mjs, and kapruka-ai-agent/src/database/Order.mjs. Memory services load and condense conversational context through kapruka-ai-agent/src/services/memory/memoryManager.service.mjs.
Redis/Upstash is an optional cache with memory fallback, bounded by kapruka-ai-agent/src/cache/redisCache.mjs and kapruka-ai-agent/src/cache/memoryCache.mjs. Startup health validation covers dependencies via kapruka-ai-agent/src/services/core/startupHealthService.mjs.
7. Frontend Interaction State
React contexts own client-side shopping state—cart, wishlists, comparison, recently viewed, and application state—rather than embedding it in individual cards: frontend/src/app/contexts/AppContext.tsx, frontend/src/app/contexts/CartContext.tsx, frontend/src/app/contexts/ComparisonContext.tsx. Chat, checkout, concierge, and search hooks translate user actions into API requests: frontend/src/app/hooks/useChat.ts, frontend/src/app/hooks/useCheckout.ts, frontend/src/app/hooks/useConcierge.ts. UI response payloads are rendered by chat/voice and commerce surfaces such as frontend/src/app/components/MessageArea.tsx, frontend/src/app/components/VoiceDashboard.tsx, and frontend/src/app/components/SmartInputPanel.tsx.
Main entry points: requestPipeline.service.mjs Request pipeline · concierge.service.mjs Commerce operations · server.mjs Express server · App.tsx Shopping UI
Components 22
React Client
- Shopping UI · Chat, voice, cards, carts, and workflow panels.
frontend/src/app/App.tsx - Client entry
frontend/src/main.tsx - API client
frontend/src/app/services/api.ts - Chat service · Issues chat and streaming requests.
frontend/src/app/services/chatServices.ts - Shopping state · Owns cart, wishlist, comparison, and app state.
frontend/src/app/contexts/AppContext.tsx - Chat and voice surfaces
frontend/src/app/components/MessageArea.tsx
Agent API
- Express server
kapruka-ai-agent/src/server.mjs - Chat and SSE API
kapruka-ai-agent/src/routes/chat.routes.mjs - Commerce APIs · Products, delivery, orders, and tracking boundaries.
kapruka-ai-agent/src/routes/products.routes.mjs - Voice API
kapruka-ai-agent/src/routes/voice.routes.mjs
Agent Runtime
- Request pipeline · Coordinates context, understanding, workflows, validation, commerce, and UI response.
kapruka-ai-agent/src/services/core/requestPipeline.service.mjs - Workflow stage · Manages multi-turn transactional state.
kapruka-ai-agent/src/services/core/requestPipeline/03_workflowManager.mjs - Response stage · Builds text and structured UI payloads.
kapruka-ai-agent/src/services/core/requestPipeline/07_responseEngine.mjs - Prompt runtime · Builds modular system prompts with cached runtime construction.
kapruka-ai-agent/src/agent/system/buildSystemPrompt.mjs - LLM gateway · Bounds model selection and streaming.
kapruka-ai-agent/src/services/ai/llm.service.mjs
Commerce & Integrations
- Commerce operations · Performs discovery, recommendations, delivery, and orders.
kapruka-ai-agent/src/services/commerce/concierge.service.mjs - Kapruka MCP · Catalog and action boundary for Kapruka.
kapruka-ai-agent/src/services/integration/mcp.service.mjs - Google Maps
kapruka-ai-agent/src/services/integration/googleMapsService.mjs - Voice service
kapruka-ai-agent/src/services/media/voiceService.js
State & Storage
- Conversation memory · Loads and condenses conversational context.
kapruka-ai-agent/src/services/memory/memoryManager.service.mjs - MongoDB models · Stores conversations, workflow state, and orders.
kapruka-ai-agent/src/database/Conversation.mjs - Cache fallback · Optional Redis/Upstash cache with in-memory fallback.
kapruka-ai-agent/src/cache/redisCache.mjs
Connections 25
- Client entry → Shopping UI: mounts
- Shopping UI → Shopping state: uses
- Shopping UI → Chat and voice surfaces: renders
- Chat and voice surfaces → Chat service: chat actions
- API client → Express server: REST
- Chat service → Chat and SSE API: chat / SSE
- Express server → Chat and SSE API: mounts
- Express server → Commerce APIs: mounts
- Express server → Voice API: mounts
- Chat and SSE API → Request pipeline: requests
- Request pipeline → Conversation memory: loads context
- Request pipeline → Workflow stage: manages flow
- Request pipeline → Prompt runtime: assembles prompt
- Prompt runtime → LLM gateway: decisioning
- Request pipeline → Commerce operations: invokes operations
- Request pipeline → Response stage: builds response
- Response stage → Chat and voice surfaces: structured payloads
- Commerce APIs → Commerce operations: direct operations
- Commerce operations → Kapruka MCP: catalog and actions
- Commerce operations → Google Maps: delivery addresses
- Voice API → Voice service: voice requests
- Conversation memory → MongoDB models: conversation state
- Workflow stage → MongoDB models: workflow state
- Commerce operations → MongoDB models: orders
- Request pipeline → Cache fallback: cached context