converse_chat_core 1.0.1
converse_chat_core: ^1.0.1 copied to clipboard
Core logic and data models for the Converse Chat SDK.
π£οΈ Converse Chat Core #
Converse Chat Core provides the domain layer, entities, and clean architecture foundation for the Converse Chat SDK.
It is platform-agnostic and can be extended or integrated with any backend (Firebase, Supabase, custom servers, etc.).
π Overview #
Converse Chat Core defines the fundamental data models, use cases, and plugin architecture that power all other Converse packages:
App / SDK
β
Converse Chat SDK
β
Converse Chat Core
β
Adapters (Firebase, REST, etc.)
It provides:
- π§± Entities & Value Objects β
User,Message,Chat,Attachment - βοΈ Use Cases β
SendMessage,FetchMessages,MarkRead - π Plugin System β Extend chat behavior dynamically
- π§© Repository Interfaces β For persistence & network integration
- π Error Handling β Custom error and failure hierarchy
π§ Architecture #
This package follows Clean Architecture principles:
+------------------------+
| Presentation Layer | β (UI / SDK / Flutter widgets)
+------------------------+
| Domain Layer | β converse_chat_core
| (Entities, UseCases) |
+------------------------+
| Data Layer / Adapters | β (Firebase, REST, etc.)
+------------------------+
You can think of converse_chat_core as the heart of your chat system β
independent of any backend, UI, or storage mechanism.
π§© Key Features #
β
Pure Dart β works with any backend
β
Extendable plugin system
β
Typed entities with strong immutability
β
Error-safe functional approach using fpdart
β
Lightweight and testable
π§° Installation #
Add to your pubspec.yaml:
dependencies:
converse_chat_core: ^1.0.0
Then import it:
import 'package:converse_chat_core/converse_chat_core.dart';
π¬ Example Usage #
import 'package:converse_chat_core/converse_chat_core.dart';
void main() {
final user = User(id: UserId('alice'), name: 'Alice');
final chat = Chat(id: ChatId('chat_1'), participants: [user]);
final message = Message.create(
id: MessageId.unique(),
userId: user.id,
text: 'Hey, this is a test!',
);
print('Message from ${user.name}: ${message.text}');
}
β
Works fully offline
β
Easily extendable for Firebase or custom backends
βοΈ Extending with Plugins #
You can register plugins to modify message flow dynamically.
final registry = PluginRegistry();
registry.register(MyEncryptionPlugin());
final processed = await registry.runOnSend(message);
See plugin_registry.dart for details.
π§± Folder Structure #
lib/
ββ converse_chat_core.dart # β
Public entrypoint (exports everything below)
ββ src/
ββ domain/
β ββ entities/
β β ββ message.dart # Defines Message entity (id, text, senderId, timestamp, status)
β β ββ chat.dart # Defines Chat entity (id, participants, metadata)
β β ββ user.dart # Defines User entity (id, name, avatar, presence)
β β ββ attachment.dart # Defines Attachment entity (type, url, mime)
β β ββ message_status.dart # Enum for sent, delivered, read, failed
β β
β ββ value_objects/
β ββ user_id.dart # Value object for unique user identifiers
β ββ message_id.dart # Value object for message IDs
β ββ chat_id.dart # Value object for chat IDs
β ββ timestamp.dart # Immutable value object for time metadata
β
ββ usecases/
β ββ send_message.dart # Handles message send logic
β ββ fetch_messages.dart # Retrieves chat history
β ββ mark_read.dart # Marks message as read
β
ββ ports/
β ββ i_chat_repository.dart # Abstract repository for chat operations
β ββ i_user_repository.dart # Abstract user repository
β ββ i_attachment_repository.dart # For media uploads/downloads
β ββ i_presence_repository.dart # For tracking online/offline state
β
ββ services/
β ββ message_pipeline.dart # Message preprocessing & plugin chain
β ββ encryption_strategy.dart # Defines encrypt/decrypt strategy interface
β ββ ... # (Future) notification or caching services
β
ββ plugins/
β ββ chat_plugin.dart # Abstract class for plugins (onSend/onReceive)
β ββ plugin_registry.dart # Registers and runs plugins sequentially
β
ββ controller/
β ββ chat_controller.dart # Coordinates between use cases and SDK layer
β
ββ errors/
ββ core_errors.dart # Common exceptions (e.g., NetworkError, InvalidEntity)
ββ chat_failure.dart # Failure models for domain layer (used with fpdart Either)
ββ error_mapper.dart # Maps exceptions into Failures or Error types
π§ͺ Example Project #
A minimal runnable example is available in the example/ directory:
dart run example/main.dart
π¦ Related Packages #
| Package | Description |
|---|---|
converse_chat_sdk |
High-level SDK with Firebase and adapters |
converse_chat_adapters |
Infrastructure integrations (Firebase, REST, etc.) |
π§ Topics #
firebase chat, chat, messaging, sdk, firebase, realtime, flutter, core, clean-architecture
πͺͺ License #
This project is licensed under the MIT License.
π¨βπ» Author #
Rajendra Bisht
GitHub @rbishtdev
