防幻觉 AI 导购:后端预过滤商品并校验模型返回的商品 ID,模型无法引用不存在的价格或库存
capstone-project-sk-ecommerce — React 电商模板
作者 StanleyNeo
NeoMart 是一个基于 React + Express + MongoDB 的全栈电商模板,内置防幻觉 AI 导购助手与三层智能搜索,可作为作品集项目或电商原型起点。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
目前有 1 张原始预览,可打开完整图片查看设计细节。
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
三层智能搜索:正则价格意图 → 加权关键词评分 → 仅必要时调用 LLM 解释
AI 提供商链:Gemini → DeepSeek → Smart Mock,无密钥时 AI 功能仍可通过 Smart Mock 使用
完整电商流程:商品筛选、购物车、结算、订单历史,订单总额由服务端计算并原子扣减库存
统一 API 响应格式 { success, count, data },包含 400/404/409 语义与幂等种子脚本
通过 frontend/src/siteConfig.js 与新的 data/seed.js 可整体更换品牌与商品目录
模板详细介绍
NeoMart 是一个全栈电商演示项目,前端使用 React(create-react-app),后端为 Express API,数据存储于本地 MongoDB。项目提供商品目录、分类筛选、价格与库存过滤、购物车抽屉、结算流程和带状态标签的订单历史。
AI 部分包含一个防幻觉的导购助手:后端先按关键词预过滤 MongoDB,只把真实商品(名称、价格、库存)注入系统提示,并要求模型返回结构化 JSON,再由后端校验商品 ID,因此模型无法编造价格或库存。智能搜索分三层:正则提取价格意图、加权关键词评分、仅当前两层结果较弱时才调用 LLM 解释。AI 提供商链为 Gemini(免费层,主)→ DeepSeek(备用)→ Smart Mock(离线,始终可答),相同提示有 5 分钟内存缓存,并提供按提供商统计的接口。
项目在 README 中说明其为 2025 年 AI 驱动 LMS 毕业设计的 2026 年重制版,复用原架构并升级 AI 栈。演示后端部署在 Render 免费层,闲置时会休眠,首次加载约需 30 秒唤醒。结算为模拟流程,未接入真实支付。项目采用 MIT 许可,可免费使用、修改、商用和分发该版本代码,但需保留版权与许可声明;外部服务(域名、托管、数据库、支付、AI)可能另行收费,演示图片、字体、图标等第三方素材需单独核对许可。
适合你的项目吗?
适用场景
- 作为全栈电商作品集项目,展示 React + Express + MongoDB 的完整实现
- 作为电商原型起点,替换种子数据后用于租赁、房产列表等不同商品类型
- 演示或教学 AI 导购与智能搜索的防幻觉设计,包括预过滤、结构化输出与提供商降级
- 在无 AI 密钥的离线环境中运行,依靠 Smart Mock 验证聊天与搜索流程
适合人群
- 需要全栈电商示例代码的学习者或开发者
- 希望快速搭建带 AI 导购的电商原型的团队
- 寻找 React + Express + MongoDB 作品集项目的求职者
- 需要演示防幻觉 AI 与分层搜索架构的技术分享者
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
需要 Node 22+ 与本地运行的 MongoDB
- 2
依次执行 npm install、复制 .env.example 为 .env、运行 node data/seed.js 填充 20 个商品/3 个用户/5 个订单
- 3
后端通过 node backend/src/server.js 启动在 :5000,前端在 frontend 目录执行 npm start 启动在 :3000
- 4
AI 密钥可选,不配置时 Smart Mock 仍可回答;GEMINI_API_KEY 与 DEEPSEEK_API_KEY 为可选环境变量
- 5
演示登录账号为 [email protected],结算为模拟流程,未接入真实支付
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 演示后端部署在 Render 免费层,闲置时会休眠,首次访问约需 30 秒唤醒,不适合对响应速度有要求的场景。
- 运行需要 Node 22+ 以及本地运行的 MongoDB 实例,环境准备有一定门槛。
- AI 密钥为可选;不配置密钥时 AI 功能降级为 Smart Mock 离线回答,而非真实大模型。
- 结算为模拟流程,未接入真实支付;Stripe 测试模式仅在路线图中,不能用于实际收款。
- 前端使用已弃用的 create-react-app,Vite 迁移仅在计划中,构建工具链较为陈旧。
- 默认 AI 提供商链依赖 Gemini 免费层与 DeepSeek 备用;免费层配额或服务变更会影响真实 AI 回答质量。
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
backend on Render free tier sleeps when idle; first load ~30s while it wakes
README 原文
Prereqs: Node 22+, local MongoDB running.
README 原文
copy .env.example .env # AI keys optional — Smart Mock works keyless
README 原文
Checkout is simulated — no payments (Stripe test mode is on the roadmap).
README 原文
`create-react-app` is deprecated — kept here deliberately for 2025 code reuse; a Vite migration is planned
README 原文
https://github.com/StanleyNeo/capstone-project-sk-ecommerce/blob/main/LICENSEhttps://github.com/StanleyNeo/capstone-project-sk-ecommerce/blob/main/README.mdGemini (free tier, primary) → DeepSeek (fallback) → Smart Mock (offline, always answers)
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-10-01。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料较完整 · 85 / 100
- 技术栈
- React
- 网站类型
- 电商 · 作品集
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2026-09-24
- 截图检查日期
- 2026-10-01
已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。
目录记录的主要技术栈是 React。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
已完成服务器许可规则与 AI 来源核对;未经过人工编辑审核。
查看当时使用的来源资料
SHA-256: 4087a878ac118a166974af352372553329729724ad69e0fcc6cf0e6024ca0df6
2026-10-01T01:28:59.097Z
来源文件 / 仓库# NeoMart — Full-Stack AI-Powered E-Commerce Capstone
> A demo store — **same engine, any business**. React + Express + MongoDB, with a
> hallucination-resistant AI chatbot and a 3-layer smart search. Built in 7 days as a
> 2026 regeneration of my 2025 AI-powered LMS capstone, reusing its architecture and
> upgrading the AI stack to the 2026 provider landscape.
> **Live demo:** https://neomart-theta.vercel.app — backend on Render free tier sleeps when idle; first load ~30s while it wakes

## Features
- **Storefront** — catalog grid, category pills, text/price/stock filters, cart drawer, checkout, order history with status pills
- **AI shop assistant (RAG-lite)** — answers with real names, prices and stock only; suggests alternatives instead of inventing products; product chips add straight to cart
- **Smart Search (3 layers)** — free regex price intent → weighted keyword scoring → LLM interpretation only when the free layers are weak
- **AI provider chain** — Gemini (free tier, primary) → DeepSeek (fallback) → Smart Mock (offline, always answers). 5-minute response cache; per-provider usage stats at `GET /api/ai/stats`
- **Engineering discipline** — `{ success, count, data }` envelope everywhere; 400/404/409 semantics; server-computed order totals; idempotent seed script; double-submit lock on checkout; startup banner with live data check
## Architecture
```
Browser — React (CRA, :3000) ← "Tables"
│ proxy /api →
Express API (:5000) ← "Kitchen"
├─ routes/ products · orders · users · ai
├─ services/ aiService (provider chain + cache + stats)
└─ config/ MongoDB connection
MongoDB local (:27017, db: ecommerce) ← "Pantry"
```
## The AI design (the interesting part)
### RAG-lite anti-hallucination
The LLM never sees the whole catalog. The backend pre-filters MongoDB by keywords,
injects only those real products (name/price/stock) into the system prompt, and demands
structured output `{"reply":"...","productIds":[...]}`. The backend then filters the
returned IDs against the real candidates — the model *can't* quote a fake price because
it never had one. Ask it for a PlayStation 5 and it honestly declines, then suggests a
real in-stock alternative.
### 3-layer Smart Search — cheapest intelligence first
1. **Regex** extracts price intent (`under $50`, "cheap" → cap 50) — free
2. **Weighted scoring** (tags +3, name +2, category +2, description +1) — free
3. **LLM interpretation** maps the query to categories/keywords — *only* when layers 1–2 return weak results
"cheap gifts for runners" costs $0 of LLM tokens: the price cap and the `gift` tag do all the work.
### Provider chain + cache
`Gemini → DeepSeek → Smart Mock`, each provider a config entry (model name lives in
`.env`, never hardcoded). Quota/auth failures fall through automatically — the demo never
dies on stage. Identical prompts are served from a 5-minute in-memory cache (key =
catalog + message, so a stock change busts the cache).


## Quick start
Prereqs: Node 22+, local MongoDB running.
```powershell
git clone https://github.com/StanleyNeo/capstone-project-sk-ecommerce.git
cd capstone-project-sk-ecommerce
npm install
copy .env.example .env # AI keys optional — Smart Mock works keyless
node data/seed.js # 20 products / 3 users / 5 orders
node backend/src/server.js # API on :5000 — watch the startup banner
cd frontend
npm install
npm start # storefront on :3000
```
Demo login: `[email protected]` (seeded). Checkout is simulated — no payments (Stripe test mode is on the roadmap).
## API reference
| Method | Endpoint | Notes |
|--------|----------|-------|
| GET | `/api/products` | filters: `category`, `search`, `minPrice`, `maxPrice`, `inStock` |
| GET | `/api/products/:id` | 404 envelope on unknown id |
| POST | `/api/orders` | 400 bad shape · 404 unknown user/product · 409 insufficient stock; server computes total |
| GET | `/api/orders/:userId` | newest first, items populated |
| GET | `/api/users/lookup?email=` | never returns password fields |
| POST | `/api/chatbot/chat` | `{ message }` → `{ reply, products[], provider }` |
| POST | `/api/search/smart` | `{ query }` → products + `meta` (maxPrice, interpretation) |
| GET | `/api/ai/stats` | per-provider success/error counts, cache size |
| GET | `/api/health` | liveness |
## Environment variables
| Key | Purpose | Required |
|-----|---------|----------|
| `MONGO_URI` | e.g. `mongodb://127.0.0.1:27017/ecommerce` | ✅ |
| `PORT` | API port (default 5000) | ✅ |
| `GEMINI_API_KEY` / `GEMINI_MODEL` | primary AI (free tier) | optional |
| `DEEPSEEK_API_KEY` | fallback AI | optional |
| `OPENAI_API_KEY` | second fallback | optional (unused) |
With no keys at all, every AI feature still works via Smart Mock.
## 2025 → 2026 migration notes
- `create-react-app` is deprecated — kept here deliberately for 2025 code reuse; a Vite migration is planned (`import.meta.env.VITE_*`, root `index.html`, proxy in `vite.config.js`)
- DeepSeek retired the `deepseek-chat` alias (2026-07) and `deepseek-v4-flash` (2026-09) — model names are config, so the fix was one `.env` line
- Gemini free tier is Flash-only since Apr 2026
- Gemini 3.x thinking models return **multi-part** responses (`content.parts[]` incl. thought parts) and count reasoning against `maxOutputTokens` — join non-thought parts and budget generously
## Verification highlights (tested during the build)
- Filters: electronics→5, `yoga`→1, ≤$25→3, out-of-stock→1
- Order for 1 Yoga Mat + 2 Resistance Bands = server-computed **$67.00**, stock decremented atomically, double-submit blocked by a `useRef` lock
- 409 surfaced as a friendly red box: `Insufficient stock for "Smart Fitness Watch": requested 10, available 9`
- Chatbot cache: fresh call ~2–9s → cache hit ~8ms
## Roadmap
- **Day 8a** — Vite migration
- **Day 8b** — Stripe test-mode payments + PayNow QR (zero-fee, Singapore)
- **Phase 2** — self-hosting on Synology DS223j NAS
- **Phase 3** — public demo: Vercel (frontend) + Render (API) + MongoDB Atlas
## Reuse this engine
The whole store rebrands from **one file**: `frontend/src/siteConfig.js`
(business name, tagline, currency, colors, categories) plus a new `data/seed.js` catalog.
Rental fleet, property listings, forex-indicator store — same engine, new seed.
## License
MIT — see [LICENSE](LICENSE).看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

react-portfolio-template
React powered portfolio website template for developers
React · 作品集

personal-website-react
personal-website-react 是一个面向开发者的个人作品集单页模板,由 React 和 Material-UI 构建,并通过 Create React App 初始化。
React · 作品集

karngyan.com
karngyan.com 是一个面向开发者的个人网站与博客模板,作者用它搭建了自己的站点,并公开了完整代码。 模板的核心定位很明确:让写作者专注于内容,而不是花时间搭建基础设施。
React · 作品集

react-portfolio-template
react-portfolio-template 是一个由 Ryan Balieiro 开发的 React 作品集模板,定位为“sleek, futuristic”,适合开发者展示个人履历。
React · 作品集

portfolio
Personal website, Data scientist portfolio template
React · 作品集

react-portfolio
react-portfolio 是一个面向开发者的个人作品集模板,基于 React 16 和 Create React App 构建,界面样式采用 Material-UI。
React · 作品集
