Files
DevFlow/docs/02-架构设计/前后端类型对齐.md
绝尘 98393b4908 新增: 初始化 DevFlow 项目仓库
Tauri 2 + Vue 3 + Vite 6 桌面应用,Rust workspace 含 13 个 crate
(df-ai / df-storage / df-workflow / df-core / df-execute 等)。
核心能力:AI 聊天 agentic 循环(工具调用+人工审批)、工作流引擎、
任务/想法/项目/阶段管理、可追溯性,及配套前端组件。
2026-06-12 01:31:05 +08:00

83 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 前后端类型对齐
> 创建: 2026-06-10 | 状态: 初稿
---
## 概述
DevFlow 前端 (TypeScript) 和后端 (Rust) 通过 Tauri IPC 和 JSON 序列化通信。两侧的类型定义必须保持一致。
## 类型映射
### 基础类型
| Rust | TypeScript | 说明 |
|------|-----------|------|
| `String` | `string` | 文本字段 |
| `i64` | `number` | 时间戳 (Unix timestamp) |
| `Option<String>` | `string \| null` | 可空字段 |
| `Vec<String>` | `string[]` | 数组 (JSON 序列化) |
| `bool` | `boolean` | 布尔值 |
### ID 类型
| 实体 | Rust | TypeScript | 格式 |
|------|------|-----------|------|
| 所有 ID | `String` | `string` | UUID v4 |
所有 ID 统一使用 UUID v4 字符串,便于前后端传递。
### 枚举对齐
#### IdeaStatus (8 值)
| Rust | TypeScript |
|------|-----------|
| `Draft` | `"Draft"` |
| `Evaluating` | `"Evaluating"` |
| `Scored` | `"Scored"` |
| `Hot` | `"Hot"` |
| `Promoted` | `"Promoted"` |
| `Parked` | `"Parked"` |
| `Merged` | `"Merged"` |
| `Discarded` | `"Discarded"` |
#### TaskStatus (6 值)
| Rust | TypeScript |
|------|-----------|
| `Created` | `"Created"` |
| `BranchCreated` | `"BranchCreated"` |
| `InProgress` | `"InProgress"` |
| `ReviewReady` | `"ReviewReady"` |
| `Merged` | `"Merged"` |
| `Abandoned` | `"Abandoned"` |
#### WorkflowRunStatus (6 值)
| Rust | TypeScript |
|------|-----------|
| `Pending` | `"Pending"` |
| `Running` | `"Running"` |
| `Paused` | `"Paused"` |
| `Completed` | `"Completed"` |
| `Failed` | `"Failed"` |
| `Cancelled` | `"Cancelled"` |
#### ProjectStatus (4 值)
| Rust | TypeScript |
|------|-----------|
| `Active` | `"Active"` |
| `Paused` | `"Paused"` |
| `Completed` | `"Completed"` |
| `Archived` | `"Archived"` |
## 约定
1. 枚举值使用 PascalCase 字符串,前后端保持一致
2. JSON 字段(如 `scores``tags`)在 Rust 侧用 `TEXT` 存储 JSON 字符串,前端解析为对象/数组
3. 时间字段统一用 `i64` (Unix timestamp),前端用 `new Date(ts * 1000)` 转换
4. 新增枚举值时Rust 和 TypeScript 两侧必须同步更新