Files
yeuimu aed9afef92 fix(api): add sync safety guards against degenerate SDS responses
Add SYNC_GUARDS thresholds so a partial/degenerate upstream response never
triggers a destructive operation:
- skip stale category deletion when the fetched tree is suspiciously small
  vs the existing SDS category count
- skip delist detection unless both leaf-category and seen-product counts
  are healthy

Verified: 77 tests pass; live SDS returns 226 categories (guard off),
incident-case ratios (2/226, 2/2) are correctly blocked.
2026-08-20 16:37:44 +08:00

127 lines
4.0 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.
# Inkreach
pnpm workspaces + Turborepo monorepo,包含三个协同工作的子项目和共享包:
| 子项目 | 包名 | 技术栈 | 端口 | 角色 |
|--------|------|--------|------|------|
| `apps/api` | `@inkreach/api` | NestJS 10 + Prisma 5 + PostgreSQL | 3001 | 后端 API(鉴权 / CRUD / SDS 同步 / 公开 API / Swagger |
| `apps/admin` | `@inkreach/admin` | Vue 3 + Vite + Element Plus + Pinia | 5173 | 后台管理(登录 / 商品 / 品类 / 国家 / 标签 / 坑位 / 同步) |
| `apps/website` | `@inkreach/website` | Nuxt 4 + Vue 3 + Tailwind v4 | 3000 | 官方展示站 + 产品中心页 |
| 共享包 | 说明 |
|--------|------|
| `packages/tsconfig` | 共享 TypeScript 配置(base / api / vue |
| `packages/shared-types` | 共享类型定义(PaginatedResult, BackendEnvelope, 实体接口) |
## 快速开始
### 1. 安装依赖
```bash
pnpm install
```
### 2. 环境变量
在仓库根目录的 `.env` 中配置数据库:
```env
DATABASE_URL=postgresql://postgres:<password>@localhost:5432/inkreach-official
```
后端额外需要的变量(在 `apps/api/.env` 中):
```env
JWT_SECRET=<your-secret>
SDS_API_BASE=https://api.sds.example.com
SDS_API_KEY=<your-key>
PORT=3001
```
官网通过 `apps/website/.env``NUXT_PUBLIC_BACKEND_URL=http://localhost:3001` 指向后端。
后台无需额外环境变量;Vite 代理已把 `/api/*` 转给 `http://localhost:3001`
### 3. 部署
启动顺序:先启动后端,再启动另两个。
```bash
# Terminal 1:后端(需要 PostgreSQL
cd apps/api
pnpm prisma:generate
pnpm prisma:migrate
pnpm start:dev
# → http://localhost:3001 · Swagger: http://localhost:3001/api/docs
# Terminal 2:官网
pnpm --filter @inkreach/website dev
# → http://localhost:3000
# Terminal 3:后台
pnpm --filter @inkreach/admin dev
# → http://localhost:5173
```
或者使用 Turborepo 同时启动所有开发服务器:
```bash
pnpm dev # turbo run dev
```
## 端口分配
| 端口 | 项目 | 入口 |
|------|------|------|
| 3001 | NestJS 后端 | `apps/api/src/main.ts` |
| 5173 | Vue Admin | `apps/admin/vite.config.ts` |
| 3000 | Nuxt 官网 | `apps/website/nuxt.config.ts` |
## 数据流概览
```
[SDS 外部 API]
│ (同步)
[NestJS 后端 :3001] ── public/goods ──► [Nitro 代理 /api/backend/*] ──► [Nuxt 官网 :3000]
│ ▲
├── /auth /goods /categories ... ──► │ Vite proxy /api/*
│ │
[PostgreSQL] [Vue Admin :5173]
```
## 常用命令
```bash
# 根目录(使用 pnpm workspace filter
pnpm install # 安装所有依赖
pnpm dev # 启动所有 dev 服务器 (turbo)
pnpm build # 构建所有项目 (turbo)
pnpm format # 格式化所有文件 (prettier)
# 后端
pnpm --filter @inkreach/api start:dev # 开发
pnpm --filter @inkreach/api build # 编译
pnpm --filter @inkreach/api test # 单元测试
pnpm --filter @inkreach/api prisma:generate # 生成 Prisma Client
pnpm --filter @inkreach/api prisma:migrate # 运行迁移
pnpm --filter @inkreach/api prisma:studio # 打开 Prisma Studio
# 官网
pnpm --filter @inkreach/website dev # 开发
pnpm --filter @inkreach/website build # 构建
pnpm --filter @inkreach/website generate # 静态站点生成
# 后台
pnpm --filter @inkreach/admin dev # 开发
pnpm --filter @inkreach/admin build # 构建
```
## 文档
- 整体目录结构:[`docs/references/structs.md`](docs/references/structs.md)
- 数据库表设计:[`docs/dev/database-table-design.md`](docs/dev/database-table-design.md)
- 产品中心 PRD[`docs/dev/product-center-prd.md`](docs/dev/product-center-prd.md)
- 官网子项目结构:[`apps/website/docs/references/structs.md`](apps/website/docs/references/structs.md)
- 开发规范:[`AGENTS.md`](AGENTS.md)