An AI‑assisted e‑commerce demo with product browsing, cart and ordering flows, plus a real‑time chat assistant that can recommend products, answer questions, and help with order actions. The app is split into a Vite + React client and a Node.js + Express server backed by PostgreSQL with pgvector embeddings. The assistant is powered by LangChain and OpenAI.
- Interactive Chat Assistant: A context-aware bot that acts as a sales associate. It can:
- Recommend products based on natural language queries (e.g., "Show me gifts for a toddler").
- Personalize suggestions based on your order history.
- Answer specific questions about store policies (Shipping, Returns) using vector search.
- Check order status and show line-item details.
- Securely cancel orders through a multi-step verification flow.
- Dynamic UI: The chat pushes interactive product cards to the interface, not just text.
- Full E-Commerce Flow: Product browsing, detailed views, shopping cart management, and checkout.
- Real-Time Updates: Order status changes and chat responses stream in real-time via WebSockets.
- Hybrid Search Engine: Combines Vector Search (Cosine Similarity via
pgvector) for semantic understanding and SQL Search (ILIKE) for keyword fallback. - Agentic Workflow: Powered by LangGraph to manage conversation state and intelligently select tools.
- Secure Auth: Role-based authentication (Admin/User) using JWT and HTTP-only cookies.
- Database Management: Fully typed schema and migrations using Drizzle ORM.
- Node.js 18+ and npm
- PostgreSQL 14+ with the
pgvectorextension - An OpenAI API key
Create a .env file in server/:
# Server
PORT=8080
NODE_ENV=development
# PostgreSQL (adjust to your database)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/smart_ecommerce
# Auth
JWT_SECRET=super-secret-string
# Admin bootstrap (bcrypt hash for your chosen admin password)
# Generate one with the command shown below in the Run section
ADMIN_HASH=$2a$10$ReplaceWithYourBcryptHash
# OpenAI
API_KEY=sk-...
Create a .env file in client/:
VITE_API_BASE_URL=http://localhost:8080- Create a database (example shown):
CREATE DATABASE smart_ecommerce;- Enable pgvector in that database:
CREATE EXTENSION IF NOT EXISTS vector;- Apply Drizzle migrations (from
server/):
cd server
npm install
npm run drizzle:push- Optional: Seed products/categories
- A sample file exists at
server/products.sql. It references category IDs 5–9. Ensure yourcategoriestable contains matching rows or update thecategory_idvalues in the SQL to match your DB. - You can import with
psqlor your favorite GUI:
# Example using psql (adjust connection/user/DB)
psql "postgresql://postgres:postgres@localhost:5432/smart_ecommerce" -f .\products.sql- Optional: Generate embeddings (requires
API_KEYand existing rows):
# From server/
npm run seed:policy-embeddings
npm run seed:product-embeddingsInstall dependencies and start both server and client.
# 1) Install deps
cd server; npm install; cd ..
cd client; npm install; cd ..
# 2) Start the server (port 8080 by default)
cd server
npm run dev
# Keep this running
# 3) In a new terminal, start the client (Vite on 5173)
cd client
npm run devClient: http://localhost:5173
On first server start, an admin account is created with email admin@local.com and the password hash from ADMIN_HASH. To generate a hash for a password of your choice (example: Admin@123), run in server/ after installing deps:
node -e "console.log(require('bcryptjs').hashSync('Admin@123', 10))"Set the printed hash in server/.env as ADMIN_HASH, restart the server, then log in with:
- Email:
admin@local.com - Password: the plaintext you hashed (e.g.,
Admin@123)
- CORS/Network: Ensure
VITE_API_BASE_URLmatches your server URL and the server CORS list includeshttp://localhost:5173. - DB Connection: Verify
DATABASE_URLand thatCREATE EXTENSION vector;ran in the correct database. - Missing Admin: Re‑generate
ADMIN_HASH, restart the server. - OpenAI Errors: Confirm
API_KEYis set and has access to the specified models. - Embeddings: Run the seed scripts after products/documents exist.
- Server:
npm run dev— start server with ts-node + nodemonnpm run drizzle:push— apply migrationsnpm run seed:policy-embeddings— embed policy documentsnpm run seed:product-embeddings— embed products
- Client:
npm run dev— start Vite dev servernpm run build— production buildnpm run preview— preview built client