Files
X-Financial/server/README.md
DESKTOP-72TV0V4\caoxiaozhu 83d7da3d62 feat: add FastAPI backend with PostgreSQL and start script fixes
- Add server/ directory with FastAPI backend
- Fix server/start.sh to properly handle venv on Windows/Git Bash
- Add alembic migrations and pyproject.toml
- Add server tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-06 17:43:47 +08:00

72 lines
1.4 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.
# Server
后端已按 `FastAPI + PostgreSQL + SQLAlchemy + Alembic` 起好基础工程。
## 为什么先选 PostgreSQL
这个项目是报销、审批、员工、流程、审计记录为主,核心特点是:
- 强事务
- 多表关联明显
- 审批流和审计日志需要一致性
- 后续大概率要做复杂查询、统计和条件筛选
这类系统优先选关系型数据库更合适,`PostgreSQL` 是当前默认推荐。
## Redis 要不要现在上
现在 **不是必须**
先不把 Redis 作为启动前置,原因很直接:
- 当前第一阶段先把核心业务表、接口、权限、审批流跑通
- 如果一开始就把 Redis 绑死,会增加部署和排障复杂度
Redis 更适合后面这些场景:
- 登录态 / token 黑名单
- 热点数据缓存
- 限流
- 分布式锁
- 消息队列 / 后台任务
所以现在的策略是:
- 主数据库:`PostgreSQL`
- Redis`可选能力`,配置已预留,但不是必需依赖
## 目录
- `src/app/`:应用代码
- `alembic/`:数据库迁移
- `tests/`:测试
## 启动
1. 创建虚拟环境并安装依赖
```bash
cd server
python -m venv .venv
.venv\\Scripts\\activate
pip install -e .[dev]
```
2. 在项目根目录准备环境变量
```bash
copy ..\\.env.example ..\\.env
```
3. 启动服务
```bash
uvicorn app.main:app --reload --app-dir src
```
## 迁移
```bash
alembic upgrade head
```