60 lines
3.6 KiB
Markdown
60 lines
3.6 KiB
Markdown
# Commercial Multi-Tenant Platform Implementation Plan
|
||
|
||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||
|
||
**Goal:** 将单工作区演示台升级为具有真实组织、工作区、用户、角色、项目 scope、邀请、审计和用量边界的本地商业化 AI 短剧生产平台 MVP。
|
||
|
||
**Architecture:** 使用 Node 24 内置 SQLite 持久化身份、租户、成员、项目、任务和治理数据;HTTP API 通过请求上下文解析 membership 和权限,再为 React 前端提供可切换的 organization/workspace/project context。既有剧本、资产、导演台和 QA 继续复用,但所有平台管理数据优先来自 SQLite,静态数据只作为无 API 时的回退。
|
||
|
||
**Tech Stack:** React 19 + Vite 7 + lucide-react;Node 24 `node:sqlite`;原生 Node HTTP;现有 Playwright 依赖用于渲染验证。
|
||
|
||
---
|
||
|
||
### Task 1: 建立租户数据库和种子数据
|
||
|
||
**Files:**
|
||
- Create: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/server/schema.sql`
|
||
- Create: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/server/db.mjs`
|
||
- Create: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/data/platform.sqlite` (运行时生成)
|
||
|
||
- [ ] 创建外键、索引、时间戳齐全的租户、成员、项目、任务、模型、配额、合规、审计表。
|
||
- [ ] 用两个组织、三个工作区、多个角色和两个项目建立可切换种子数据。
|
||
- [ ] 用 `DatabaseSync` 的 `prepare().run/all/get()` 封装参数化查询和事务。
|
||
- [ ] 运行 `node -e 'import("./server/db.mjs")'`,确认数据库和种子数据可读。
|
||
|
||
### Task 2: 增加 scope-aware API
|
||
|
||
**Files:**
|
||
- Create: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/server/tenant.mjs`
|
||
- Modify: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/server/local-api.mjs`
|
||
|
||
- [ ] 解析 `x-user-id`、`x-organization-id`、`x-workspace-id`、`x-project-id`。
|
||
- [ ] 在所有组织、工作区、项目、任务、模型、审片和导出接口执行 membership 和权限检查。
|
||
- [ ] 新增 context、组织、工作区、项目、邀请、用量、账单、权限和审计接口。
|
||
- [ ] 让新增任务、模型、项目和邀请写入 SQLite,并同步写 audit log / usage event。
|
||
|
||
### Task 3: 前端接入真实组织上下文
|
||
|
||
**Files:**
|
||
- Create: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/src/lib/api.js`
|
||
- Modify: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/src/App.jsx`
|
||
- Modify: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/src/styles.css`
|
||
|
||
- [ ] 启动时请求 `/api/context`,失败时显示明确的本地回退状态。
|
||
- [ ] 顶栏增加组织、工作区、项目和当前用户上下文切换。
|
||
- [ ] 平台管理页展示成员、待邀请、工作区、项目访问、权限矩阵、配额和审计。
|
||
- [ ] 邀请成员、创建工作区、创建项目和注册模型走真实 API,成功后刷新上下文。
|
||
|
||
### Task 4: 验证商业 MVP
|
||
|
||
**Files:**
|
||
- Verify: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/package.json`
|
||
- Verify: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/server/local-api.mjs`
|
||
- Verify: `/Users/xz/Documents/daima/ai短剧/ai-drama-platform/src/App.jsx`
|
||
|
||
- [ ] 运行 `npm run build`。
|
||
- [ ] 用 curl 验证默认组织、切换组织、邀请、创建工作区和越权请求。
|
||
- [ ] 在 `http://127.0.0.1:5173/` 验证桌面端和移动端,完成组织切换、平台管理和生成任务路径。
|
||
- [ ] 确认控制台无错误、页面不横向溢出,API 和 Vite 服务保持运行。
|
||
|