Chat App
π Overview
This comprehensive implementation guideline provides a complete chat application using Flexbase architecture patterns, following Single Responsibility Principle (SRP) and integrating seamlessly with your existing EBusiness project structure.
ποΈ Project Structure
Chat Module Organization
EBusiness.Application/
βββ Domain/
β βββ EBusiness.DomainModels/
β βββ Chat/
β βββ Chat.cs
β βββ Chat_SeedData.cs
β βββ Message.cs
β βββ Message_SeedData.cs
β βββ ChatParticipant.cs
β βββ ChatParticipant_SeedData.cs
β βββ MessageReaction.cs
β βββ MessageAttachment.cs
β βββ ChatSettings.cs
βββ DomainHandler/
β βββ EBusiness.Handlers/
β βββ CommandHandlers/
β β βββ Chat/
β β β βββ CreateChatHandler.cs
β β β βββ SendMessageHandler.cs
β β β βββ AddParticipantHandler.cs
β β β βββ RemoveParticipantHandler.cs
β β β βββ UpdateChatSettingsHandler.cs
β β β βββ ArchiveChatHandler.cs
β β β βββ DeleteChatHandler.cs
β β β βββ CreateGroupChatHandler.cs
β β β βββ InviteToGroupChatHandler.cs
β β β βββ LeaveGroupChatHandler.cs
β β β βββ UpdateGroupChatInfoHandler.cs
β β β βββ PromoteToAdminHandler.cs
β β βββ Message/
β β β βββ UpdateMessageStatusHandler.cs
β β β βββ AddMessageReactionHandler.cs
β β β βββ RemoveMessageReactionHandler.cs
β β β βββ DeleteMessageHandler.cs
β β β βββ EditMessageHandler.cs
β β βββ Media/
β β β βββ UploadMediaHandler.cs
β β β βββ DeleteMediaHandler.cs
β β β βββ GenerateThumbnailHandler.cs
β β β βββ ProcessImageHandler.cs
β β β βββ ProcessVideoHandler.cs
β β β βββ ProcessAudioHandler.cs
β β β βββ ProcessFileHandler.cs
β β β βββ GenerateLinkPreviewHandler.cs
β β β βββ CompressMediaHandler.cs
β β βββ RealTime/
β β βββ JoinChatHandler.cs
β β βββ LeaveChatHandler.cs
β β βββ UpdateTypingStatusHandler.cs
β β βββ UpdateUserOnlineStatusHandler.cs
β βββ Subscribers/
β βββ Chat/
β β βββ NotifyParticipantsOnChatCreated.cs
β β βββ NotifyParticipantsOnMessageSent.cs
β β βββ NotifyParticipantsOnParticipantAdded.cs
β β βββ NotifyParticipantsOnParticipantRemoved.cs
β β βββ UpdateChatLastMessageOnMessageSent.cs
β β βββ UpdateChatStatisticsOnMessageSent.cs
β β βββ NotifyMentionedUsersOnMessageSent.cs
β β βββ NotifyGroupChatCreated.cs
β β βββ NotifyGroupChatInvitation.cs
β β βββ NotifyGroupChatLeft.cs
β βββ Message/
β β βββ SendPushNotificationOnMessageSent.cs
β β βββ UpdateMessageDeliveryStatus.cs
β β βββ UpdateMessageReadStatus.cs
β β βββ ProcessMessageAnalytics.cs
β β βββ ArchiveOldMessages.cs
β βββ Media/
β β βββ ProcessMediaUpload.cs
β β βββ GenerateMediaThumbnail.cs
β β βββ CleanupUnusedMedia.cs
β β βββ ProcessImageUpload.cs
β β βββ ProcessVideoUpload.cs
β β βββ ProcessAudioUpload.cs
β β βββ ProcessFileUpload.cs
β β βββ GenerateLinkPreview.cs
β β βββ CompressMediaFiles.cs
β β βββ ScanMediaForViruses.cs
β βββ RealTime/
β βββ UpdateUserOnlineStatus.cs
β βββ BroadcastTypingStatus.cs
β βββ UpdateChatPresence.cs
β βββ ProcessRealTimeEvents.cs
βββ ControlContracts/
β βββ EBusiness.DTOs/
β βββ DomainDtos/
β β βββ Chat/
β β β βββ ChatDto.cs
β β β βββ ChatDtoDtoWithId.cs
β β βββ Message/
β β β βββ MessageDto.cs
β β β βββ MessageDtoDtoWithId.cs
β β βββ ChatParticipant/
β β β βββ ChatParticipantDto.cs
β β β βββ ChatParticipantDtoDtoWithId.cs
β β βββ MessageReaction/
β β βββ MessageReactionDto.cs
β β βββ MessageReactionDtoDtoWithId.cs
β βββ FeatureDtos/
β βββ Chat/
β β βββ Input/
β β β βββ CreateChat/
β β β β βββ CreateChatDto.cs
β β β βββ SendMessage/
β β β β βββ SendMessageDto.cs
β β β βββ AddParticipant/
β β β β βββ AddParticipantDto.cs
β β β βββ UpdateChatSettings/
β β β βββ UpdateChatSettingsDto.cs
β β βββ Output/
β β βββ GetChatMessages/
β β β βββ GetChatMessagesDto.cs
β β βββ GetUserChats/
β β β βββ GetUserChatsDto.cs
β β βββ GetChatParticipants/
β β βββ GetChatParticipantsDto.cs
β βββ Message/
β βββ Input/
β β βββ UpdateMessageStatus/
β β β βββ UpdateMessageStatusDto.cs
β β βββ AddMessageReaction/
β β β βββ AddMessageReactionDto.cs
β β βββ EditMessage/
β β βββ EditMessageDto.cs
β βββ Output/
β βββ GetMessageHistory/
β βββ GetMessageHistoryDto.cs
βββ Infrastructure/
βββ EventHandlers/
βββ IHybridEventService.cs
βββ HybridEventService.cs
βββ RedisStreamProcessor.cs
βββ ChatSignalRHub.cs
EBusiness.Framework/
βββ EventHandlers/
βββ ChatEventHandlers/
β βββ ChatCreatedEventHandler.cs
β βββ MessageSentEventHandler.cs
β βββ UserOnlineEventHandler.cs
β βββ TypingStatusChangedEventHandler.cs
βββ BackgroundProcessors/
βββ MessageArchivalProcessor.cs
βββ MediaCleanupProcessor.cs
βββ AnalyticsProcessor.csπ― Domain Models Implementation
1. Chat Domain Model
2. Message Domain Model
π― Command Handlers Implementation
1. Chat Command Handlers
CreateChatHandler (SRP: Chat Creation)
SendMessageHandler (SRP: Message Sending)
2. Group Chat Command Handlers
CreateGroupChatHandler (SRP: Group Chat Creation)
InviteToGroupChatHandler (SRP: Group Chat Invitations)
3. Media Command Handlers
UploadMediaHandler (SRP: Media Upload)
GenerateLinkPreviewHandler (SRP: Link Preview Generation)
4. Message Command Handlers
UpdateMessageStatusHandler (SRP: Status Updates)
π‘ Event Subscribers Implementation
1. Chat Event Subscribers
NotifyParticipantsOnChatCreated (SRP: Participant Notifications)
UpdateChatLastMessageOnMessageSent (SRP: Chat Metadata Updates)
2. @ Mentions Event Subscribers
NotifyMentionedUsersOnMessageSent (SRP: @ Mentions Notifications)
3. Message Event Subscribers
SendPushNotificationOnMessageSent (SRP: Push Notifications)
ProcessMessageAnalytics (SRP: Analytics Processing)
π§ Infrastructure Implementation
1. Hybrid Event Service
2. Chat SignalR Hub
π― DTOs Implementation
1. Domain DTOs
2. Feature DTOs
2. Group Chat Feature DTOs
3. Media Feature DTOs
User types @john in group chat β SendMessageHandler processes message β ProcessMentions() extracts @john β FindUserByMention() resolves to user ID β Message metadata includes mentions β NotifyMentionedUsersOnMessageSent β SendMentionNotificationAsync() to @john β PublishMentionNotificationAsync() for real-time UI
User uploads image/video/file β UploadMediaHandler validates file β MediaStorageService uploads to storage β Message created with media attachment β ProcessHyperlinks() for any URLs in caption β PublishRealtimeMessageAsync() for immediate display β PublishMessageEventAsync() for reliable processing β ProcessMediaUpload subscriber generates thumbnails β CompressMediaFiles subscriber optimizes file size
User sends message with URL β SendMessageHandler processes message β ProcessHyperlinks() extracts URLs β GenerateLinkPreviewHandler triggered β LinkPreviewService generates preview β Message metadata updated with preview β PublishLinkPreviewGeneratedAsync() for real-time UI
Last updated