Skip to content

Phân tích Mã nguồn Boxme AI Insight

Quick Reference

  • Dự án: boxme-insight
  • Loại: Web App (Angular Embedded Module)
  • Ngôn ngữ: TypeScript 5.9+
  • Framework: Angular 19+ (Standalone, Signals, TailwindCSS 4)
  • Trạng thái: Production / Active
  • API Integration: 28+ insights từ insights.omisell.com

Kiến trúc Tổng quan

Mô tả: Frontend Angular 19 giao tiếp với backend qua REST API. Backend xử lý AI inference (LLM), truy vấn PostgreSQL, và gửi thông báo qua Telegram/Email/Lark. Frontend nhận token JWT từ parent app (oms.boxme.asia) để xác thực.

Cấu trúc Thư mục

text
src/app/
├── app.ts                        # Root component (bootstrap)
├── app.config.ts                 # Providers, interceptors config
├── app.routes.ts                 # Main routing (lazy-loaded)

├── core/                         # Core singletons
│   ├── auth/
│   │   ├── auth.service.ts      # JWT token management, user signals
│   │   └── auth.guard.ts        # Route protection guard
│   ├── interceptors/
│   │   ├── auth.interceptor.ts  # Append JWT header
│   │   ├── error.interceptor.ts # Global 401/403/500 handling
│   │   └── demo.interceptor.ts  # Mock data for demo mode
│   ├── models/
│   │   └── ai-providers.ts      # Provider/model definitions
│   ├── services/
│   │   ├── api.service.ts       # Central HTTP service (all endpoints)
│   │   ├── theme.service.ts     # Dark/light mode
│   │   ├── ai-config.service.ts # AI connector state
│   │   ├── header-state.service.ts  # Dynamic header state
│   │   └── permission.service.ts    # RBAC checks
│   └── demo/                    # Mock data generators
│       ├── mock-chat-responses.ts
│       ├── mock-insights.ts
│       ├── mock-execute-responses.ts
│       ├── mock-settings.ts
│       ├── mock-dashboard.ts
│       └── delay.utils.ts

├── features/                    # Feature modules (lazy-loaded)
│   ├── chat/
│   │   ├── chat.component.ts
│   │   ├── services/chat.service.ts
│   │   └── components/          # message-list, message-bubble, chat-input,
│   │                            # artifact-renderer, suggested-questions
│   ├── dashboard/
│   │   ├── dashboard.routes.ts
│   │   ├── services/dashboard.service.ts
│   │   └── components/          # dashboard-list, dashboard-view, widget-card,
│   │                            # settings-dialog, schedule-dialog, share-dialog,
│   │                            # filter-preset-bar
│   ├── insights/
│   │   ├── insights.routes.ts
│   │   ├── insight-catalog.component.ts
│   │   └── insight-detail.component.ts
│   └── settings/
│       ├── settings.routes.ts
│       ├── settings.component.ts
│       └── components/          # ai-config-wizard, onboarding-dialog,
│                                # channel-config-dialog

├── layout/                      # App shell
│   ├── main-layout/main-layout.component.ts
│   ├── header/header.component.ts
│   └── sidebar/sidebar.component.ts

└── shared/                      # Reusable components & models
    ├── models/
    │   ├── api.models.ts        # All TypeScript interfaces (365 lines)
    │   └── index.ts
    └── components/
        ├── chart-renderer.component.ts   # ECharts wrapper
        └── data-table.component.ts       # Paginated data table

Phụ thuộc Chính (Dependencies)

CategoryPackageVersionPurpose
Framework@angular/core^21.2.0Frontend framework
UI@angular/material^21.2.6Material Design components
Stylingtailwindcss^4.2.2Utility-first CSS
Chartsecharts + ngx-echarts^6.0.0, ^21.0.0Chart rendering
Markdownngx-markdown + marked^21.2.0, ^17.0.6AI response parsing
Diagramsmermaid^11.14.0Diagram rendering
Iconslucide-angular^1.0.0Icon library
Exportjspdf, xlsx^4.2.1, ^0.18.5PDF/Excel export
Reactiverxjs~7.8.0Observable streams
Testingvitest^4.0.8Unit tests

Route Map

PathComponentAuthLoadingMô tả
/Redirect → /chatYesTrang mặc định
/chatChatComponentYesLazyGiao diện AI Chatbot
/insightsInsightCatalogComponentYesLazyCatalog insight phân tích
/insights/:queryCodeInsightDetailComponentYesLazyChi tiết insight + execute
/dashboardDashboardListComponentYesLazyDanh sách dashboards
/dashboard/:idDashboardViewComponentYesLazyXem/chỉnh sửa dashboard
/settingsSettingsComponentYesLazyCài đặt AI, channels, subscriptions
**Redirect → /chatFallback

Source: (src/app/app.routes.ts:1), (src/app/features/dashboard/dashboard.routes.ts:1), (src/app/features/insights/insights.routes.ts:1)

Data Models Chính

Authentication & User

InterfaceFieldsSource
UserInfoid, email, name, seller_type, country, company_name?, role, tenant_id(api.models.ts:7)
SellerType'boxme_only' | 'omisell_only' | 'boxme_and_omisell'(api.models.ts:1)
OrgRole'owner' | 'admin' | 'member'(api.models.ts:2)

AI Chat

InterfaceKey FieldsSource
AIChatRequestquestion, insight_code?, granularity?, filters?(api.models.ts)
AIChatResponsemode, intent, explanation, data[], chart_hint?, alerts[], execution_status(api.models.ts)
ChatMessageid, role, content, timestamp, artifacts?, mode?, rating?(api.models.ts)
Artifacttype (chart | table | kpi), data[], chartHint?, title?(api.models.ts)

Insights

InterfaceKey FieldsSource
InsightReadquery_code, name, description, category, seller_type, granularities[], filter_config[], chart_hint?, tags?(api.models.ts)
ExecuteRequestgranularity, end_date?, country?, sort_by?, filters?, limit?(api.models.ts)
ExecuteResponsedata[], chart_hint?, alerts[], total_rows, execution_time_ms(api.models.ts)

Dashboards

InterfaceKey FieldsSource
Dashboardid, name, description?, is_shared, shared_with_emails?, widget_ids[], global_filter_presets[](api.models.ts)
DashboardWidgetid, title, widget_type, display_size, data_source, insight_code?, snapshot_data?(api.models.ts)
DashboardSubscriptionid, dashboard_id, channel_ids[], schedule, schedule_time, is_active(api.models.ts)

Visualization

InterfaceKey FieldsSource
ChartHintchart_type, x_column, y_columns[], title(api.models.ts)
ChartTypebar | line | pie | stacked_bar | grouped_bar | area | heatmap(api.models.ts)
DataRowRecord<string, unknown>(api.models.ts)

Notifications & Subscriptions

InterfaceKey FieldsSource
NotificationChannelid, channel_type, config, is_verified(api.models.ts)
InsightSubscriptionid, insight_code, channel_id, schedule, granularity, is_active(api.models.ts)
DeliveryLogid, subscription_id, insight_name, channel_type, status, error_message?(api.models.ts)

AI Connectors

InterfaceKey FieldsSource
AIConnectorprovider, api_key_masked, is_active, model?, model_label?(api.models.ts)
AIConnectorCreateRequestprovider, api_key, model?(api.models.ts)
AIConnectorTestResponsesuccess, message, latency_ms?(api.models.ts)

Luồng Hoạt động Dữ liệu

Mô tả: Ứng dụng dùng Angular Signals (không dùng NgRx) để quản lý state. Tất cả component giao tiếp qua HttpClient với pipeline interceptors: demoInterceptorauthInterceptorerrorInterceptor. Response JSON chứa data[], chart_hint, alerts[] được parse bởi chart-rendererdata-table.

Key Files

FileVai tròDòng
src/app/core/services/api.service.tsCentral HTTP service — tất cả API calls274
src/app/shared/models/api.models.tsTất cả TypeScript interfaces365
src/app/core/auth/auth.service.tsJWT token management, user signals158
src/app/core/interceptors/demo.interceptor.tsDemo mode mock data256
src/app/core/models/ai-providers.tsAI provider/model definitions222
src/app/features/chat/services/chat.service.tsChat message state~100
src/app/features/dashboard/services/dashboard.service.tsDashboard state~150
src/app/core/services/permission.service.tsRBAC permission checks42
src/app/shared/components/chart-renderer.component.tsECharts wrapper~200
src/styles.cssTailwind theme + brand colors~150

Test Coverage

FrameworkThư mục TestGhi chú
Vitestsrc/**/*.spec.tsUnit tests cho components & services

Liên kết

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