Technical Architecture: Smart Search (Federated Action Orchestrator)
Status: Draft Domain: Course Management Context: Building a scalable, deep-integration backend for Smart Search v3.
1. Architectural Overview
Phần tiêu đề “1. Architectural Overview”Để đáp ứng yêu cầu “Deep Resource Integration” (tổng hợp dữ liệu sâu từ nhiều nguồn) và “Platform-wide Extensibility” (khả năng mở rộng toàn nền tảng), hệ thống sử dụng mô hình Federated Action Orchestrator.
Mô hình này tách biệt hoàn toàn giữa Intent Detection (Frontend) và Data Aggregation (Backend), giúp hệ thống linh hoạt và dễ bảo trì.
1.1. The 3-Tier Model
Phần tiêu đề “1.1. The 3-Tier Model”graph TD Client[Frontend: Smart Search UI] -->|1. Submit Intent + Context| Gateway[Tier 1: API Gateway / BFF]
subgraph "Tier 2: The Orchestrator (Brain)" Gateway --> Orchestrator[Search Orchestrator] Orchestrator -->|Dispatch| AdapterCM[Course Mgmt Adapter] Orchestrator -->|Dispatch| AdapterUser[User Space Adapter]
AI_Worker[AI Context Worker] -.->|Enrich| Orchestrator end
subgraph "Tier 3: Domain Services (Data Sources)" AdapterCM -->|Pull Live Data| LMS_Service[LMS Core Service] AdapterCM -->|Pull Logs| Attendance_Service[Attendance Service] AdapterCM -->|Search Index| Search_Engine[Meilisearch / Elastic] end- Tier 1 (Frontend & Gateway): “The Asker”. Nhận diện ý định (
ACT_PRACTICE_PROCESS) và gửi về Backend kèm context (CourseID, UserID). Không chứa logic xử lý dữ liệu phức tạp. - Tier 2 (Orchestrator): “The Coordinator”. Trái tim của hệ thống. Nhận Intent, quyết định gọi Adapter nào, tổng hợp dữ liệu từ nhiều nguồn, và format lại theo chuẩn UI quy định.
- Tier 3 (Domain Services): “The Provider”. Các service vệ tinh cung cấp dữ liệu thô (Raw Data).
2. Data Strategy: Hybrid Pull & Push
Phần tiêu đề “2. Data Strategy: Hybrid Pull & Push”Để cân bằng giữa Tốc độ (Speed) và Tính tươi mới (Freshness), chúng ta áp dụng chiến lược Hybrid.
2.1. Real-time Pull (Cho “Live Data”)
Phần tiêu đề “2.1. Real-time Pull (Cho “Live Data”)”Dành cho dữ liệu thay đổi liên tục, cần độ chính xác tuyệt đối ngay tức thì.
- Use-cases:
- Lịch học ngày mai: Cần biết chính xác nếu lớp vừa bị hủy 1 phút trước.
- Trạng thái bài tập: Vừa nộp xong phải hiện “Completed” ngay.
- Điểm danh: Check-in xong phải thấy ngay.
- Implementation:
- Sử dụng GraphQL Federation hoặc gRPC.
- Orchestrator gọi song song (Parallel Requests) tới
LMS ServicevàAttendance Service. - Timeout thấp (e.g., 500ms). Nếu quá hạn, trả về fallback data.
2.2. Async Push to Search Engine (Cho “Searchable Resources”)
Phần tiêu đề “2.2. Async Push to Search Engine (Cho “Searchable Resources”)”Dành cho dữ liệu tĩnh hoặc ít thay đổi, cần tốc độ tìm kiếm cực nhanh (<50ms) trên tập dữ liệu lớn.
- Use-cases:
- Kho tài liệu: Slide, Video, Handout.
- Ngân hàng câu hỏi: Để phục vụ “AI Error Bank”.
- Từ vựng: Dictionary entries.
- Implementation:
- Write Path: Khi Teacher tạo bài mới -> Service bắn Event (
MaterialCreated) -> Worker hứng Event -> Index vào Meilisearch/Elasticsearch. - Read Path: Khi User search -> Orchestrator query trực tiếp vào Search Engine (không chạm vào DB chính).
- Write Path: Khi Teacher tạo bài mới -> Service bắn Event (
2.3. Pre-computation & Caching (Cho “AI Insights”)
Phần tiêu đề “2.3. Pre-computation & Caching (Cho “AI Insights”)”Dành cho các logic tính toán nặng, không thể chạy real-time mỗi lần search.
- Use-cases:
- Practice Journey: Thống kê hiệu suất tuần/tháng.
- Exam Readiness: Dự báo điểm rơi phong độ.
- AI Error Bank: Tổng hợp lỗi sai từ hàng nghìn record lịch sử.
- Implementation:
- Background Jobs: Chạy định kỳ (e.g., Cronjob mỗi đêm hoặc Trigger sau khi nộp bài thi lớn).
- AI Worker: Tính toán, aggregate dữ liệu, tạo ra file JSON kết quả (snapshot).
- Storage: Lưu snapshot này vào Redis hoặc NoSQL Doc Store.
- Read: Khi User mở Smart Search -> Orchestrator chỉ việc “bốc” snapshot từ Cache ra. Zero latency.
3. Extensibility Design (Thiết kế mở rộng)
Phần tiêu đề “3. Extensibility Design (Thiết kế mở rộng)”Để mở rộng ra toàn hệ thống (không chỉ Course Management), kiến trúc sử dụng Adapter Pattern.
3.1. The Adapter Interface
Phần tiêu đề “3.1. The Adapter Interface”Mọi Adapter muốn cắm vào Search Orchestrator phải tuân thủ Interface chuẩn:
interface IsSearchAdapter { getName(): string; // e.g., "CourseManagement", "Social" getSupportedIntents(): IntentID[]; // e.g., ["ACT_PRACTICE", "ACT_SCHEDULE"] execute(intent: IntentID, context: Context): Promise<SearchResult>;}3.2. Scenario: Mở rộng sang “Social Community”
Phần tiêu đề “3.2. Scenario: Mở rộng sang “Social Community””Sau này khi muốn làm Smart Search cho mảng Cộng đồng:
- Không sửa Core: Orchestrator giữ nguyên.
- Viết Adapter Mới: Tạo class
SocialAdapter.- Đăng ký Intent:
ACT_FIND_FRIEND,ACT_TRENDING_POST. - Logic: Gọi sang
Social Serviceđể lấy dữ liệu.
- Đăng ký Intent:
- Plug & Play: Register
SocialAdaptervào Orchestrator. Xong.
4. Security & Privacy
Phần tiêu đề “4. Security & Privacy”- Context-aware Scoping: Orchestrator luôn bắt buộc kèm
UserIDvàCurrentRoletrong mọi request. - Filtering tại nguồn: Search Engine chỉ trả về các items mà User có quyền truy cập (e.g., Tài liệu của khóa học mình đã mua).
5. Roadmap triển khai (Course Management First)
Phần tiêu đề “5. Roadmap triển khai (Course Management First)”-
Phase 1: Foundation (Gateway & Live Data)
- Dựng API
/smart-search/execute. - Implement
CourseAdapterkết nối API Lịch học & Bài tập hiện có. - Mục tiêu: Chạy được các widget cơ bản (Schedule Prep, Next Action).
- Dựng API
-
Phase 2: Speed Layer (Search Engine)
- Setup Meilisearch.
- Sync dữ liệu Tài liệu & Video vào Index.
- Mục tiêu: Search “tài liệu Unit 5” ra kết quả tức thì.
-
Phase 3: Intelligence Layer (Deep AI)
- Viết các AI Workers để chạy ngầm (tính toán Error Bank, Vocab Connector).
- Setup Redis caching cho các báo cáo thống kê nặng.
- Mục tiêu: Hoàn thiện các tính năng Deep Resource cao cấp.
References
Phần tiêu đề “References”../../../../Shared/Shared Capabilities/Smart Search Platform/SSP_00_Overview.md../../../../Shared/Shared Capabilities/Smart Search Platform/contracts/SSP_Intent_Taxonomy_Result_Contract.md../../../../Shared/Shared Capabilities/Smart Search Platform/contracts/SSP_Context_Pack_Adapter_Contracts.md../../../../Shared/Shared Capabilities/Smart Search Platform/governance/SSP_Rollout_Governance.md