# namburivivek/ofoods-ai architecture

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

- Interactive diagram: https://gitdiagram.com/namburivivek/ofoods-ai
- Repository: https://github.com/namburivivek/ofoods-ai

## Overview

OFOODS AI combines a customer-facing food-commerce assistant with a human-reviewed revenue-recovery workflow. The shopping path runs from customer requests through the assistant and AI service to product discovery or cart actions; the existing commerce server handles the broader account, order, checkout, and payment lifecycle. Recovery analyzes drop-off context, predicts recovery likelihood, proposes a strategy, and exposes cases for admin review. Several connections below are documented in the README; source excerpts confirm the internal recovery calls and database operations. Other server and frontend details are only represented at the subsystem level.

Main entry points: [`backend/ai/llmService.js`](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/llmService.js) (AI conversation service), [`backend/ai/agent.js`](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/agent.js) (Recovery agent), [`frontend/ai-assistant.js`](https://github.com/namburivivek/ofoods-ai/blob/main/frontend/ai-assistant.js) (Shopping assistant), [`backend/server.js`](https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js) (Commerce API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shopping["AI shopping"]
  node_assistant_ui["Shopping assistant<br/>[ai-assistant.js]"]
end

subgraph group_ai_core["AI services"]
  node_llm["AI conversation service<br/>[llmService.js]"]
  node_intent["Intent detection<br/>[intentDetector.js]"]
  node_context["User context"]
  node_catalog["Product catalog<br/>[catalog.js]"]
  node_product_engine["Product engine<br/>[productEngine.js]"]
  node_knowledge["Knowledge retrieval"]
end

subgraph group_commerce["Commerce platform"]
  node_ai_api["AI request API<br/>[server.js]"]
  node_commerce_server["Commerce API<br/>[server.js]"]
  node_frontend_server["Frontend server<br/>[server.js]"]
  node_cart["Cart and checkout<br/>[Checkout.html]"]
  node_payments["Razorpay payments<br/>[server.js]"]
  node_commerce_db[("Commerce database")]
end

subgraph group_recovery["Revenue recovery"]
  node_recovery_agent["Recovery agent<br/>[agent.js]"]
  node_analyzer["Customer analysis"]
  node_predictor["Recovery prediction"]
  node_strategy["Recovery strategy<br/>[llmService.js]"]
  node_recovery_cases[("Recovery cases")]
  node_recovery_api["Recovery case API"]
end

subgraph group_admin["Admin review"]
  node_dashboard["Recovery dashboard<br/>[ai-dashboard.js]"]
end

node_customer(("Customer"))
node_dropoff(("Payment or cart drop-off"))
node_admin_user(("Admin reviewer"))

node_customer -->|"asks"| node_assistant_ui
node_assistant_ui -->|"sends requests"| node_ai_api
node_ai_api -->|"invokes"| node_llm
node_llm -.->|"detects intent"| node_intent
node_llm -->|"uses context"| node_context
node_llm -->|"queries"| node_catalog
node_llm -->|"uses recommendations"| node_product_engine
node_product_engine -->|"searches"| node_catalog
node_llm -.->|"retrieves knowledge"| node_knowledge
node_assistant_ui -->|"updates cart"| node_cart
node_customer -->|"checks out"| node_cart
node_cart -.->|"submits order"| node_commerce_server
node_commerce_server -->|"reads and writes"| node_commerce_db
node_commerce_server -.->|"handles payment"| node_payments
node_dropoff -->|"triggers"| node_recovery_agent
node_recovery_agent -->|"analyzes customer"| node_analyzer
node_analyzer -->|"queries history"| node_commerce_db
node_recovery_agent -->|"calculates probability"| node_predictor
node_recovery_agent -->|"requests strategy"| node_strategy
node_recovery_agent -->|"creates case"| node_recovery_cases
node_recovery_api -->|"reads and updates"| node_recovery_cases
node_dashboard -.->|"loads cases"| node_recovery_api
node_admin_user -->|"reviews cases"| node_dashboard
node_dashboard -.->|"submits decision"| node_recovery_api

click node_assistant_ui "https://github.com/namburivivek/ofoods-ai/blob/main/frontend/ai-assistant.js"
click node_ai_api "https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js"
click node_llm "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/llmService.js"
click node_intent "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/intentDetector.js"
click node_context "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/userContextService.js"
click node_catalog "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/catalog.js"
click node_product_engine "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/productEngine.js"
click node_knowledge "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/knowledge/knowledgeRetriever.js"
click node_commerce_server "https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js"
click node_frontend_server "https://github.com/namburivivek/ofoods-ai/blob/main/frontend/server.js"
click node_cart "https://github.com/namburivivek/ofoods-ai/blob/main/frontend/Checkout.html"
click node_payments "https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js"
click node_recovery_agent "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/agent.js"
click node_analyzer "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/customerAnalyzer.js"
click node_predictor "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/recoveryPredictor.js"
click node_strategy "https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/llmService.js"
click node_recovery_api "https://github.com/namburivivek/ofoods-ai/blob/main/backend/aiRecoveryRoutes.js"
click node_dashboard "https://github.com/namburivivek/ofoods-ai/blob/main/frontend/ai-dashboard.js"

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_assistant_ui,node_admin_user toneBlue
class node_llm,node_intent,node_context,node_catalog,node_product_engine,node_knowledge toneAmber
class node_ai_api,node_commerce_server,node_frontend_server,node_cart,node_payments,node_commerce_db toneMint
class node_recovery_agent,node_analyzer,node_predictor,node_strategy,node_recovery_cases,node_recovery_api toneRose
class node_dashboard,node_customer,node_dropoff toneIndigo
```

## Components

### AI shopping

- [Shopping assistant](https://github.com/namburivivek/ofoods-ai/blob/main/frontend/ai-assistant.js): `frontend/ai-assistant.js`

### AI services

- [AI conversation service](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/llmService.js): `backend/ai/llmService.js`
- [Intent detection](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/intentDetector.js): `backend/ai/intentDetector.js`
- [User context](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/userContextService.js): `backend/ai/userContextService.js`
- [Product catalog](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/catalog.js): `backend/ai/catalog.js`
- [Product engine](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/productEngine.js): `backend/ai/productEngine.js`
- [Knowledge retrieval](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/knowledge/knowledgeRetriever.js): `backend/ai/knowledge/knowledgeRetriever.js`

### Commerce platform

- [AI request API](https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js): `backend/server.js`
- [Commerce API](https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js): `backend/server.js`
- [Frontend server](https://github.com/namburivivek/ofoods-ai/blob/main/frontend/server.js): `frontend/server.js`
- [Cart and checkout](https://github.com/namburivivek/ofoods-ai/blob/main/frontend/Checkout.html): `frontend/Checkout.html`
- [Razorpay payments](https://github.com/namburivivek/ofoods-ai/blob/main/backend/server.js): `backend/server.js`
- **Commerce database**

### Revenue recovery

- [Recovery agent](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/agent.js): `backend/ai/agent.js`
- [Customer analysis](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/customerAnalyzer.js): `backend/ai/customerAnalyzer.js`
- [Recovery prediction](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/recoveryPredictor.js): `backend/ai/recoveryPredictor.js`
- [Recovery strategy](https://github.com/namburivivek/ofoods-ai/blob/main/backend/ai/llmService.js): `backend/ai/llmService.js`
- **Recovery cases**
- [Recovery case API](https://github.com/namburivivek/ofoods-ai/blob/main/backend/aiRecoveryRoutes.js): `backend/aiRecoveryRoutes.js`

### Admin review

- [Recovery dashboard](https://github.com/namburivivek/ofoods-ai/blob/main/frontend/ai-dashboard.js): `frontend/ai-dashboard.js`

### Other components

- **Customer**
- **Payment or cart drop-off**
- **Admin reviewer**

## Connections

- Customer → Shopping assistant: asks (evidence: `README.md`)
- Shopping assistant → AI request API: sends requests (evidence: `README.md`)
- AI request API → AI conversation service: invokes (evidence: `backend/server.js`)
- AI conversation service → Intent detection: detects intent
- AI conversation service → User context: uses context (evidence: `backend/ai/llmService.js`)
- AI conversation service → Product catalog: queries (evidence: `backend/ai/llmService.js`)
- AI conversation service → Product engine: uses recommendations (evidence: `backend/ai/llmService.js`)
- Product engine → Product catalog: searches (evidence: `backend/ai/productEngine.js`)
- AI conversation service → Knowledge retrieval: retrieves knowledge
- Shopping assistant → Cart and checkout: updates cart (evidence: `README.md`)
- Customer → Cart and checkout: checks out (evidence: `README.md`)
- Cart and checkout → Commerce API: submits order
- Commerce API → Commerce database: reads and writes (evidence: `backend/server.js`)
- Commerce API → Razorpay payments: handles payment (evidence: `README.md`)
- Payment or cart drop-off → Recovery agent: triggers (evidence: `README.md`)
- Recovery agent → Customer analysis: analyzes customer (evidence: `backend/ai/agent.js`)
- Customer analysis → Commerce database: queries history (evidence: `backend/ai/customerAnalyzer.js`)
- Recovery agent → Recovery prediction: calculates probability (evidence: `backend/ai/agent.js`)
- Recovery agent → Recovery strategy: requests strategy (evidence: `backend/ai/agent.js`)
- Recovery agent → Recovery cases: creates case (evidence: `backend/ai/agent.js`)
- Recovery case API → Recovery cases: reads and updates (evidence: `backend/aiRecoveryRoutes.js`)
- Recovery dashboard → Recovery case API: loads cases
- Admin reviewer → Recovery dashboard: reviews cases (evidence: `README.md`)
- Recovery dashboard → Recovery case API: submits decision
