Backend Service Design(后端服务设计)
知识库位置:
FDE Knowledge Base/03 Engineering/Software Engineering/System Design/Backend-Service-Design.md
Backend Service(后端服务)是大多数企业级 FDE 项目的核心组成部分。
它通常负责:
- Business Logic(业务逻辑)
- API(Application Programming Interface,应用程序编程接口)
- Authentication(身份认证)
- Authorization(授权)
- Data Access(数据访问)
- AI Orchestration(AI 编排)
- Integration(集成)
- Logging(日志记录)
- Error Handling(错误处理)
典型结构:
Client(客户端)↓API Layer(API 层)↓Application Layer(应用层)↓Domain / Business Logic(领域/业务逻辑)↓Data / External Services(数据/外部服务)Why It Matters(为什么重要)
Section titled “Why It Matters(为什么重要)”FDE 项目经常从一个 Prototype(原型)开始。
Prototype 中可能只有:
Frontend(前端)↓LLM API(大语言模型接口)但进入 Production(生产)后通常需要演变为:
Frontend(前端)↓Backend API(后端 API)↓Authentication(身份认证)↓Business Logic(业务逻辑)↓AI Orchestration(AI 编排)↓Enterprise Systems(企业系统)↓Database(数据库)Backend 是控制复杂性(Complexity,复杂性)的地方。
Separation of Concerns(关注点分离)
Section titled “Separation of Concerns(关注点分离)”建议至少区分:
API Layer(API 层)
Section titled “API Layer(API 层)”处理:
- Request(请求)
- Response(响应)
- Validation(校验)
Business Layer(业务层)
Section titled “Business Layer(业务层)”处理:
- Business Rules(业务规则)
- Workflow(工作流)
- Decision Logic(决策逻辑)
Integration Layer(集成层)
Section titled “Integration Layer(集成层)”处理:
- CRM API(Customer Relationship Management,客户关系管理系统接口)
- ERP API(Enterprise Resource Planning,企业资源计划系统接口)
- LLM API(Large Language Model,大语言模型接口)
- External Services(外部服务)
Data Layer(数据层)
Section titled “Data Layer(数据层)”处理:
- Database(数据库)
- Cache(缓存)
- Storage(存储)
FDE Principle(FDE 原则)
Section titled “FDE Principle(FDE 原则)”不要把所有逻辑写在一个 Endpoint(接口端点)中。
例如:
POST /agent内部同时完成:
- Prompt(提示词)
- Database(数据库)
- Permission(权限)
- CRM
- Email(邮件)
- Logging(日志)
短期很快,长期会非常难维护(Maintainability,可维护性)。
更好的方式是:
Controller(控制器)↓Service(服务)↓Policy(策略)↓Tool / Repository(工具/仓储层)