Skip to content

Helpdesk Service

@nx/helpdesk là microservice hỗ trợ khách hàng cho nền tảng BANA. Nó sở hữu vòng đời ticket, theo dõi SLA và auto-escalation, phân công agent dựa trên rule, một knowledge base, khảo sát hài lòng, và thông báo đa kênh theo template. Đây là một VerifierApplication chỉ phụ thuộc vào @nx/core và xử lý công việc nền qua các worker BullMQ và một event bus in-process.

1. Tham khảo nhanh

Thuộc tínhGiá trị
Package@nx/helpdesk
CodeSVC-00120-HELPDESK
TypeMicroservice
RuntimeBun
Base ClassVerifierApplication
Locationpackages/helpdesk
Base Path/v1/api/helpdesk
Dev Port31130
Container Port3000 (external 31130)
Snowflake ID12
DB Schemahelpdesk (30 bảng)
Rolesapi, worker (RUN_MODE=worker)
Binding Namespace@nx/helpdesk
Ownersupport-team

Nguồn sự thật về định danh: src/resources/app-info.json (trả về bởi getAppInfo()). Các giá trị trên đến từ đó. .env.development nay đã mang APP_ENV_APPLICATION_CODE=SVC-00120-HELPDESK khớp với app-info (va chạm SVC-00030-HELPDESK với sale đã được giải quyết). Drift còn lại cần đối chiếu: APP_ENV_SERVER_PORT=31032APP_ENV_SNOWFLAKE_WORKER_ID=0. Xem Cấu hình.

Vấn đề đã biết: build TypeScript của package này hiện đang fail (đường tham chiếu assignTicketUseCase chết). Xem Vận hành → Vấn đề đã biết.

2. Mục đích & Phạm vi

Bao gồmLoại trừ
Quản lý ticket (vòng đời, message, attachment, event)Phát JWT / identity (xử lý bởi @nx/identity)
Theo dõi SLA, cảnh báo, vi phạm, auto-escalationXử lý order/payment (context chỉ-đọc từ @nx/core)
Tự phân công dựa trên rule (agents, agent groups)Logic inventory và pricing
Knowledge base (articles, categories, views, feedback)Event bus cross-service (không đấu nối Kafka; chỉ in-process)
Khảo sát hài lòng + vote feature-request
Thông báo theo template, gom batch (email + WebSocket)

3. Tech Stack

Bên ngoài:

Thư việnMục đích
@venizia/ignisIoC container, DI, base application/controller/service, components
@venizia/ignis-helpersRedis helper, TConstValue, TNullable, tiện ích dùng chung
honoFramework HTTP server (qua IGNIS)
drizzle-ormTruy cập DB qua PostgresCoreDataSource
pgDriver PostgreSQL
bullmqHàng đợi job nền + workers
ioredisClient Redis (kết nối cache + BullMQ)
eventemitter3Event bus in-process
xstateMáy trạng thái ticket-status
nodemailerGửi email
slugifySinh slug article/category
zodXác thực schema request/response
lodashTiện ích

@platformatic/kafka được khai báo trong package.json nhưng chết — không có Kafka producer/consumer trong src/. Xem API Events.

Nội bộ:

PackageMục đích
@nx/corePhụ thuộc @nx/* duy nhất. Cung cấp VerifierApplication, PostgresCoreDataSource, createAppConfig, bootstrapApplication, schema/model Drizzle tập trung, ProductRepository + SaleOrderRepository (cho enrichment context), assertMerchantAccess, useRequestContext, ActorTypes, builder WebSocket/topic, enum ticket (TicketStatuses, TicketEventTypes, TicketPriorities).

4. Cấu trúc dự án

packages/helpdesk/
├── src/
│   ├── application.ts            # HelpdeskApplication (VerifierApplication)
│   ├── index.ts                  # Điểm vào → bootstrapApplication()
│   ├── migrate.ts                # Điểm vào migration → bootstrapMigration()
│   ├── application/
│   │   ├── use-cases/            # Business logic (service đăng ký DI)
│   │   ├── services/             # Service thuần (notification, compensation, …)
│   │   ├── events/               # Emitter + listener in-process
│   │   └── validators/           # AgentValidator
│   ├── components/
│   │   ├── event-bus/            # EventBusComponent (eventemitter3)
│   │   ├── queue.component.ts    # Hàng đợi BullMQ + scheduler cron SLA
│   │   ├── workers/              # 6 worker BullMQ
│   │   ├── mail/                 # NodemailerComponent
│   │   └── websocket/            # ApplicationWebSocketComponent
│   ├── controllers/              # 11 REST controller
│   ├── datasources/              # Binding PostgresCoreDataSource
│   ├── models/requests/          # Zod request schemas
│   ├── repositories/             # Lớp repository (schema nằm trong @nx/core)
│   ├── migrations/processes/     # Migration processes
│   ├── resources/                # app-info.json + email templates
│   └── shared/                   # common (keys, paths, constants), helpers, utils
├── package.json
└── tsconfig.json

5. Kiến trúc

Chi tiết: xem Kiến trúc.

6. Ảnh chụp Domain

ERD đầy đủ + bảng theo từng thực thể: xem Domain Model.

7. Tóm tắt Bề mặt

REST controllers (tham khảo đầy đủ render trực tiếp từ /v1/api/helpdesk/doc/openapi.json):

ControllerBase path (RestPaths)Ghi chú
TicketController/ticketsVòng đời ticket đầy đủ, message, phân công
AgentController/agentsQuản lý support agent
AgentGroupController/agent-groupsAgent group + thành viên
TicketCategoryController/ticket-categoriesCategory ticket
TicketTagController/ticket-tagsTag + ánh xạ ticket-tag
SlaController/sla-policiesChính sách SLA
ArticleController(articles)Article knowledge base
ArticleCategoryController(article categories)Category article
AssignmentRuleController/assignment-rulesRule tự phân công
FeatureRequestController(feature requests)Feature request + vote
SurveyController(surveys)Khảo sát hài lòng

Live spec: /v1/api/helpdesk/doc/openapi.json. Bảng REST cố ý không duy trì thủ công.

Bề mặt async (tham khảo đầy đủ trong API Events):

KênhSố lượng
Kafka in/out0 (dep chết)
Sự kiện in-process (EventBus)ticket created / status-changed / assigned / message-created
Hàng đợi BullMQ6 (SLA monitor, escalation, assignment, notification, context-enrichment, survey-trigger)
Phát WebSockettopic observation helpdesk

8. Components

ComponentFileMục đích
Cache RedisuseCacheRedis()BindingKeys.APPLICATION_REDIS_CACHERedis cho cache + kết nối BullMQ
QueueComponentsrc/components/queue.component.tsTạo 6 hàng đợi BullMQ; lên lịch cron SLA-monitor
EventBusComponentsrc/components/event-bus/component.tsBus eventemitter3 in-process + registry handler
NodemailerComponentsrc/components/mail/component.tsGửi email SMTP
WorkerComponentsrc/components/workers/worker.component.tsĐăng ký và chạy 6 worker BullMQ
ApplicationWebSocketComponentsrc/components/websocket/component.tsGửi WebSocket thời gian thực

9. Services

Business logic nằm trong use-cases (src/application/use-cases/*, đăng ký làm service DI). Các service thuần dưới đây cung cấp helper xuyên suốt dùng chung.

ServiceFileMô tả một dòng
FileStorageHelpersrc/shared/helpers/file-storage.helper.tsHelper lưu trữ attachment
PermissionServicesrc/application/services/permission.service.tsKiểm tra quyền helpdesk
CompensationCalculatorServicesrc/application/services/compensation-calculator.service.tsMa trận đền bù vi phạm SLA
EscalationJobManagerServicesrc/application/services/escalation-job-manager.service.tsLên lịch/quản lý job escalation
ProcessNotificationServicesrc/application/services/notification/process-notification.service.tsPhân giải + gửi thông báo
NotificationBatchServicesrc/application/services/notification/notification-batch.service.tsGom batch/digest thông báo
AgentValidatorsrc/application/validators/agent.validator.tsXác thực input agent

Use-case được nhóm theo domain: Agent, Agent Group, Assignment, Assignment Rule, Article, Article Category, Feature Request, SLA, SLA Policy, Survey, Survey Question, Ticket, Ticket Category, Ticket Tag, cộng HandleDeadLetterUseCase. Xem src/application.ts configureServices() cho tập đã đăng ký.

10. Repositories

Tất cả schema/model Drizzle được tập trung trong @nx/core (packages/core/src/models/schemas/helpdesk/). Package này chỉ khai báo lớp repository.

NhómRepositories
TicketTicketRepository, TicketMessageRepository, TicketEventRepository, TicketAssignmentRepository, TicketCategoryRepository, TicketTagRepository, TicketTagMappingRepository
AgentAgentRepository, AgentGroupRepository, AgentGroupMemberRepository
SLASlaPolicyRepository, SlaTrackerRepository, SlaEscalationRepository
Knowledge baseArticleRepository, ArticleCategoryRepository, ArticleViewRepository, ArticleFeedbackRepository
Survey & featureSurveyRepository, SurveyQuestionRepository, SurveyResponseRepository, FeatureRequestRepository, FeatureVoteRepository
NotificationNotificationRepository, NotificationTemplateRepository, NotificationPreferenceRepository, NotificationDeliveryLogRepository, NotificationBatchRepository
KhácAssignmentRuleRepository, CompensationRepository, MetaLinkRepository, JobExecutionLogRepository, UserRepository, OrganizerRepository
Từ @nx/coreProductRepository, SaleOrderRepository (enrichment context chỉ-đọc)

11. Điểm vào

FileMục đích
src/index.tsĐiểm vào dịch vụ → bootstrapApplication({ ApplicationClass: HelpdeskApplication })
src/migrate.tsĐiểm vào migration → bootstrapMigration()
src/application.tsHelpdeskApplication kế thừa VerifierApplication

Chế độ chạy được chọn qua RUN_MODE (startup API / worker / migrate).

12. Cấu hình

Biến env + feature flag + dữ liệu seed: xem Cấu hình.

13. Vận hành

Triển khai + observability + bảo mật + runbook + vấn đề đã biết: xem Vận hành.

14. Trang liên quan

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