Skip to content

Outreach Service

@nx/outreach thu thập yêu cầu từ form liên hệ và đăng ký newsletter từ trang marketing công khai. Khi người dùng gửi, service phát một WebSocket event theo thời gian thực tới các phòng quan sát của admin. Đây là service lá, không dùng Kafka và chỉ phụ thuộc nội bộ vào @nx/core.

1. Tham chiếu nhanh

Thuộc tínhGiá trị
Package@nx/outreach
CodeSVC-00110-OUTREACH
LoạiMicroservice
RuntimeBun
Base ClassVerifierApplication
Vị trípackages/outreach
Base Path/v1/api/outreach
Dev Port31110
Container Port3000 (external 31110)
Snowflake ID10
DB Schemaoutreach (2 bảng: Inquiry, Subscriber)
Binding Namespace@nx/outreach
Owneroutreach-team

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

Bao gồmKhông bao gồm
Thu thập yêu cầu liên hệ / bán hàng / demo / đối tácGửi email / SMTP (không có thành phần mail)
Đăng ký / huỷ đăng ký newsletter (idempotent)Phát Kafka event (không có)
Thống kê subscriber cho admin dashboardTự động hoá luồng CRM (thủ công qua trường CRUD)
Thông báo WebSocket theo thời gian thực khi có yêu cầu mớiPhân tách theo merchant đa-tenant (bảng dùng chung toàn cục)

3. Tech Stack

Bên ngoài:

Thư việnMục đích
@venizia/ignisIoC container, DI, BaseService, ControllerFactory, VerifierApplication
@venizia/ignis-helpersWebSocketEmitter, HTTP, env helpers
honoFramework cho HTTP server (qua IGNIS)
@hono/zod-openapiSchema của route → spec OpenAPI
@scalar/hono-api-referenceTrình xem tương tác /doc
drizzle-ormTruy cập DB qua PostgresCoreDataSource
pgPostgreSQL driver

Nội bộ:

PackageMục đích
@nx/coreToàn bộ schema/repository (Inquiry, Subscriber), VerifierApplication, BaseSocketEventService, Redis factory, bộ nạp migration, repository cho permission/role/policy

@nx/core là phụ thuộc nội bộ duy nhất. Không có client tới service nào khác.

4. Cấu trúc Project

packages/outreach/
├── src/
│   ├── application.ts          # Application extends VerifierApplication
│   ├── index.ts                # Entry → bootstrapApplication()
│   ├── migrate.ts              # Migration entry → bootstrapMigration()
│   ├── common/                 # RestPaths, constants, keys
│   ├── components/
│   │   └── websocket/          # ApplicationWebSocketComponent + OutreachSocketEventService
│   ├── controllers/
│   │   ├── inquiry/            # InquiryController (+ /submit)
│   │   ├── subscriber/         # SubscriberController (+ subscribe/unsubscribe/statistics)
│   │   └── permissions.ts      # OutreachPermissions (permission CRUD cho cả hai entity)
│   ├── datasources/            # PostgresCoreDataSource binding
│   ├── errors/                 # SubscriberErrors, WorkerErrors
│   ├── migrations/processes/   # 0001 seed-permissions, 0002 seed-role-permissions
│   ├── repositories/           # SubscriberRepository (custom getStatistics) + re-exports
│   └── services/               # SubscriberService
├── package.json
└── tsconfig.json

5. Architecture

Chi tiết: xem Architecture.

6. Tổng quan Domain

Không có khóa ngoại giữa các entity - cả hai là bảng thu thập độc lập. ERD đầy đủ + bảng theo từng entity: xem Domain Model.

7. Tổng quan giao diện

REST controllers (tham chiếu đầy đủ được render trực tiếp từ /v1/api/outreach/doc/openapi.json):

ControllerBase pathEndpoints
InquiryController/inquiries7 (CRUD + /submit)
SubscriberController/subscribers9 (CRUD + /subscribe, /unsubscribe, /statistics)

Async topics (tham chiếu đầy đủ trong API Events):

HướngSố lượng
Inbound (Kafka)0 (không có)
Outbound (Kafka)0 (không có)
WebSocket out1 (INQUIRY_SUBMITTED)
BullMQ jobs in0
BullMQ jobs out0

8. Components

ComponentFileMục đích
ApplicationWebSocketComponentsrc/components/websocket/component.tsTạo WebSocketEmitter dựa trên Redis (single/cluster), bind nó, đăng ký OutreachSocketEventService

9. Services

ServiceFileMô tả ngắn
SubscriberServicesrc/services/subscriber.service.tsĐăng ký idempotent, huỷ đăng ký theo token, tổng hợp thống kê
OutreachSocketEventServicesrc/components/websocket/socket-event.service.tsPhát INQUIRY_SUBMITTED tới các phòng quan sát (được bind bởi component, không qua configureServices)

10. Repositories

RepositoryBảngNguồnMethod tuỳ chỉnh
InquiryRepositoryoutreach.Inquiry@nx/core (re-export)-
SubscriberRepositoryoutreach.Subscriberkế thừa repo của coregetStatistics() - tổng hợp trong một truy vấn (total / monthlyNew / by-status)

11. Entry Points

FileMục đích
src/index.tsService entry → bootstrapApplication()
src/migrate.tsMigration entry → bootstrapMigration()
src/application.tsLớp Application kế thừa VerifierApplication

12. Configuration

Biến môi trường + feature flag + dữ liệu seed: xem Configuration.

13. Operations

Deployment + observability + security + runbook: xem Operations.

14. Trang liên quan

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