
The Challenge
The core challenge was bridging the gap between static content and dynamic AI interactions. Implementing a RAG-based AI assistant that accurately retrieves real-time product specs from PayloadCMS was complex. Additionally, orchestrating the 'Quote-to-Invoice' workflow—where approved quotes automatically trigger PDF generation and email dispatch via Server Actions—required precise state management to prevent data inconsistencies.
Tech Stack
The Solution
Architected a monolithic-style application using Next.js 15 and PayloadCMS 3.0 backed by a serverless Neon (Postgres) database. Integrated Google Gemini 1.5 Flash for the RAG-based 'ChemBot' to parse live inventory data. Utilized Next.js Server Actions for secure Stripe payments and automated the entire post-purchase lifecycle using Payload Hooks and Resend for transactional emails.
1// AI Implementation: RAG (Retrieval-Augmented Generation) Logic
2// Feeding PayloadCMS Product Data into Google Gemini 1.5 Flash
3
4import { google } from '@ai-sdk/google';
5import { streamText } from 'ai';
6import { getPayload } from 'payload';
7import config from '@payload-config';
8
9export async function POST(req: Request) {
10 const { messages } = await req.json();
11 const payload = await getPayload({ config });
12
13 // 1. Retrieve Real-time Catalog Data (The 'R' in RAG)
14 const products = await payload.find({
15 collection: 'products',
16 limit: 50,
17 pagination: false,
18 });
19
20 // 2. Create Context Window for AI
21 const context = products.docs.map((p: any) =>
22 `Product: ${p.name}\nDetails: ${p.description}\nIn Stock: ${p.stockStatus}`
23 ).join('\n---\n');
24
25 // 3. Generate Response with Grounded Data
26 const result = streamText({
27 model: google('gemini-1.5-flash'),
28 system: `You are ChemBot. Answer strictly based on this inventory:\n${context}`,
29 messages,
30 });
31
32 return result.toDataStreamResponse();
33}Type Safety
Manual Emails
Core Integrations
Key Highlights
B2B RFQ System
Complete 'Request for Quote' workflow allowing admins to approve custom prices & quantities.
AI Product Assistant
RAG-based Chatbot using Gemini 1.5 Flash that answers queries based on live inventory data.
Dynamic Invoicing
Automated generation of downloadable PDF invoices with unique transaction IDs post-payment.
Admin Analytics
Visual dashboard using Recharts to track monthly sales, quote conversion rates, and inventory.
Next Project