Appearance
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):
| # | Interceptor | File | Chức năng |
|---|---|---|---|
| 1 | demoInterceptor | demo.interceptor.ts | Mock data khi demoMode=true |
| 2 | authInterceptor | auth.interceptor.ts | Gắn JWT header |
| 3 | errorInterceptor | error.interceptor.ts | Xử lý lỗi global |
Signal-based State Management
Pattern: Mỗi feature có 1 service quản lý state bằng signals:
| Service | Signals | Source |
|---|---|---|
ChatService | messages, isLoading, error, hasMessages (computed) | chat.service.ts |
DashboardService | dashboards, currentDashboard, widgets, isLoading, error | dashboard.service.ts |
AiConfigService | connectors, isLoading, activeConnector (computed), onboardingCompleted | ai-config.service.ts |
AuthService | token, user, isAuthenticated, sellerType, country, role | auth.service.ts |
ThemeService | theme ('light' | 'dark') | theme.service.ts |
HeaderStateService | pageActions, primaryAction, showBack | header-state.service.ts |
AI Chat Data Flow
Chi tiết xử lý response:
ChatService.sendMessage()tạo user message, set loadingApiService.chatWithAI()gọiPOST /api/v1/ai/chat- Response (
AIChatResponse) chứa:explanation→ hiển thị dạng Markdown (ngx-markdown)data[]→ build artifact typetablechart_hint→ build artifact typechartalerts[]→ hiển thị warning/info/critical badgessql_used→ hiển thị trong collapsible section
- Artifacts được dispatch tới
ArtifactRendererComponent→ renderChartRendererComponenthoặcDataTableComponent - User có thể: Rate (1-5 sao), Pin to Dashboard (tạo widget)
Dashboard Widget Data Flow
Widget data sources:
| Source | Mô tả | Khi nào refresh |
|---|---|---|
live_insight | Gọi API execute insight mỗi lần refresh | Manual refresh hoặc scheduled |
snapshot | Dùng snapshot_data cố định | Chỉ khi user update widget |
Insight Execution Data Flow
External Integrations
| Service | Protocol | Direction | Data | Source |
|---|---|---|---|---|
insights.omisell.com | HTTPS REST | Bi-directional | AI chat, insights, dashboards | api.service.ts |
oms.boxme.asia | localStorage/cookie | Read-only | JWT token | auth.service.ts |
| Telegram Bot API | HTTPS (via backend) | Outbound | Scheduled reports | Backend cron |
| Lark Webhook | HTTPS (via backend) | Outbound | Scheduled reports | Backend cron |
| Email SMTP | SMTP (via backend) | Outbound | Scheduled reports | Backend cron |
Liên kết
- Architecture — Kiến trúc tổng quan
- Process Flows — Luồng quy trình nghiệp vụ
- API Reference — Chi tiết API endpoints
- Phân tích Mã nguồn — Code analysis