cents/docs/技术方案.md

83 lines
1.6 KiB
Markdown
Raw Permalink 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.

# 技术方案
## 客户端
默认选 Web-first PWA。
技术栈:
- Vue 3 + TypeScript。
- Vite。
- PWA manifest + Service Worker。
- Vue Router。
- Pinia。
- Dexie + IndexedDB。
选择理由:
- 不需要应用商店安装。
- 更新由服务端发布,用户无需手动升级 App。
- 同一套代码覆盖 iOS、Android 和桌面浏览器。
- 账本主要是表单、列表、汇总和同步Web 足够。
本地存储:
- IndexedDB 是客户端主数据源。
- 所有账目先写本地,再进入同步队列。
- Service Worker 缓存应用壳,使无网络时仍能打开。
- localStorage 只存轻量配置。
## 后端
默认选 Node.js + TypeScript + Fastify + PostgreSQL。
职责:
- 账号登录。
- 设备审批。
- 账本、成员和邀请管理。
- 按账本权限过滤数据访问。
- 同步 push/pull。
- 服务端变更日志。
## 测试
首期只做 Playwright 端到端测试。
覆盖重点:
- 手机视口下的核心操作。
- 账本权限和邀请。
- 离线记账。
- 恢复网络后的同步。
暂不引入单元测试和组件测试。
## 备选
### React Native
仅在这些情况再考虑:
- 必须应用商店分发。
- 必须强后台同步。
- 必须调用大量原生能力。
- PWA 在目标设备上体验不可接受。
### Supabase / Firebase
可以加快早期开发,但离线同步和冲突语义仍要自己把控。当前不作为默认方案。
## 工程结构
```text
apps/
web/ # PWA Web App
services/
api/ # Fastify API
packages/
domain/ # 共享类型、同步操作定义
db/ # 数据库 schema 和迁移
docs/
```