Skip to content

Data Flow

Quick Reference

  • Pattern: Request-Response (REST)
  • Protocol: HTTPS + JSON
  • State: Angular Signals (reactive)
  • Pipeline: DemoInterceptor → AuthInterceptor → ErrorInterceptor

End-to-End Data Flow

Mô tả: User actions trigger service methods → HttpClient gửi request qua interceptor pipeline → backend xử lý → response quay về qua pipeline → services update signals → UI tự động re-render.

Interceptor Pipeline

Thứ tự đăng ký (trong app.config.ts):

#InterceptorFileChức năng
1demoInterceptordemo.interceptor.tsMock data khi demoMode=true
2authInterceptorauth.interceptor.tsGắn JWT header
3errorInterceptorerror.interceptor.tsXử lý lỗi global

Signal-based State Management

Pattern: Mỗi feature có 1 service quản lý state bằng signals:

ServiceSignalsSource
ChatServicemessages, isLoading, error, hasMessages (computed)chat.service.ts
DashboardServicedashboards, currentDashboard, widgets, isLoading, errordashboard.service.ts
AiConfigServiceconnectors, isLoading, activeConnector (computed), onboardingCompletedai-config.service.ts
AuthServicetoken, user, isAuthenticated, sellerType, country, roleauth.service.ts
ThemeServicetheme ('light' | 'dark')theme.service.ts
HeaderStateServicepageActions, primaryAction, showBackheader-state.service.ts

AI Chat Data Flow

Chi tiết xử lý response:

  1. ChatService.sendMessage() tạo user message, set loading
  2. ApiService.chatWithAI() gọi POST /api/v1/ai/chat
  3. Response (AIChatResponse) chứa:
    • explanation → hiển thị dạng Markdown (ngx-markdown)
    • data[] → build artifact type table
    • chart_hint → build artifact type chart
    • alerts[] → hiển thị warning/info/critical badges
    • sql_used → hiển thị trong collapsible section
  4. Artifacts được dispatch tới ArtifactRendererComponent → render ChartRendererComponent hoặc DataTableComponent
  5. User có thể: Rate (1-5 sao), Pin to Dashboard (tạo widget)

Dashboard Widget Data Flow

Widget data sources:

SourceMô tảKhi nào refresh
live_insightGọi API execute insight mỗi lần refreshManual refresh hoặc scheduled
snapshotDùng snapshot_data cố địnhChỉ khi user update widget

Insight Execution Data Flow

External Integrations

ServiceProtocolDirectionDataSource
insights.omisell.comHTTPS RESTBi-directionalAI chat, insights, dashboardsapi.service.ts
oms.boxme.asialocalStorage/cookieRead-onlyJWT tokenauth.service.ts
Telegram Bot APIHTTPS (via backend)OutboundScheduled reportsBackend cron
Lark WebhookHTTPS (via backend)OutboundScheduled reportsBackend cron
Email SMTPSMTP (via backend)OutboundScheduled reportsBackend cron

Liên kết

Hệ thống tài liệu Boxme AI Insight — Powered by CodyMaster DocKit