Architecture: hbf-core
C4 Component Diagram
Domain Model Summary
From the README class diagram:
Organization(1) ownsTenant(1..),User(1..),AuditLog(0..),ApiToken(0..),NLUAgent(0..*).TenantownsSubscriber(0..),ChatSession(0..),Broadcast(0..),Group(0..),Survey(0..*).Tenanthas exactly oneBotContentand oneBotContentCompiled.Tenantlinks toBotDeployment(1..*) for each channel (Facebook, WhatsApp, Webchat, etc.).BotContentcontainsActivity(1..);BotContentCompiledcontainsActivityCompiled(1..), each withConversationNode(1..*).BroadcasttargetsGroup(1..);GroupcontainsSubscriber(1..).
Key Flows
JWT Authentication
- Client sends
POST /loginwith credentials; request is handled byAuthenticationResourcewhich delegates toAuthenticationService. AuthenticationServicevalidates credentials againstUserRepository, issues a JWT signed with the configured HS256 secret.- On every subsequent request,
TokenAuthenticationFilterextracts the Bearer token, validates it viaTokenManager, and populatesSecurityContextwith the user principal. - Method-level
@PreAuthorizeannotations check roles (MODERATOR, ADMIN, etc.) viaSecurityService.
Bot Content Compilation
- User edits bot content (flows/FAQs/activities) via
BotContentResource; changes persist raw to MongoDB viaBotContentRepository. - A save event triggers
BotContentListenerto mark the tenant as needing recompilation. TenantRecompilationService(scheduled, throttled at 10 tenants/min) picks up tenants flagged for recompilation.- Compilation produces
BotContentCompiledwith expandedActivityCompilednodes; stored toBotContentCompiledRepository. - Other services (hbf-bot) read
BotContentCompiledto serve conversations.
NLU Training
TenantResource.trainNlu()orBotContentRecompilationResourcetriggers NLU training.NLPPipelineServicecreates/updates NLU agents on the configured provider (LUIS or Dialogflow).- Service polls agent status (up to
nlu.train.max_check_ready_attemptsattempts,nlu.train.repeat_rate_millisdelay via@Retryable). - On completion, tenant
nluSyncflag is updated; Redis cache for NLU detections is invalidated.
Cascade Delete (Organization)
DELETE /organizations/{id}callsOrganizationService.delete().OrganizationServicedeletes all org tenants first (each triggersTenantCascadeListener).TenantCascadeListenerdeletes subscribers, chat sessions, broadcasts, groups, surveys, deployments, content for that tenant.OrganizationCascadeListenerthen removes org-level audit logs, API tokens, users from the org.