logo
0
0
WeChat Login
feat: init

🤖 LangChain Agent

基于 NestJS + Next.js 混合架构的 LangChain Agent 项目。

🏗️ 架构特点

本项目采用独特的混合架构模式,将 NestJS 的微服务架构与 Next.js 的服务端渲染能力相结合:

客户端请求 → NestJS服务器 → 路由判断 → { 页面请求 → NextController → RenderService → Next.js Server → 页面组件 API请求 → AppController → AppService → 返回API响应 }

核心组件

  • NestJS 服务器: 统一请求入口和路由分发
  • Next.js 渲染引擎: 负责页面组件渲染
  • NextController: 处理页面请求
  • AppController: 处理API请求
  • RenderService: 封装Next.js渲染逻辑

🚀 快速开始

安装依赖

yarn install

开发模式

yarn start:dev

访问 http://localhost:3000 查看应用。

生产构建

yarn build yarn start:prod

📁 项目结构

langchain-agent/ ├── src/ # NestJS 源码 │ ├── main.ts # 应用入口 │ ├── app.module.ts # 根模块 │ ├── app.controller.ts # API 控制器 │ ├── app.service.ts # API 服务 │ ├── next.controller.ts # 页面控制器 │ ├── nextServer.ts # Next.js 服务封装 │ ├── render.module.ts # 渲染模块 │ └── render.service.ts # 渲染服务 ├── pages/ # Next.js 页面 │ ├── index.tsx # 首页 │ └── about.tsx # 关于页面 ├── test/ # 测试文件 └── 配置文件...

🛠️ 技术栈

  • 后端: NestJS + Express
  • 前端: Next.js + React
  • 语言: TypeScript
  • 包管理: Yarn
  • 架构: 单体混合架构

📝 可用脚本

  • yarn start:dev - 开发模式启动
  • yarn start:prod - 生产模式启动
  • yarn build - 构建项目
  • yarn test - 运行测试
  • yarn lint - 代码检查
  • yarn format - 代码格式化

🔗 API 端点

  • GET / - 首页
  • GET /about - 关于页面
  • GET /api - API 健康检查
  • GET /api/health - 服务状态
  • POST /api/data - 数据处理
  • GET /api/:id - 根据ID获取数据

🎯 开发指南

添加新的API端点

src/app.controller.ts 中添加新的路由处理方法。

添加新的页面

pages/ 目录下创建新的 .tsx 文件,Next.js 会自动处理路由。

自定义页面路由

src/next.controller.ts 中添加特定的页面路由处理。

📄 License

MIT