{
    "database": {
        "title": "数据库设计",
        "subtitle": "了解 DeepTrans Studio 的数据库架构和表结构设计",
        "introduction": {
            "title": "数据库概述",
            "description": "DeepTrans Studio 使用 PostgreSQL 作为主数据库，通过 Prisma ORM 进行数据访问和管理。数据库设计支持多租户、用户权限、项目管理和翻译工作流等核心功能。"
        },
        "technology": {
            "title": "技术栈",
            "description": "数据库相关技术选型：",
            "items": [
                {
                    "name": "PostgreSQL",
                    "description": "主数据库，存储用户、项目、文档、词典、翻译记忆等结构化数据"
                },
                {
                    "name": "Prisma ORM",
                    "description": "类型安全的 ORM，提供数据库访问、迁移管理和类型生成"
                },
                {
                    "name": "Valkey",
                    "description": "缓存和任务队列，用于存储临时数据和 BullMQ 任务队列"
                },
                {
                    "name": "pgvector",
                    "description": "PostgreSQL 向量扩展，用于翻译记忆 embedding 检索和语义搜索"
                },
                {
                    "name": "PGroonga",
                    "description": "支持 CJK 的 PostgreSQL 全文检索扩展，用于中文、日文、韩文关键词检索"
                },
                {
                    "name": "对象存储",
                    "description": "本地开发使用 MinIO，生产环境使用腾讯云 COS，存储文档文件、解析产物和静态资源"
                }
            ]
        },
        "coreModels": {
            "title": "核心数据模型",
            "description": "数据库中的主要数据模型：",
            "models": [
                {
                    "name": "User（用户）",
                    "description": "用户账户信息，支持多租户和角色管理",
                    "keyFields": ["id", "email", "name", "role", "tenantId"],
                    "relations": ["projects", "documents", "dictionaries", "translationMemories"]
                },
                {
                    "name": "Tenant（租户）",
                    "description": "多租户支持，组织级别的数据隔离",
                    "keyFields": ["id", "name", "description"],
                    "relations": ["users", "projects", "dictionaries", "translationMemories"]
                },
                {
                    "name": "Project（项目）",
                    "description": "翻译项目，包含项目基本信息和语言设置",
                    "keyFields": ["id", "name", "domain", "sourceLanguage", "targetLanguage"],
                    "relations": ["documents", "projectDictionaries", "projectMemories"]
                },
                {
                    "name": "Document（文档）",
                    "description": "项目中的文档，存储文档元数据和文件信息",
                    "keyFields": ["id", "name", "originalName", "url", "status", "structured"],
                    "relations": ["documentItems", "project"],
                    "notes": "structured 字段存储 JSON 格式的解析产物信息"
                },
                {
                    "name": "DocumentItem（文档项）",
                    "description": "文档中的段落/片段，是翻译的基本单位",
                    "keyFields": [
                        "id",
                        "documentId",
                        "order",
                        "sourceText",
                        "targetText",
                        "status",
                        "type"
                    ],
                    "relations": ["document", "translationStageTimelines"],
                    "notes": "包含各阶段的中间结果（preTranslateTerms、qualityAssureSyntax 等）"
                },
                {
                    "name": "Dictionary（词典）",
                    "description": "术语词典，支持公共、项目和私有三种可见性",
                    "keyFields": ["id", "name", "domain", "visibility", "tenantId", "userId"],
                    "relations": ["entries", "projectBindings"]
                },
                {
                    "name": "DictionaryEntry（词典条目）",
                    "description": "词典中的术语对照",
                    "keyFields": ["id", "sourceText", "targetText", "notes", "dictionaryId"],
                    "relations": ["dictionary"]
                },
                {
                    "name": "TranslationMemory（翻译记忆库）",
                    "description": "翻译记忆库，存储源文-译文对照",
                    "keyFields": ["id", "name", "sourceText", "targetText", "tenantId", "userId"],
                    "relations": ["entries", "projectBindings"]
                },
                {
                    "name": "TranslationMemoryEntry（翻译记忆条目）",
                    "description": "翻译记忆库中的具体条目",
                    "keyFields": [
                        "id",
                        "memoryId",
                        "sourceText",
                        "targetText",
                        "embedding",
                        "sourceLang",
                        "targetLang"
                    ],
                    "relations": ["memory"],
                    "notes": "embedding 字段存储 pgvector 向量；sourceText 和 targetText 通过 PGroonga 建索引以支持 CJK 关键词检索"
                },
                {
                    "name": "TranslationStageRecord（翻译阶段记录）",
                    "description": "记录翻译过程中每个阶段的执行历史",
                    "keyFields": [
                        "id",
                        "documentItemId",
                        "stepKey",
                        "actorType",
                        "status",
                        "metadata"
                    ],
                    "relations": ["documentItem"],
                    "notes": "用于追踪翻译流程、调试和审计"
                },
                {
                    "name": "ProjectDictionary（项目-词典关联）",
                    "description": "项目与词典的多对多关联",
                    "keyFields": ["projectId", "dictionaryId"]
                },
                {
                    "name": "ProjectMemory（项目-记忆库关联）",
                    "description": "项目与翻译记忆库的多对多关联",
                    "keyFields": ["projectId", "memoryId"]
                }
            ]
        },
        "enums": {
            "title": "枚举类型",
            "description": "数据库中定义的枚举类型：",
            "items": [
                {
                    "name": "TranslationStage",
                    "values": [
                        "NOT_STARTED",
                        "MT",
                        "MT_REVIEW",
                        "QA",
                        "QA_REVIEW",
                        "POST_EDIT",
                        "POST_EDIT_REVIEW",
                        "SIGN_OFF",
                        "COMPLETED",
                        "ERROR",
                        "CANCELED"
                    ],
                    "description": "翻译阶段枚举，表示文档项的翻译状态"
                },
                {
                    "name": "DictionaryVisibility",
                    "values": ["PUBLIC", "PROJECT", "PRIVATE"],
                    "description": "词典可见性，控制词典的访问范围"
                },
                {
                    "name": "DocumentStatus",
                    "values": [
                        "WAITING",
                        "PARSING",
                        "SEGMENTING",
                        "TERMS_EXTRACTING",
                        "PREPROCESSED",
                        "TRANSLATING",
                        "COMPLETED",
                        "ERROR"
                    ],
                    "description": "文档处理状态，跟踪文档的处理进度"
                },
                {
                    "name": "TranslationProcessActorType",
                    "values": ["AGENT", "USER"],
                    "description": "翻译流程执行者类型，区分 AI 代理和人工操作"
                },
                {
                    "name": "TranslationProcessStepStatus",
                    "values": ["STARTED", "SUCCESS", "FAILED"],
                    "description": "翻译步骤执行状态"
                },
                {
                    "name": "UserRole",
                    "values": ["ADMIN", "USER"],
                    "description": "用户角色"
                }
            ]
        },
        "migrations": {
            "title": "数据库迁移",
            "description": "使用 Prisma Migrate 管理数据库架构变更：",
            "commands": [
                {
                    "command": "yarn prisma migrate dev",
                    "description": "开发环境创建新迁移"
                },
                {
                    "command": "yarn prisma migrate deploy",
                    "description": "生产环境应用迁移"
                },
                {
                    "command": "yarn prisma generate",
                    "description": "生成 Prisma Client"
                },
                {
                    "command": "yarn prisma studio",
                    "description": "打开 Prisma Studio 可视化数据库"
                }
            ]
        }
    }
}
