Architecture: hbf-data-manager
Component Diagram
Module Structure
| Module | Responsibilities |
|---|---|
AppModule | Root: wires ConfigModule, TypeOrmModule (MySQL), LoggerModule, HealthModule, InteractionsModule, QueueModule |
HealthModule | Health check on GET / and GET /health |
InteractionsModule | InteractionsController, InteractionsDeleteController, InteractionsService, InteractionMetadata entity |
QueueModule | KafkaConsumerService — subscribes to Kafka on startup, calls InteractionsService |
AuthModule | AuthService (JWT verify), JwtModule (DM_AUTH_JWT_SECRET) |
ClientsModule (in auth) | CoreClientService (HTTP to hbf-core), HttpClientService |
Data Flow
Write path (Kafka)
hbf-bot publishes event to Kafka "interaction-metadata" topic
-> KafkajsConsumer receives message
-> KafkaConsumerService.onKafkaMessage parses JSON as InteractionMetadataDto
-> InteractionsService.saveMetadata persists row to MySQL
Read path (REST)
Client sends GET /orgs/:orgId/interactions (Bearer token)
-> HBFGuard calls CoreClientService.getUserMe -> hbf-core /users/me
-> Validates org-level role (or isModerator bypass)
-> InteractionsService.findAll / findByHbfEventId / getLatestVariableRecordsAtEvent
-> Returns DTOs
Delete path (internal)
hbf-data-retention sends DELETE /chat-sessions/:sessionId/interactions (DM JWT)
-> DMJwtGuard.canActivate verifies HS256 JWT (DM_AUTH_JWT_SECRET)
-> InteractionsService.deleteBySessionId / deleteBySessionIds
-> Returns 202 Accepted (async fire-and-forget)
Key Design Notes
- Dual auth pattern: read endpoints use HBFGuard (remote validation via hbf-core); delete endpoints use DMJwtGuard (local JWT, for internal services only).
- Async deletes: delete controllers return 202 immediately and perform DB deletion in background via
Promise.resolve().then(...). - Kafka SASL_SSL:
buildKafkaConnectionConfig()detectsKAFKA_SECURITY_PROTOCOL=SASL_SSLand configures kafkajsssl: true+sasl: plainfor Confluent Cloud. - Variable snapshot:
getLatestVariableRecordsAtEventreconstructs per-key variable state up to a given event timestamp by scanning allVARIABLE-type records in the session and keeping the latest per key. - Body limit: 5MB JSON body parser limit set in
main.tsto handle large conversation payloads.