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