Provide an API service for external systems to access the KnowledgeBase functionalities, including chat, search, and document management.
[!IMPORTANT] Multi-Tenancy & Resource Sharing:
- Tenant Entity: We will introduce a
Tenant(Organization) entity.- Resource Scoping:
User,KnowledgeBase,KnowledgeGroup,SearchHistory,Note, andImportTaskwill be scoped bytenantId.- Configuration Hierarchy:
- ModelConfig: Inherited hierarchy:
System Models (Global)->Tenant Models (Shared in Org)->User Models (Private).- TenantSettings: New entity to define organization-wide defaults (Language, Default Models, Search thresholds).
UserSettingcan still override these for personalization.- Data Migration: Existing data will be migrated to a "Default Tenant" during the first run.
- Elasticsearch Isolation: The
tenantIdfield will be added to the ES mapping and enforced in all search/delete queries.- Storage Partitioning: Uploaded files will be stored in
uploads/{tenantId}/{fileId}to isolate files at the filesystem level.- API Key: Tied to
User, and all operations will be automatically scoped to the user's and tenant's data range.[!IMPORTANT] RBAC & Interface Separation:
- Roles:
SUPER_ADMIN: Manage Tenants and global system settings.TENANT_ADMIN: Manage Users and Knowledge Bases within their Tenant.USER: Access Chat, Search, and Knowledge Base within their Tenant.- API Separation: Administrative endpoints will be separated into
/api/v1/super-admin/*and/api/v1/admin/*.- UI Separation: Recommend separating the "Admin Portal" from the "User Workspace" to ensure a cleaner user experience and better security boundaries.
[!IMPORTANT] Frontend Modernization & Boundary Separation (Google Workspace Style):
- Design Aesthetic: Adopt a clean, modern, and professional style inspired by Google Workspace (Gmail, Drive, Gemini), following Material Design 3 specifications.
- Frontend Boundary Separation:
- User Workspace: Focused purely on end-user tools (Chat, Notebooks, Personal Settings).
- Admin Dashboard: Dedicated area for management (Knowledge Base files, System/Tenant Settings, Global Models).
- Implementation: We will introduce
react-router-domto provide clear URL boundaries (e.g.,/for workspace and/adminfor management) OR use a strict state-based layout split (WorkspaceLayoutvsAdminLayout) with an app switcher.- Core Elements:
- Sleek Navigation Rail: A minimal, collapsible sidebar with rounded active states, scoped to the current boundary (Admin vs Workspace).
- Top Global Search: A prominent, rounded search bar for quick access.
- Airy Layout: Increased white space and soft shadows to improve readability.
- Gemini-like Chat: A modern AI chat interface with clean message bubbles and a refined input area.
- Mockup:
Tenant entity with id and name.tenantId column (ManyToOne relationship with Tenant).role column (Enum: SUPER_ADMIN, TENANT_ADMIN, USER).apiKey column for API authentication.UserSetting).tenantId column (nullable for global models).tenantId column.tenantId column.tenantId column.tenantId column.createIndex mapping to include tenantId as a keyword field.searchSimilar, searchFullText, and hybridSearch to include term: { tenantId } filter.uploads/{tenantId}/{fileId} path.Tenant table.SUPER_ADMIN role.TENANT_ADMIN role or higher within the same tenant.WorkspaceLayout and AdminLayout.WorkspaceSidebarRail showing only user-centric views (chat, notebooks).AdminSidebarRail showing management views (knowledge, settings).curl -X GET http://localhost:3001/api/v1/knowledge-bases -H "x-api-key: YOUR_KEY"curl -X POST http://localhost:3001/api/v1/chat -H "x-api-key: YOUR_KEY" -d '{"message": "Hello"}'/api/user/api-key to get the key./api/v1/* endpoints.http://localhost:3001/api/docs.POST /api/v1/chat with stream: true returns SSE chunks.