Service Design Specification
tutorhub-messaging-service documentation
Version: 1.0.15
Scope
This document provides a structured architectural overview of the messaging microservice, detailing its configuration, data model, authorization logic, business rules, and API design. It has been automatically generated based on the service definition within Mindbricks, ensuring that the information reflects the source of truth used during code generation and deployment.
The document is intended to serve multiple audiences:
- Service architects can use it to validate design decisions and ensure alignment with broader architectural goals.
- Developers and maintainers will find it useful for understanding the structure and behavior of the service, facilitating easier debugging, feature extension, and integration with other systems.
- Stakeholders and reviewers can use it to gain a clear understanding of the service’s capabilities and domain logic.
Note for Frontend Developers: While this document is valuable for understanding business logic and data interactions, please refer to the Service API Documentation for endpoint-level specifications and integration details.
Note for Backend Developers: Since the code for this service is automatically generated by Mindbricks, you typically won’t need to implement or modify it manually. However, this document is especially valuable when you’re building other services—whether within Mindbricks or externally—that need to interact with or depend on this service. It provides a clear reference to the service’s data contracts, business rules, and API structure, helping ensure compatibility and correct integration.
Messaging Service Settings
Real-time messaging service: student-tutor chat (bidirectional), admin-student warnings (one-way), admin-tutor communication (bidirectional). Uses RealtimeHub for WebSocket chat with persistence, typing, and read receipts.
Service Overview
This service is configured to listen for HTTP requests on port 3000,
serving both the main API interface and default administrative endpoints.
The following routes are available by default:
- API Test Interface (API Face):
/ - Swagger Documentation:
/swagger - Postman Collection Download:
/getPostmanCollection - Health Checks:
/healthand/admin/health - Current Session Info:
/currentuser - Favicon:
/favicon.ico
The service uses a PostgreSQL database for data storage, with the database name set to tutorhub-messaging-service.
This service is accessible via the following environment-specific URLs:
- Preview:
https://tutorhub.prw.mindbricks.com/messaging-api - Staging:
https://tutorhub-stage.mindbricks.co/messaging-api - Production:
https://tutorhub.mindbricks.co/messaging-api
Authentication & Security
- Login Required: Yes
This service requires user authentication for access. It supports both JWT and RSA-based authentication mechanisms, ensuring secure user sessions and data integrity. If a crud route also is configured to require login, it will check a valid JWT token in the request query/header/bearer/cookie. If the token is valid, it will extract the user information from the token and make the fetched session data available in the request context.
Service Data Objects
The service uses a PostgreSQL database for data storage, with the database name set to tutorhub-messaging-service.
Data deletion is managed using a soft delete strategy. Instead of removing records from the database, they are flagged as inactive by setting the isActive field to false.
| Object Name | Description | Public Access |
|---|---|---|
conversation |
Represents a chat channel between two participants. Types: studentTutor (bidirectional enrolled chat), adminStudent (one-way admin warnings), adminTutor (bidirectional admin-tutor communication). | accessPrivate |
chatMessage |
Auto-generated message DataObject for the chat RealtimeHub. Stores all messages with typed content payloads. | accessPrivate |
chatModeration |
Auto-generated moderation DataObject for the chat RealtimeHub. Stores block and silence actions for room-level user moderation. | accessPrivate |
conversation Data Object
Object Overview
Description: Represents a chat channel between two participants. Types: studentTutor (bidirectional enrolled chat), adminStudent (one-way admin warnings), adminTutor (bidirectional admin-tutor communication).
This object represents a core data structure within the service and acts as the blueprint for database interaction, API generation, and business logic enforcement.
It is defined using the ObjectSettings pattern, which governs its behavior, access control, caching strategy, and integration points with other systems such as Stripe and Redis.
Core Configuration
- Soft Delete: Enabled — Determines whether records are marked inactive (
isActive = false) instead of being physically deleted. - Public Access: accessPrivate — If enabled, anonymous users may access this object’s data depending on API-level rules.
Composite Indexes
- unique_conversation_pair: [participantA, participantB, enrollmentId] This composite index is defined to optimize query performance for complex queries involving multiple fields.
The index also defines a conflict resolution strategy for duplicate key violations.
When a new record would violate this composite index, the following action will be taken:
On Duplicate: throwError
An error will be thrown, preventing the insertion of conflicting data.
Properties Schema
| Property | Type | Required | Description |
|---|---|---|---|
conversationType |
String | Yes | Channel type: studentTutor, adminStudent, or adminTutor. Determines messaging permissions. |
participantA |
ID | Yes | First participant userId. For studentTutor: the student. For adminStudent/adminTutor: the admin. |
participantB |
ID | Yes | Second participant userId. For studentTutor: the tutor. For adminStudent: the student. For adminTutor: the tutor. |
enrollmentId |
ID | No | FK to enrollment. Only set for studentTutor conversations to link chat to enrollment context. |
lastMessageAt |
Date | No | Timestamp of the most recent message. Used for sorting conversations in inbox. |
lastMessagePreview |
String | No | Truncated preview of last message content. Shown in conversation list. |
status |
String | Yes | Conversation status: active or closed. |
participantAName |
String | No | Cached display name of participant A for quick rendering in conversation list. |
participantBName |
String | No | Cached display name of participant B for quick rendering in conversation list. |
courseTitle |
String | No | Cached course pack title for display. Set on conversation creation for studentTutor type. |
- Required properties are mandatory for creating objects and must be provided in the request body if no default value is set.
Default Values
Default values are automatically assigned to properties when a new object is created, if no value is provided in the request body. Since default values are applied on db level, they should be literal values, not expressions.If you want to use expressions, you can use transposed parameters in any business API to set default values dynamically.
- conversationType: ‘default’
- participantA: ‘00000000-0000-0000-0000-000000000000’
- participantB: ‘00000000-0000-0000-0000-000000000000’
- status: active
Always Create with Default Values
Some of the default values are set to be always used when creating a new object, even if the property value is provided in the request body. It ensures that the property is always initialized with a default value when the object is created.
- status: Will be created with value
active
Constant Properties
conversationType participantA participantB enrollmentId
Constant properties are defined to be immutable after creation, meaning they cannot be updated or changed once set. They are typically used for properties that should remain constant throughout the object’s lifecycle.
A property is set to be constant if the Allow Update option is set to false.
Auto Update Properties
conversationType participantA participantB enrollmentId lastMessageAt lastMessagePreview status participantAName participantBName courseTitle
An update crud API created with the option Auto Params enabled will automatically update these properties with the provided values in the request body.
If you want to update any property in your own business logic not by user input, you can set the Allow Auto Update option to false.
These properties will be added to the update API’s body parameters and can be updated by the user if any value is provided in the request body.
Enum Properties
Enum properties are defined with a set of allowed values, ensuring that only valid options can be assigned to them. The enum options value will be stored as strings in the database, but when a data object is created an addtional property with the same name plus an idx suffix will be created, which will hold the index of the selected enum option. You can use the index property to sort by the enum value or when your enum options represent a sequence of values.
-
conversationType: [studentTutor, adminStudent, adminTutor]
-
status: [active, closed]
Elastic Search Indexing
conversationType participantA participantB enrollmentId lastMessageAt status participantAName participantBName courseTitle
Properties that are indexed in Elastic Search will be searchable via the Elastic Search API. While all properties are stored in the elastic search index of the data object, only those marked for Elastic Search indexing will be available for search queries.
Database Indexing
conversationType participantA participantB enrollmentId lastMessageAt status
Properties that are indexed in the database will be optimized for query performance, allowing for faster data retrieval. Make a property indexed in the database if you want to use it frequently in query filters or sorting.
Relation Properties
participantA participantB enrollmentId
Mindbricks supports relations between data objects, allowing you to define how objects are linked together. You can define relations in the data object properties, which will be used to create foreign key constraints in the database. For complex joins operations, Mindbricks supportsa BFF pattern, where you can view dynamic and static views based on Elastic Search Indexes. Use db level relations for simple one-to-one or one-to-many relationships, and use BFF views for complex joins that require multiple data objects to be joined together.
- participantA: ID
Relation to
user.id
The target object is a parent object, meaning that the relation is a one-to-many relationship from target to this object.
On Delete: Set Null Required: Yes
- participantB: ID
Relation to
user.id
The target object is a parent object, meaning that the relation is a one-to-many relationship from target to this object.
On Delete: Set Null Required: Yes
- enrollmentId: ID
Relation to
enrollment.id
The target object is a parent object, meaning that the relation is a one-to-many relationship from target to this object.
On Delete: Set Null Required: No
chatMessage Data Object
Object Overview
Description: Auto-generated message DataObject for the chat RealtimeHub. Stores all messages with typed content payloads.
This object represents a core data structure within the service and acts as the blueprint for database interaction, API generation, and business logic enforcement.
It is defined using the ObjectSettings pattern, which governs its behavior, access control, caching strategy, and integration points with other systems such as Stripe and Redis.
Core Configuration
- Soft Delete: Enabled — Determines whether records are marked inactive (
isActive = false) instead of being physically deleted. - Public Access: accessPrivate — If enabled, anonymous users may access this object’s data depending on API-level rules.
Properties Schema
| Property | Type | Required | Description |
|---|---|---|---|
roomId |
ID | Yes | Reference to the room this message belongs to |
senderId |
ID | No | Reference to the user who sent this message |
senderName |
String | No | Display name of the sender (denormalized from user profile at send time) |
senderAvatar |
String | No | Avatar URL of the sender (denormalized from user profile at send time) |
messageType |
Enum | Yes | Content type discriminator for this message |
content |
Object | Yes | Type-specific content payload (structure depends on messageType) |
timestamp |
No | Message creation time | |
status |
Enum | No | Message moderation status |
replyTo |
Object | No | Reply thread reference { id, preview } |
- Required properties are mandatory for creating objects and must be provided in the request body if no default value is set.
Default Values
Default values are automatically assigned to properties when a new object is created, if no value is provided in the request body. Since default values are applied on db level, they should be literal values, not expressions.If you want to use expressions, you can use transposed parameters in any business API to set default values dynamically.
- roomId: ‘00000000-0000-0000-0000-000000000000’
- messageType: “text”
- content: {}
- timestamp: now()
- status: approved
Constant Properties
roomId senderId senderName senderAvatar messageType timestamp replyTo
Constant properties are defined to be immutable after creation, meaning they cannot be updated or changed once set. They are typically used for properties that should remain constant throughout the object’s lifecycle.
A property is set to be constant if the Allow Update option is set to false.
Auto Update Properties
roomId senderId senderName senderAvatar messageType content timestamp status replyTo
An update crud API created with the option Auto Params enabled will automatically update these properties with the provided values in the request body.
If you want to update any property in your own business logic not by user input, you can set the Allow Auto Update option to false.
These properties will be added to the update API’s body parameters and can be updated by the user if any value is provided in the request body.
Enum Properties
Enum properties are defined with a set of allowed values, ensuring that only valid options can be assigned to them. The enum options value will be stored as strings in the database, but when a data object is created an addtional property with the same name plus an idx suffix will be created, which will hold the index of the selected enum option. You can use the index property to sort by the enum value or when your enum options represent a sequence of values.
-
messageType: [text, image, document, system, warning]
-
status: [pending, approved, rejected]
Elastic Search Indexing
roomId senderId senderName senderAvatar messageType content timestamp status replyTo
Properties that are indexed in Elastic Search will be searchable via the Elastic Search API. While all properties are stored in the elastic search index of the data object, only those marked for Elastic Search indexing will be available for search queries.
Database Indexing
roomId senderId senderName senderAvatar messageType content timestamp status replyTo
Properties that are indexed in the database will be optimized for query performance, allowing for faster data retrieval. Make a property indexed in the database if you want to use it frequently in query filters or sorting.
Secondary Key Properties
roomId
Secondary key properties are used to create an additional indexed identifiers for the data object, allowing for alternative access patterns. Different than normal indexed properties, secondary keys will act as primary keys and Mindbricks will provide automatic secondary key db utility functions to access the data object by the secondary key.
Session Data Properties
senderId
Session data properties are used to store data that is specific to the user session, allowing for personalized experiences and temporary data storage. If a property is configured as session data, it will be automatically mapped to the related field in the user session during CRUD operations. Note that session data properties can not be mutated by the user, but only by the system.
- senderId: ID property will be mapped to the session parameter
userId.
Filter Properties
roomId senderId senderName senderAvatar messageType content timestamp status replyTo
Filter properties are used to define parameters that can be used in query filters, allowing for dynamic data retrieval based on user input or predefined criteria. These properties are automatically mapped as API parameters in the listing API’s that have “Auto Params” enabled.
-
roomId: ID has a filter named
roomId -
senderId: ID has a filter named
senderId -
senderName: String has a filter named
senderName -
senderAvatar: String has a filter named
senderAvatar -
messageType: Enum has a filter named
messageType -
content: Object has a filter named
content -
timestamp: has a filter named
timestamp -
status: Enum has a filter named
status -
replyTo: Object has a filter named
replyTo
chatModeration Data Object
Object Overview
Description: Auto-generated moderation DataObject for the chat RealtimeHub. Stores block and silence actions for room-level user moderation.
This object represents a core data structure within the service and acts as the blueprint for database interaction, API generation, and business logic enforcement.
It is defined using the ObjectSettings pattern, which governs its behavior, access control, caching strategy, and integration points with other systems such as Stripe and Redis.
Core Configuration
- Soft Delete: Disabled — Determines whether records are marked inactive (
isActive = false) instead of being physically deleted. - Public Access: accessPrivate — If enabled, anonymous users may access this object’s data depending on API-level rules.
Properties Schema
| Property | Type | Required | Description |
|---|---|---|---|
roomId |
ID | Yes | Reference to the room where the moderation action applies |
userId |
ID | Yes | The user who is blocked or silenced |
action |
Enum | Yes | Moderation action type |
reason |
Text | No | Optional reason for the moderation action |
duration |
Integer | No | Duration in seconds. 0 means permanent |
expiresAt |
No | Expiry timestamp. Null means permanent | |
issuedBy |
ID | No | The moderator who issued the action |
- Required properties are mandatory for creating objects and must be provided in the request body if no default value is set.
Default Values
Default values are automatically assigned to properties when a new object is created, if no value is provided in the request body. Since default values are applied on db level, they should be literal values, not expressions.If you want to use expressions, you can use transposed parameters in any business API to set default values dynamically.
- roomId: ‘00000000-0000-0000-0000-000000000000’
- userId: ‘00000000-0000-0000-0000-000000000000’
- action: “blocked”
- duration: 0
Constant Properties
roomId userId action duration expiresAt issuedBy
Constant properties are defined to be immutable after creation, meaning they cannot be updated or changed once set. They are typically used for properties that should remain constant throughout the object’s lifecycle.
A property is set to be constant if the Allow Update option is set to false.
Auto Update Properties
roomId userId action reason duration expiresAt issuedBy
An update crud API created with the option Auto Params enabled will automatically update these properties with the provided values in the request body.
If you want to update any property in your own business logic not by user input, you can set the Allow Auto Update option to false.
These properties will be added to the update API’s body parameters and can be updated by the user if any value is provided in the request body.
Enum Properties
Enum properties are defined with a set of allowed values, ensuring that only valid options can be assigned to them. The enum options value will be stored as strings in the database, but when a data object is created an addtional property with the same name plus an idx suffix will be created, which will hold the index of the selected enum option. You can use the index property to sort by the enum value or when your enum options represent a sequence of values.
- action: [blocked, silenced]
Elastic Search Indexing
roomId userId action reason duration expiresAt issuedBy
Properties that are indexed in Elastic Search will be searchable via the Elastic Search API. While all properties are stored in the elastic search index of the data object, only those marked for Elastic Search indexing will be available for search queries.
Database Indexing
roomId userId action reason duration expiresAt issuedBy
Properties that are indexed in the database will be optimized for query performance, allowing for faster data retrieval. Make a property indexed in the database if you want to use it frequently in query filters or sorting.
Secondary Key Properties
roomId userId
Secondary key properties are used to create an additional indexed identifiers for the data object, allowing for alternative access patterns. Different than normal indexed properties, secondary keys will act as primary keys and Mindbricks will provide automatic secondary key db utility functions to access the data object by the secondary key.
Relation Properties
roomId
Mindbricks supports relations between data objects, allowing you to define how objects are linked together. You can define relations in the data object properties, which will be used to create foreign key constraints in the database. For complex joins operations, Mindbricks supportsa BFF pattern, where you can view dynamic and static views based on Elastic Search Indexes. Use db level relations for simple one-to-one or one-to-many relationships, and use BFF views for complex joins that require multiple data objects to be joined together.
- roomId: ID
Relation to
conversation.id
The target object is a parent object, meaning that the relation is a one-to-many relationship from target to this object.
On Delete: Set Null Required: Yes
Session Data Properties
issuedBy
Session data properties are used to store data that is specific to the user session, allowing for personalized experiences and temporary data storage. If a property is configured as session data, it will be automatically mapped to the related field in the user session during CRUD operations. Note that session data properties can not be mutated by the user, but only by the system.
- issuedBy: ID property will be mapped to the session parameter
userId.
Filter Properties
roomId userId action reason duration expiresAt issuedBy
Filter properties are used to define parameters that can be used in query filters, allowing for dynamic data retrieval based on user input or predefined criteria. These properties are automatically mapped as API parameters in the listing API’s that have “Auto Params” enabled.
-
roomId: ID has a filter named
roomId -
userId: ID has a filter named
userId -
action: Enum has a filter named
action -
reason: Text has a filter named
reason -
duration: Integer has a filter named
duration -
expiresAt: has a filter named
expiresAt -
issuedBy: ID has a filter named
issuedBy
Business Logic
messaging has got 8 Business APIs to manage its internal and crud logic. For the details of each business API refer to its chapter.
Realtime Hubs
messaging has 1 Realtime Hub configured. Each hub provides bidirectional communication powered by Socket.IO with room-based messaging, built-in and custom message types, and auto-generated REST endpoints.
| Hub Name | Namespace | Room DataObject | Roles |
|---|---|---|---|
chat |
/hub/chat |
conversation |
member, viewer |
For detailed documentation on each hub, refer to:
This document was generated from the service architecture definition and should be kept in sync with implementation changes.