Skip to content

Kiến trúc

1. Bối cảnh hệ thống (C4 L1)

Helpdesk là một VerifierApplication — nó xác thực JWT với JWKS của identity issuer nhưng không bao giờ phát token. Nó không có cuộc gọi outbound đồng bộ tới các microservice chị em; dữ liệu cross-domain (products, sale orders) được đọc qua repository do @nx/core ship.

2. Góc nhìn Container (C4 L2)

ProcessRUN_MODEChạy
APIstartup (mặc định)Hono server, controllers, EventBus, queue producers
WorkerworkerWorker BullMQ tiêu thụ 6 hàng đợi
MigrationmigrateProcess migration Drizzle một lần

3. Góc nhìn Component (C4 L3) — Phân lớp nội bộ

LớpTrách nhiệm
ControllersCổng merchant-access (assertMerchantAccess() + useRequestContext()), ánh xạ DTO; ủy thác cho use-case. Không có decorator @authenticate
Use-CasesThao tác nghiệp vụ single-responsibility, đăng ký làm service DI; phát event / dispatch job
ListenersĐăng ký sự kiện in-process, fan out tới job BullMQ / side effect
WorkersTiêu thụ hàng đợi BullMQ; chạy use-case cho công việc async (assignment, SLA, escalation, notification, enrichment, survey)
RepositoriesTruy vấn Drizzle; schema tập trung trong @nx/core
ComponentsXuyên suốt: EventBus, Queue, Worker, Mail, WebSocket, Redis cache

4. Chỉ mục Máy trạng thái

Thực thểTrạng tháiSơ đồ
TicketOPEN, ASSIGNED, IN_PROGRESS, WAITING_USER, WAITING_AGENT, WAITING_INTERNAL, PENDING, ASSIGNMENT_FAILED, ESCALATED, RESOLVED, CLOSED, REOPENED→ nhảy
SlaTrackerON_TRACK → WARNING → BREACHED → CRITICAL→ SLA & Escalation

Ticket (XState v5)

Nguồn TicketStatuses: packages/core/src/models/schemas/helpdesk/ticket/schema.ts. 12 trạng thái; chuyển đổi được thực thi bởi UpdateTicketStatusUseCase.

PENDING là trạng thái giữ chỗ được định nghĩa trong TicketStatuses cho công việc chưa được phân loại. Bảng chuyển đổi chi tiết: Ticket System → Vòng đời.

5. Kịch bản Runtime

5.1 Tạo ticket → enrichment + assignment

BướcChi tiết
3Ticket + audit TicketEvent được ghi trong một đơn vị công việc
4Emit in-process — không bao giờ chặn response HTTP
7-8Listener fan out tới BullMQ; worker (worker process) nhận chúng

5.2 Vi phạm SLA → escalation → notification

BướcChi tiết
1Cron được đăng ký bởi QueueComponent.scheduleSlaMonitoring() (WORKER_CONFIG.SLA_MONITOR_INTERVAL)
4-5Ngưỡng cảnh báo từ SLA_WARNING_THRESHOLDS (75 / 90 / 100 / 150)
reassignTái phân công Level-2+ cho senior agent hiện bị tắt trong code (xem Vận hành → Vấn đề đã biết)

5.3 Ticket resolved → trigger survey

6. Mối quan tâm xuyên suốt

Mối quan tâmDịch vụ này xử lý như thế nào
AuthNJWT được xác thực với JWKS của identity (VerifierApplication). Không phát hành
AuthZTruy cập theo merchant qua assertMerchantAccess() + useRequestContext() từ @nx/core; không có decorator @authenticate theo route. PermissionService cho kiểm tra riêng helpdesk
i18nCột jsonb, hình dạng { en, vi } (helper cột i18n()) — ví dụ subject, description ticket, name chính sách SLA
Loggingconsole.log/console.error có tiền tố phạm vi [Component] (không có logger có cấu trúc đấu nối trong worker/listener)
TracingKhông đấu nối
IdempotencyJob BullMQ dùng helper idempotency (worker-idempotency.helper.ts, idempotent-worker-deps.factory.ts); cron SLA dùng jobId: 'sla-monitor-cron' cố định để ngăn trùng lặp
Soft-deletedeletedAt qua generateCommonColumnDefs() tập trung; đọc mặc định loại trừ hàng đã xóa
IDsSnowflake qua IdGenerator, worker node 12
DLQHandleDeadLetterUseCase + dlq.helper.ts cho job thất bại

7. Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.