Flipkart分钟克隆
一个使用MERN栈(MongoDB、Express、React、Node.js)构建的全栈电子商务应用程序,复制了Flipkart Minutes的杂货配送体验。
特性
后端API(15个端点)
- 认证:
login_user,register - 产品:
search_items,filter_products,get_alternatives - 购物车:
add_to_cart,remove_from_cart,get_cart_contents - 结账:
proceed_to_checkout,set_payment_mode,process_payment - 订单:
get_order_status,get_order_history,cancel_order - 地址:
get_available_addresses,set_delivery_location
前端功能
- 蓝色主题的Flipkart风格UI
- 类别转盘和产品网格
- 使用文本索引进行产品搜索
- 过滤器(价格、饮食偏好)
- 带有数量控制的购物车
- 带地址选择的结账流程
- 模拟UPI/COD付款
- 通过模拟骑手更新进行实时订单跟踪
- 订单历史
- 地址管理
技术栈
前端
- 反应19
- 快7
- 顺风CSS 4
- Redux工具包2.5
- React路由器7
- 公理1.7
- 反应热吐司
- 反应图标
后端
- Node.js 18+
- 快递5
- MongoDB与Mongoose 8
- JWT身份验证
- 用于密码哈希的bcryptjs
- 快递验证器
入门指南
先决条件
- Node.js 18+
- MongoDB(本地或Atlas)
快速开始
- 安装所有依赖项
# Install backend dependencies
cd server && npm install
# Install frontend dependencies
cd ../client && npm install- 配置环境变量
后端 .env (服务器/.env):
MONGODB_URI=mongodb://localhost:27017/flipkart-minutes
JWT_SECRET=your-secret-key-change-in-production
JWT_EXPIRES_IN=7d
PORT=5000
CLIENT_URL=http://localhost:5173前端 .env (客户端/.env):
VITE_API_URL=http://localhost:5000/api
VITE_APP_NAME=Flipkart Minutes- 启动MongoDB
# If using local MongoDB
mongod
# Or use MongoDB Atlas connection string in MONGODB_URI- 为数据库添加种子
cd server
npm run seed种子脚本是 幂等 -您可以安全地多次运行它:
- 首次运行:创建所有数据
- 后续运行:如果数据存在则跳过
- 强制新鲜种子:
npm run seed -- --fresh
- 启动服务器
终端1(后端):
cd server
npm run dev2号航站楼(前端):
cd client
npm run dev访问应用程序
- 前端: http://localhost:5173
- 后端API: http://localhost:5000/api
- 健康检查: http://localhost:5000/api/health
演示凭据
- 电子邮件:
test@example.com - 密码:
password123
集成详细信息
前端-后端通信
- 前端在开发中使用Vite代理(
/api->localhost:5000) - 带有JWT令牌拦截器的Axios实例
- 自动令牌刷新处理
- 为跨源请求配置CORS
API路线图
| 前端API调用 | 后端路由 |
|---|---|
authAPI.login() | 职位 /api/auth/login |
productAPI.getCategories() | 得到 /api/products/categories |
productAPI.searchProducts() | 得到 /api/products/search |
cartAPI.getCart() | 得到 /api/cart |
orderAPI.getOrderStatus() | 得到 /api/orders/:id/status |
addressAPI.getAddresses() | 得到 /api/addresses |
项目结构
Fk-MCP/
├── client/ # React Frontend
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ │ ├── common/ # Header, Footer, Loader
│ │ │ ├── home/ # CategoryCarousel
│ │ │ └── product/ # ProductCard
│ │ ├── pages/ # Page components
│ │ ├── store/ # Redux store & slices
│ │ ├── services/ # API service layer
│ │ └── index.css # Tailwind styles
│ └── package.json
│
└── server/ # Express Backend
├── src/
│ ├── config/ # DB, constants
│ ├── controllers/ # Route handlers
│ ├── middleware/ # Auth, validation, error
│ ├── models/ # Mongoose schemas
│ ├── routes/ # API routes
│ └── seed/ # Database seeding
├── server.js
└── package.jsonAPI 文档
认证
| 方法 | 端点 | 描述 |
|---|---|---|
| 职位 | /api/auth/register | 注册新用户 |
| 职位 | /api/auth/login | 登录用户 |
| 得到 | /api/auth/me | 获取当前用户 |
产品
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/products/categories | 获取所有类别 |
| 得到 | /api/products/category/:id | 按类别获取产品 |
| 得到 | /api/products/search?q= | 搜索产品 |
| 得到 | /api/products/filter | 过滤产品 |
| 得到 | /api/products/:id | 获取单一产品 |
| 得到 | /api/products/:id/alternatives | 获取类似产品 |
购物车
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/cart | 获取购物车内容 |
| 职位 | /api/cart/items | 将商品添加到购物车 |
| PUT | /api/cart/items/:productId | 更新项目数量 |
| 删除 | /api/cart/items/:productId | 删除项目 |
订单
| 方法 | 端点 | 描述 |
|---|---|---|
| 职位 | /api/checkout | 创建订单 |
| PUT | /api/orders/:id/payment-mode | 设置付款方式 |
| 职位 | /api/orders/:id/pay | 处理付款 |
| 得到 | /api/orders/:id/status | 获取订单状态 |
| 得到 | /api/orders | 获取订单历史记录 |
| 职位 | /api/orders/:id/cancel | 取消订单 |
地址
| 方法 | 端点 | 描述 |
|---|---|---|
| 得到 | /api/addresses | 获取所有地址 |
| 职位 | /api/addresses | 创建地址 |
| PUT | /api/addresses/:id | 更新地址 |
| 删除 | /api/addresses/:id | 删除地址 |
| 职位 | /api/session/location | 设置交货地点 |
种子数据
种子脚本创建:
- 10个杂货类别
- 50多种产品,价格和图片逼真
- 1个具有2个地址的测试用户
MCP服务器(人工智能购物助手)
该项目包括一个智能MCP(模型上下文协议)服务器,使AI助手能够通过自然对话帮助用户购物。
MCP功能
- 24种人工智能工具:搜索、购物车、结账、食谱、日程安排、建议
- 配方智能:15个内置配方,具有自动配料缩放功能
- 预定订单:“下午6点交货”-在预定时间自动执行
- 聪明的建议:基于时间、购物车、历史的情境感知建议
- 对话记忆:多回合上下文跟踪
快速MCP设置
# Install MCP dependencies
cd mcp-server && npm install
# Build
npm run build
# Configure in Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"flipkart-minutes": {
"command": "node",
"args": ["/path/to/Fk-MCP/mcp-server/dist/index.js"]
}
}
}对话示例
User: "I want to make chicken biryani for 6 people"
AI: Lists all ingredients, scales quantities, shows total cost
User: "Order groceries for tomorrow 5 PM"
AI: Builds cart, schedules delivery, auto-places order at 5 PM
User: "What should I buy?"
AI: Suggests based on time of day, cart contents, order history📚 完整的MCP文档:参见 mcp服务器/README.md 获取完整的技术文档。
许可证
麻省理工学院
