For the complete documentation index, see llms.txt. This page is also available as Markdown.

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)

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