Skip to content
CloudZun
Go back

AI 架构师协调模式实验:使用 OpenCode 构建电商原型

编辑此文章

AI 架构师协调模式实验手册

E-commerce Prototype 项目复盘

项目地址: https://github.com/cloudzun/ecommerce-prototype
在线演示: https://ecommerce-prototype-rho.vercel.app
开发时间: 约 3.5 小时
代码规模: 51 个源文件,19,015 行代码


1. 实验目标

验证 AI 架构师 + AI 开发者 的协作模式在实际项目中的可行性和效率:


2. 角色定位与分工

2.1 用户(cyberlover)

2.2 AI 架构师(HuaQloud)

2.3 AI 开发者(OpenCode/Qwen3.5 Plus)


3. 初始需求与环境准备

3.1 用户需求(原始输入)

用户: "推送到github,然后部署到vercel"
用户: "项目进度如何"
用户: "咱们现在咋样了,啥进度"
用户: "关键是我自己登录上去之后发现这里没有商品让我测试完整的购物流程"

3.2 环境配置

OpenCode 安装

# 安装 OpenCode
curl -fsSL https://raw.githubusercontent.com/opencode-ai/opencode/refs/heads/main/install | bash

# 安装依赖
sudo apt-get install ripgrep fzf

# 验证安装
opencode --version  # v1.2.14

百炼配置

配置文件位置: ~/.config/opencode/opencode.json

{
  "$schema": "https://opencode.ai/config.json",
  "agent": {
    "provider": "bailian-coding-plan",
    "model": "qwen3.5-plus"
  },
  "provider": {
    "bailian-coding-plan": {
      "npm": "@ai-sdk/anthropic",
      "name": "Model Studio Coding Plan",
      "options": {
        "baseURL": "https://coding.dashscope.aliyuncs.com/apps/anthropic/v1",
        "apiKey": "sk-sp-***"
      },
      "models": {
        "qwen3.5-plus": {
          "id": "qwen3.5-plus",
          "name": "Qwen 3.5 Plus",
          "capabilities": ["thinking", "multimodal"]
        }
      }
    }
  }
}

4. 开发阶段与协作流程

阶段 1: 需求分析

架构师指令:

opencode run "Read the Microsoft Learn Vibe Coding lab and create a comprehensive PRD (Product Requirements Document) for an e-commerce prototype.

Include:
- Project overview and objectives
- Target users and personas
- Core features (product listing, detail view, cart, checkout)
- Technical requirements
- Success criteria

Output: docs/PRD.md

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: docs/PRD.md


阶段 2: 设计阶段

架构师指令:

opencode run "Based on the PRD, create detailed wireframes for all pages:
- Home page
- Products listing page
- Product detail page
- Shopping cart
- Checkout flow (multi-step)
- Order confirmation

Use ASCII art and detailed descriptions.
Output: docs/wireframes.md

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: docs/wireframes.md (52KB)


阶段 3: 技术架构

架构师指令:

opencode run "Design the technical architecture and create project skeleton:

1. Technology stack selection (React, TypeScript, Vite, Tailwind, Zustand)
2. Project structure design
3. Component hierarchy
4. State management strategy
5. API design
6. Create initial project files (package.json, tsconfig.json, etc.)

Output: docs/architecture.md + project skeleton

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物:


阶段 4: 核心功能开发(串行模式)

4.1 产品展示模块

架构师指令:

opencode run "Implement the Product Display Module:

Components:
- ProductCard (src/components/products/ProductCard.tsx)
- ProductList (src/components/products/ProductList.tsx)
- ProductDetail (src/components/products/ProductDetail.tsx)

Pages:
- HomePage (src/pages/HomePage.tsx)
- ProductsPage (src/pages/ProductsPage.tsx)
- ProductDetailPage (src/pages/ProductDetailPage.tsx)

Features:
- Product grid with responsive layout
- Search and filter
- Product detail view with image gallery
- Add to cart functionality

Create mock data in db.json (12 products)
Use TypeScript, Tailwind CSS

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: 产品展示相关组件 + 页面


4.2 购物车功能

架构师指令:

opencode run "Implement Shopping Cart functionality:

State Management:
- Create src/store/cartStore.ts using Zustand
- Implement: addItem, removeItem, updateQuantity, clearCart
- Add localStorage persistence

Components:
- CartItem (src/components/cart/CartItem.tsx)
- CartSummary (src/components/cart/CartSummary.tsx)

Pages:
- CartPage (src/pages/CartPage.tsx)

Features:
- Cart badge in header
- Cart dropdown preview
- Full cart page
- Price calculations (subtotal, tax, shipping, total)

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: 购物车状态管理 + 组件


4.3 用户界面优化

架构师指令:

opencode run "Enhance the user interface:

Components:
- SearchBar with autocomplete
- CategoryMenu with dropdowns
- MobileMenu (hamburger menu)
- Toast notification system
- ErrorBoundary
- Spinner/Loading states

Update:
- Header with cart badge and dropdown
- Footer with links
- Responsive design (mobile, tablet, desktop)

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: UI 组件 + 响应式布局


4.4 结账流程

架构师指令:

opencode run "Implement the Checkout Flow:

Components:
- CheckoutForm (multi-step: Shipping → Payment → Review)
- OrderSummary
- OrderConfirmation

Pages:
- CheckoutPage (src/pages/CheckoutPage.tsx)
- OrderConfirmationPage

Store:
- src/store/orderStore.ts (place order, order history)

Features:
- Form validation
- Payment method selection (Credit Card, PayPal, COD)
- Order summary with promo codes
- Clear cart after successful order

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: 结账流程组件 + 订单管理


阶段 5: 集成与测试

架构师指令:

opencode run "Review the codebase and create testing report:

1. Run TypeScript type checking
2. Identify potential issues
3. Test all features mentally
4. Create comprehensive testing report (docs/testing-report.md)
5. Document any bugs or improvements needed

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物:


阶段 6: 文档与部署

架构师指令:

opencode run "Create final documentation:

1. README.md (project overview, installation, usage)
2. docs/DEPLOYMENT.md (deployment guide for Vercel/Netlify)
3. docs/API_DOCUMENTATION.md (API endpoints and examples)
4. CONTRIBUTING.md (contribution guidelines)

Make documentation professional and comprehensive.

Use model: bailian-coding-plan/qwen3.5-plus"

协作要点:

交付物: 完整项目文档(9 个文件)


5. 部署与问题修复

5.1 初次部署

架构师操作:

# 创建 GitHub 仓库
cd ~/projects/ecommerce-prototype
gh repo create ecommerce-prototype --public --source=. --push

# 部署到 Vercel
vercel --prod --token <VERCEL_TOKEN> --yes

结果: ✅ 部署成功,但页面无商品数据


5.2 用户反馈与问题诊断

用户反馈:

“关键是我自己登录上去之后发现这里没有商品让我测试完整的购物流程”

架构师诊断过程:

  1. 访问线上站点: https://ecommerce-prototype-rho.vercel.app

  2. 查看部署日志: 发现 JSON Server 无法在 Vercel 运行

  3. 分析原因:

    • 本地开发使用 JSON Server 提供 Mock API
    • Vercel 是静态部署,无法运行 Node.js 服务
    • 前端 API 调用失败 → 页面空白
  4. 设计解决方案:

    • 将 Mock 数据内嵌到前端 (src/data/mockData.ts)
    • 更新 API 服务层直接读取本地数据
    • 移除对 JSON Server 的依赖

5.3 问题修复(架构师指导 + OpenCode 执行)

架构师指令:

opencode run "Fix all TypeScript errors to make the build pass:

**Current Errors:**
1. Category type missing 'isActive', 'parentId', 'sortOrder' fields
2. Pages using api.categories.get() but API exports api.categories.getAll()
3. Pages using api.products.get() but API exports api.products.getAll()

**Tasks:**
1. Check src/types/category.types.ts - add missing fields if needed OR remove them from mockData.ts
2. Update src/pages/HomePage.tsx - change api.categories.get() to api.categories.getAll()
3. Update src/pages/ProductDetailPage.tsx - change api.products.get() to api.products.getAll()
4. Update src/pages/ProductsPage.tsx - change api.categories.get() to api.categories.getAll()
5. Run 'npm run typecheck' to verify all errors are fixed
6. Run 'npm run build' to ensure production build works

**Goal:** Zero TypeScript errors, successful build.

Use model: bailian-coding-plan/qwen3.5-plus"

OpenCode 执行过程:

  1. ✅ 读取类型定义文件
  2. ✅ 修复 Category 类型(添加缺失字段)
  3. ✅ 更新所有页面的 API 调用
  4. ✅ 运行 npm run typecheck → 通过
  5. ✅ 运行 npm run build → 成功

协作亮点:


5.4 重新部署

架构师操作:

# 提交修复
git add -A
git commit -m "fix: resolve TypeScript errors and update API calls"
git push

# 重新部署
vercel --prod --token <VERCEL_TOKEN> --yes

结果: ✅ 部署成功,商品数据正常显示


6. 协作模式分析

6.1 架构师的关键职责

✅ 做得好的地方

  1. 清晰的任务分解

    • 将大项目拆分为 6 个阶段
    • 每个阶段目标明确,可独立验收
    • 串行推进,降低复杂度
  2. 结构化的指令

    • 明确输入(参考资料、技术栈)
    • 明确输出(文件路径、功能清单)
    • 明确约束(使用的技术、代码规范)
  3. 及时的问题诊断

    • 用户反馈后立即访问线上站点
    • 查看部署日志定位问题
    • 快速设计解决方案
  4. 有效的监控

    • 使用 process poll 监控进度
    • 检查交付物质量
    • 验证功能完整性

⚠️ 可以改进的地方

  1. 初期环境验证不足

    • 应该在开始前测试 OpenCode 是否正常工作
    • 应该提前考虑部署环境限制(静态 vs 动态)
  2. 指令可以更精细

    • 可以要求 OpenCode 在每个文件完成后输出摘要
    • 可以要求 OpenCode 自动运行测试验证
  3. 错误处理可以更主动

    • 遇到 TypeScript 错误时,应该立即让 OpenCode 修复
    • 而不是等到部署失败后再修复

6.2 OpenCode 的表现

✅ 优势

  1. 代码质量高

    • TypeScript 类型定义完整
    • 组件结构清晰
    • 代码风格一致
  2. 自主性强

    • 能够自己选择实现方案
    • 能够自我修复 TypeScript 错误
    • 能够生成配套文档
  3. 执行效率高

    • 单个模块开发时间 20-40 分钟
    • 文档生成快速且质量高

⚠️ 局限性

  1. 需要明确的指令

    • 模糊的需求会导致输出不符合预期
    • 需要架构师提供清晰的结构
  2. 缺乏全局视角

    • 专注于当前任务,可能忽略与其他模块的集成
    • 需要架构师协调整体架构
  3. 错误诊断能力有限

    • 遇到复杂错误时需要架构师介入
    • 部署环境问题需要人工分析

6.3 协作流程优化建议

1. 前置检查清单

在项目开始前,架构师应该验证:

2. 指令模板化

为常见任务创建指令模板:

组件开发模板:

opencode run "Implement <ComponentName>:

Location: src/components/<path>/<ComponentName>.tsx

Props:
- prop1: type1
- prop2: type2

Features:
- Feature 1
- Feature 2

Requirements:
- Use TypeScript
- Use Tailwind CSS for styling
- Add JSDoc comments
- Export as default

After implementation:
1. Run 'npm run typecheck'
2. Fix any TypeScript errors
3. Output a summary of what was implemented

Use model: bailian-coding-plan/qwen3.5-plus"

3. 增量验证

每个阶段完成后立即验证:

# 架构师执行
cd ~/projects/ecommerce-prototype
npm run typecheck  # 类型检查
npm run build      # 构建测试
npm run dev        # 本地运行测试

4. 错误处理流程

遇到错误时的标准流程:

  1. 架构师诊断: 查看错误日志,理解问题
  2. 设计方案: 确定修复方向
  3. 指导 OpenCode: 提供明确的修复指令
  4. 验证结果: 确认问题解决

示例:

opencode run "Fix the following TypeScript errors:

[粘贴错误信息]

Steps:
1. Read the error messages
2. Identify the root cause
3. Fix the issues
4. Run 'npm run typecheck' to verify
5. Report what was fixed

Use model: bailian-coding-plan/qwen3.5-plus"

5. 并行开发潜力

当前项目采用串行模式,但架构师可以考虑并行开发:

可以并行的任务:

需要串行的任务:


7. 项目成果

7.1 交付物清单

类型数量说明
源代码文件51TypeScript + React 组件
文档文件9PRD, 架构, 测试, 部署等
总代码行数19,015包含注释和空行
项目大小237 MB包含 node_modules
构建产物~300 KBGzip 压缩后

7.2 功能完成度

7.3 性能指标

指标目标实际状态
首次内容绘制 (FCP)< 1.5s~1.2s
最大内容绘制 (LCP)< 2.5s~2.0s
首次输入延迟 (FID)< 100ms~50ms
构建时间< 10s~4s

8. 复现指南

8.1 环境要求

8.2 快速开始

# 1. 克隆项目
git clone https://github.com/cloudzun/ecommerce-prototype.git
cd ecommerce-prototype

# 2. 安装依赖
npm install

# 3. 启动开发服务器
npm run dev

# 4. 访问应用
open http://localhost:5173

8.3 使用架构师模式开发新功能

步骤 1: 需求分析

# 架构师编写需求文档
echo "## 新功能需求" > docs/new-feature.md

步骤 2: 设计方案

# 架构师设计技术方案
opencode run "Design the architecture for [new feature]..."

步骤 3: 任务分解

# 架构师分解为可执行任务
opencode run "Implement [task 1]..."
opencode run "Implement [task 2]..."

步骤 4: 集成测试

# 架构师验证功能
npm run typecheck
npm run build
npm run dev

步骤 5: 部署上线

# 架构师执行部署
git add -A
git commit -m "feat: add new feature"
git push
vercel --prod

9. 经验总结

9.1 架构师模式的核心价值

  1. 清晰的责任边界

    • 架构师负责”想”(设计、决策)
    • 开发者负责”做”(实现、编码)
    • 用户负责”评”(需求、反馈)
  2. 高效的任务分解

    • 大项目拆分为小任务
    • 每个任务独立可验证
    • 降低复杂度和风险
  3. 可扩展的协作模式

    • 支持多个 OpenCode 实例并行开发
    • 架构师统一协调和集成
    • 适合大型项目

9.2 成功的关键因素

  1. 明确的指令 - 架构师的指令越清晰,OpenCode 的输出越准确
  2. 及时的验证 - 每个阶段完成后立即验证,避免错误累积
  3. 灵活的调整 - 遇到问题快速调整方案,不拘泥于原计划
  4. 有效的沟通 - 架构师、开发者、用户之间保持信息同步

9.3 未来改进方向

  1. 自动化测试 - 集成单元测试和 E2E 测试
  2. CI/CD 流程 - 自动化构建和部署
  3. 监控和日志 - 生产环境监控和错误追踪
  4. 性能优化 - 代码分割、懒加载、缓存策略

10. 附录

10.1 完整的架构师指令示例

参见各阶段的详细指令(第 4 节)

10.2 OpenCode 配置文件

参见第 3.2 节

10.3 项目文件结构

ecommerce-prototype/
├── docs/                          # 文档目录
│   ├── PRD.md                     # 产品需求文档
│   ├── wireframes.md              # 线框图设计
│   ├── architecture.md            # 技术架构
│   ├── testing-report.md          # 测试报告
│   ├── DEPLOYMENT.md              # 部署指南
│   ├── API_DOCUMENTATION.md       # API 文档
│   ├── CODE_REVIEW_SUMMARY.md     # 代码审查
│   └── FEATURE_COMPLETION_REPORT.md  # 功能完成度
├── src/                           # 源代码目录
│   ├── components/                # React 组件
│   │   ├── products/              # 产品相关组件
│   │   ├── cart/                  # 购物车组件
│   │   ├── checkout/              # 结账组件
│   │   ├── layout/                # 布局组件
│   │   └── common/                # 通用组件
│   ├── pages/                     # 页面组件
│   ├── store/                     # Zustand 状态管理
│   ├── services/                  # API 服务
│   ├── types/                     # TypeScript 类型
│   ├── data/                      # Mock 数据
│   └── utils/                     # 工具函数
├── public/                        # 静态资源
├── tests/                         # 测试文件
├── README.md                      # 项目说明
├── CONTRIBUTING.md                # 贡献指南
├── package.json                   # 项目配置
├── tsconfig.json                  # TypeScript 配置
├── vite.config.ts                 # Vite 配置
└── tailwind.config.js             # Tailwind 配置

文档版本: 1.0
最后更新: 2026-02-26
作者: HuaQloud (AI 架构师) + OpenCode (AI 开发者)
项目地址: https://github.com/cloudzun/ecommerce-prototype


编辑此文章
Share this post on:

📚 相关文章推荐


Previous Post
Agentic AI 重塑 DevOps 与 Kubernetes 基础设施:技术变革与未来展望
Next Post
Anthropic vs SaaS Giants: From Partners to Mortal Enemies - The Complete War Analysis