Production-ready AI-powered sustainable commerce platform.
- Frontend (Netlify): https://rayeva-ai-system.netlify.app
- Backend API (Render): https://rayeva-ai-system.onrender.com
Rayeva is a B2B/B2C sustainable commerce platform that uses OpenAI to automate product categorization, generate corporate proposals, and assist customers via WhatsApp. Built with a clean, layered architecture separating AI concerns from business logic.
rayeva-ai/
βββ backend/
β βββ server.js # Express entry point
β βββ routes/
β β βββ aiRoutes.js # API route definitions
β βββ controllers/
β β βββ categoryController.js # Module 1 input validation + response
β β βββ proposalController.js # Module 2 input validation + response
β βββ services/
β β βββ categoryService.js # Module 1 business logic
β β βββ proposalService.js # Module 2 business logic
β βββ ai/
β β βββ promptBuilder.js # Centralized prompt factory (system + user)
β β βββ openaiService.js # OpenAI API wrapper (JSON mode)
β β βββ aiLogger.js # Dual logger (Winston file + MongoDB)
β βββ models/
β β βββ AILog.js # AI interaction audit trail
β β βββ ProductCategory.js # Module 1 results storage
β β βββ B2BProposal.js # Module 2 results storage
β βββ middleware/
β β βββ validate.js # express-validator error formatter
β β βββ errorHandler.js # Global error handler
β β βββ requestLogger.js # HTTP request logging
β βββ utils/
β βββ logger.js # Winston app + AI logger instances
β βββ responseHelper.js # Standardized response wrappers
βββ frontend/
β βββ src/
β βββ pages/
β β βββ ProductUploadPage.jsx # Module 1 UI
β β βββ ProposalPage.jsx # Module 2 UI
β βββ components/
β β βββ ResultCard.jsx # Reusable AI result card
β β βββ LoadingSpinner.jsx # Animated spinner
β βββ services/
β βββ api.js # Axios API client
βββ logs/
βββ combined.log # All app logs
βββ error.log # Error-level logs only
βββ ai-prompts.log # AI prompt+response structured logs
- Node.js 18+
- MongoDB (local or Atlas)
- OpenAI API key
# Copy and fill environment variables
cp rayeva-ai/.env.example rayeva-ai/.envEdit .env:
MONGODB_URI=mongodb://localhost:27017/rayeva
OPENAI_API_KEY=sk-your-key-here
PORT=5000
FRONTEND_URL=http://localhost:5173
cd rayeva-ai/backend
npm install
npm run devServer starts on http://localhost:5000
cd rayeva-ai/frontend
npm install
npm run devFrontend runs on http://localhost:5173
POST /api/ai/category
Request:
{
"product_name": "Bamboo Toothbrush",
"description": "Eco-friendly toothbrush made from bamboo handle with BPA-free bristles"
}Response:
{
"success": true,
"message": "Category and tags generated successfully",
"data": {
"id": "65f...",
"primary_category": "Personal Care",
"sub_category": "Oral Care",
"seo_tags": ["bamboo toothbrush", "eco friendly toothbrush", "plastic free dental care", "sustainable oral care"],
"sustainability_filters": ["plastic-free", "compostable", "vegan"],
"ai_log_id": "65f..."
}
}GET /api/ai/category?page=1&limit=10
POST /api/ai/proposal
Request:
{
"budget": 5000,
"client_type": "Corporate office",
"event_type": "Employee welcome kits"
}Response:
{
"success": true,
"message": "B2B proposal generated successfully",
"data": {
"id": "65f...",
"recommended_products": [
{ "name": "Reusable Coffee Cup", "quantity": 200, "estimated_cost": 1500, "sustainability_note": "BPA-free, replaces 200 disposable cups daily" },
{ "name": "Bamboo Notebooks", "quantity": 200, "estimated_cost": 2000, "sustainability_note": "FSC-certified bamboo, fully biodegradable" }
],
"budget_allocation": {
"product_cost": 3500,
"packaging": 500,
"logistics": 1000
},
"impact_summary": "This proposal replaces single-use plastics and supports sustainable sourcing.",
"ai_log_id": "65f..."
}
}GET /api/ai/proposals?page=1&limit=10
We use OpenAI's response_format: { type: 'json_object' } so the API guarantees valid JSON output β no regex parsing, no markdown stripping.
- Module 1 (Category):
temperature: 0.3β low randomness for consistent categorization - Module 2 (Proposal):
temperature: 0.4β slightly higher for product variety
SYSTEM PROMPT = Role definition + Output schema + Hard rules
USER PROMPT = Specific input data + JSON keys expected
The system prompt defines what JSON keys to output and hard rules (e.g., budget allocation must sum to total). This drastically reduces schema validation errors.
All AI interactions are logged in two places:
logs/ai-prompts.logβ Structured JSON, timestamped, module-tagged- MongoDB
ailogscollection β Queryable audit trail with token usage
Sample log entry:
{
"timestamp": "2026-03-05 18:30:00",
"level": "info",
"message": "AI Interaction",
"module": "category-generator",
"status": "success",
"tokensUsed": 312,
"processingTimeMs": 1842
}Goal: Aggregate sustainability impact across all orders.
Endpoints:
GET /api/impact/reportβ Full platform impact reportGET /api/impact/report/:monthβ Monthly breakdown
Logic:
- Aggregate
ProductCategorydocs β count sustainability_filters - Aggregate
B2BProposaldocs β sum product quantities - Apply conversion constants (e.g. 1 bamboo product β 0.3kg plastic saved)
- Call OpenAI to generate narrative summary
- Return:
plastic_saved_kg,carbon_avoided_kg,products_sustainably_sourced,impact_narrative
New Models: ImpactReport { month, plastic_saved_kg, carbon_avoided_kg, products_count, narrative, generatedAt }
Goal: Automated customer support via WhatsApp Cloud API.
Endpoints:
GET /api/whatsapp/webhookβ Verify webhook (token challenge)POST /api/whatsapp/webhookβ Receive & process messages
Intent Routing:
| User Message | Bot Action |
|---|---|
| "Where is my order?" | Look up order in DB β reply with status |
| "What is your return policy?" | Return static FAQ response |
| "I want a refund" | Create support ticket β escalate to human |
| Default | Friendly fallback + escalation offer |
New Models:
WhatsAppConversation { phone_number, messages[], intent, status, createdAt }SupportTicket { phone_number, issue_type, status, conversation_id }
New Services: whatsappService.js, intentClassifierService.js, orderLookupService.js
| Variable | Description |
|---|---|
PORT |
Backend server port (default: 5000) |
NODE_ENV |
development or production |
MONGODB_URI |
MongoDB connection string |
OPENAI_API_KEY |
OpenAI API key |
WHATSAPP_TOKEN |
WhatsApp Cloud API token |
WHATSAPP_PHONE_NUMBER_ID |
WhatsApp Business phone ID |
WHATSAPP_VERIFY_TOKEN |
Webhook verification token |
FRONTEND_URL |
Frontend URL for CORS |
| Layer | Technology |
|---|---|
| Frontend | React 18 + Vite + TailwindCSS |
| Backend | Node.js + Express |
| Database | MongoDB + Mongoose |
| AI | OpenAI GPT-4o (JSON mode) |
| Logging | Winston (file + console) |
| Messaging | WhatsApp Cloud API (Module 4) |
| Env | dotenv |