Appearance
Process Flows
Quick Reference
- Số luồng chính: 5
- Định dạng: Mermaid Flowchart + Sequence Diagram
- Source: Trace từ services, components, interceptors
1. AI Chat Flow
Mô tả chi tiết:
- User mở
/chat— hệ thống kiểm traAiConfigService.hasActiveConnector(ai-config.service.ts:20) - Nếu chưa có connector → hiện
AiConfigWizardComponentđể setup - User nhập câu hỏi →
ChatService.sendMessage()gọiApiService.chatWithAI()(api.service.ts:30) - Request body:
{ question, insight_code?, granularity?, filters? } - Response chứa:
mode,explanation,data[],chart_hint?,alerts[] ArtifactRendererComponentdispatch render theo artifact type: chart →ChartRendererComponent, table →DataTableComponent- User có thể rate message hoặc "Pin to Dashboard" để tạo widget
2. Insight Execution Flow
Mô tả chi tiết:
InsightCatalogComponentgọiApiService.listInsights()→ hiện grid (insight-catalog.component.ts)- 12 insights được tổ chức theo series: O (Omisell), B (Boxme), X (Cross) (
mock-insights.ts:1-194) - Search dùng
ApiService.searchInsights(query)→ trảSearchResult[]với score - Click insight → navigate tới
InsightDetailComponent(insight-detail.component.ts) - Detail page hiện: mô tả, when_to_use, outcome, filter form (granularity, date, country)
- Execute gọi
POST /api/v1/insights/{code}/executevớiExecuteRequest - Kết quả render bằng
ChartRendererComponenthoặcDataTableComponent
3. Dashboard Lifecycle
Mô tả chi tiết:
DashboardListComponenthiện tất cả dashboards user có quyền xem (dashboard.service.ts)- Permission check via
PermissionService: Owner/Admin tạo mới, Member chỉ xem shared (permission.service.ts:10-42) - Widget types:
chart,table,kpi— sizes:small,medium,large,full - Data source:
live_insight(gọi API mỗi lần refresh) hoặcsnapshot(dữ liệu tĩnh) - Global filter presets cho phép switch nhanh giữa các bộ filter (daily/weekly/monthly)
- Share: thêm emails vào
shared_with_emails[], setis_shared = true - Schedule: tạo
DashboardSubscriptionvới schedule (daily/weekly/monthly) + channels
4. Subscription & Notification Flow
Mô tả chi tiết:
- Setup Channel: User tạo notification channel (Telegram/Email/Lark) trong Settings (
channel-config-dialog.component.ts)- Telegram: cần
bot_token+chat_id - Email: tự động theo account
- Lark: cần
webhook_url
- Telegram: cần
- Verify: Gọi
POST /channels/:id/test→ backend kiểm tra kết nối - Subscribe: Tạo
InsightSubscriptionvới insight_code, channel_id, schedule, granularity - Delivery: Backend cron chạy theo schedule → execute insight → gửi kết quả → ghi log
- Monitor: User xem
DeliveryLogtrong Settings → filter theo status
5. Authentication Flow
Mô tả chi tiết:
AuthGuard(auth.guard.ts:1-32) kiểm tra authentication trước khi cho truy cập routeAuthService.initializeSession()(auth.service.ts:50-100) thử 4 nguồn token theo thứ tự:- URL query param
?token=xxx(cho iframe embedding) - localStorage key
boxme_insight_token - Cookie
omi_token(parent shell sets) - Demo mode fallback
- URL query param
- Token được decode client-side (base64) → extract
UserInfo(id, email, name, role, tenant_id) - Signals được set:
token,user,isAuthenticated,sellerType,country,role AuthInterceptor(auth.interceptor.ts:1-25) append headerAuthorization: Omi <token>cho mọi request tớiapiBaseUrl
6. Interceptor Pipeline
Mô tả: Pipeline interceptor chạy theo thứ tự đăng ký trong app.config.ts:
demoInterceptor— nếudemoMode=true, trả mock data ngay (không gọi backend)authInterceptor— gắn JWT token vào headererrorInterceptor— xử lý lỗi global (401 → logout, 403 → log, 500 → log)
Source: (src/app/app.config.ts), (src/app/core/interceptors/)
Liên kết
- User Personas — Ai sử dụng các luồng này
- JTBD — Tại sao họ cần các luồng này
- Architecture — Kiến trúc kỹ thuật chi tiết
- API Reference — Chi tiết API endpoints