Rainty module: In-app messaging
Build v1 of In-app messaging in Rainty: one-to-one text messages between people of the same organisation, with delivery and read receipts, a typing indicator, offline sending and search. You write messaging-service and the frontend module; who sees what is handled by the platform: messages carry the user and organisation from the token, and the data routes apply the permissions. The participant model must be ready for customers to join later.
Rainty module: In-app messaging
Rainty is one application for professionals who manage customers; each customer gets a different set of switchable modules. This challenge builds In-app messaging: one-to-one text messages between the people of the same organisation (a gym's coaches, a school's teachers, a studio's staff), inside Rainty, with no personal phone numbers and no data leaving the platform. Customers cannot sign in to Rainty yet; when they can, they will join the same conversations as one more kind of participant, so the model you build must not assume that every participant is a staff user.
This brief has two parts: a backend service, messaging-service, and the frontend module messaggi. Who sees what is not your problem: every message is written with the user and the organisation taken from the token, and the platform's permission layer decides what each user gets back. The rules, the workflow and the common acceptance criteria of the module challenges are in the common brief and the documents it points to. They are part of the specification: read them first.
Repository and workflow
| Repository | https://github.com/vinovalab/rainty |
| Module key | messaggi |
| Verticals | all |
| Working branch | feature/messaggi |
| Target branch (PR) | main |
| Service folder | services/messaging-service/ (rainty) |
| Module folder | frontend/modules/messaggi/ (rainty) |
| Reference mockup | ~/riferimenti/VL021-messaggi/mockup-a/ in your workspace (see below) |
You work from your personal dev-platform workspace (https://ws-<your-github-login>.vinovalab.ai, sign in with Cloudflare Access). Run ws-sync, then git checkout -b feature/messaggi origin/main in rainty. Run the frontend dev server from frontend/apps/rainty-organizer against the development API, on port 5182, with the dev users the project coordinator enables for you (at least two users and one organisation admin of the same organisation). Push only your branch and open the Pull Request targeting main (gh pr create --base main).
The documents that govern the work
Read these before writing a line. Reviews cite their rule numbers.
- Rainty module challenges: common brief: the workflow, the six non-negotiable rules, the deliverables and the common acceptance criteria.
- Rainty modules contract: manifest, frontend, proposal, core, events, services, acceptance (§1–§10).
- Anatomy of a module: the thirteen pieces of a module, file by file, proposal included.
- Engineering guidelines: how code is written and reviewed here.
- The Conversation Context Service (
rainty/docs/conversation-context/PROPOSAL.mdandrainty/services/conversation-context-service/): the reference for a Rainty service that stores its data through the platform's data routes. Reuse its patterns; do not change it.
Where the documents do not match what you find in the repositories or in the development API, report it in the PR. Those corrections are on us to fix and never move your delivery window.
The first version
Inside:
- one-to-one conversations between two members of the same organisation who both have the module active; one conversation per pair, reopened when either of them writes again;
- text messages only (plain text with line breaks; links shown as links);
- delivered and read receipts, and a typing indicator, both ways;
- real-time delivery to every open tab of the recipient, and an unread count per conversation and in total, shown in the module;
- messages written while offline are kept in the browser, shown as "waiting", and sent in order when the connection returns, without duplicates;
- search in the conversations the user can see;
- the directory: the list of the organisation's members the user can write to.
Outside (later challenges), and decided:
- group conversations: not in this version;
- office hours and automatic replies: not planned;
- images, files and voice notes: not in this version;
- deleting or editing a message: not in this version; a message, once sent, stays as it is;
- customers as participants: they arrive with the customer portal; leave room for them in the model, build nothing for them;
- AI-suggested replies: they will come with customers, through rAInty AI; do not implement;
- push notifications (iOS, Android, web push) and email notifications: the mobile apps come later;
- links from a conversation to a customer record or to the customer timeline;
- end-to-end encryption, voice and video calls.
Who uses it, and who sees what
- Member. A user of the organisation with the module active. Writes to any member listed in the directory and reads the conversations they are given.
- Organisation admin. Sees every conversation of the organisation.
You do not implement visibility. Every message and every conversation is written with the user id and the organisation id taken from the authentication token, never from the request. Every read goes through the platform's data routes, which apply the permission rules (a member gets the conversations they take part in, the organisation admin gets all of them, nobody gets anything of another organisation) and return each conversation with a puoScrivere flag. Your service and your interface show what they receive and hide the composer when puoScrivere is false; they never filter by user, organisation or role, and never check RAINTY_ADMIN. Audit of admin reading is ours too.
The only thing the module says about it is a short notice, once, in the empty state: the organisation's admins can read the conversations. The wording is ours to review in the PR.
Architecture
messaging-service (yours)
A new Node service in rainty/services/messaging-service/, built like the other Rainty services (Dockerfile, compose entry in the rainty compose files, health route, structured logs). It is reached by the frontend as /messaging-service/*; we add the proxy location in the frontend's nginx.
- Authentication on every request through auth-service, as the other services do. The service forwards the user's token to the data routes; it never sends a user id or an organisation id of its own.
- No direct database access. Every read and write goes through the data routes
/rainty/messaggi/*(below). This is a platform rule, not a preference. - REST for everything that changes state: send a message (with a client-generated id, so a retry never creates a duplicate), mark as delivered and read, list conversations with the unread count, page through a conversation, search, directory.
- Real time through the service's own authenticated stream (Server-Sent Events or WebSocket: your choice, justified in the proposal), one per open tab, carrying new message, receipt and typing events. Before forwarding an event to a stream, the service asks the data routes whether that user can see that conversation (cache the answer briefly); it never decides it on its own. With more than one instance of the service, instances talk through Redis pub/sub on channels that only the service reads. Do not use the existing
redis-ws-bridge: it fans every Redis channel out to every authenticated client, with no per-organisation or per-user filtering, so it must never carry message content or metadata. - Message content never appears in logs, URLs or error messages.
Data routes (ours, from your proposal)
The routes under /rainty/messaggi/* in data-service are written by the core team, as for every Rainty module, from the list you put in the proposal: for each route, method, path, what it reads or writes, and the shape of the request and of the answer. They take user and organisation from the token, write them on every row, and apply the permission rules on every read. Until they are live on development, write against a small stub in your tests that follows the same contract.
Tables (proposed by you, created by us)
In schema rainty_messaggi, shaped in the proposal. A starting point, not a constraint:
conversazioni: organisation, created at, last message at;partecipanti: conversation, participant kind and participant reference (today onlyuserwith the user id; later a customer of the portal), joined at, last read message;messaggi: conversation, organisation, sender (kind and reference), text, client id (unique per sender), created at;ricevute: message, participant, delivered at, read at.
You do not need columns or tables for permissions or for the admin's access log: those are ours.
No edited_at, no deleted_at: there is no edit or delete in this version. The body is sensitive: mark it so in the proposal and in the manifest; we will encrypt it when the platform's tenant encryption is switched on, without changes on your side.
The module
The frontend lives in frontend/modules/messaggi/ and follows the module contract (manifest, pages, components, hooks, API client, it/en catalogues, tests):
- a module page with the list of conversations (name, last message preview, time, unread count) and the open conversation beside it on desktop, one after the other on the phone;
- a composer for text (Enter sends, Shift+Enter adds a line); the typing indicator and the receipts as small, quiet signs;
- a directory to start a conversation, with search by name;
- search across the user's conversations, opening the conversation at the message found;
- a conversation with
puoScriverefalse is shown read-only, without the composer; - an offline banner, and messages waiting to be sent kept across a page reload.
The mockup also shows three things the lists above take for granted, so here they are explicitly:
- the unread count next to "Messages" in the side menu and in the phone's bottom bar. If the module shell has no way for a module to show a count in the navigation, ask for it in the "what I use from the core" section of the proposal and keep the count inside the module page meanwhile;
- the time of reading on the last message you sent ("Read at 11:21"): the service returns
read atwith the receipts, not only a flag; - in a read-only conversation the names of both participants above the bubbles: list the field you need in the data routes of the proposal (the conversation answer carries every participant, not only "the other one").
Reference mockup
Where it is. In your workspace, read-only, at ~/riferimenti/VL021-messaggi/mockup-a/ (outside ~/code, so ws-sync never touches it). Start from LEGGIMI.md, then look at the screenshots in immagini/, then open index.html (python3 -m http.server from that folder; views with ?v=vuota|conversazione|nuova|ricerca|lettura|offline|telefono, dark theme with #dark). If the page does not open, the screenshots are enough. Do not copy the CSS of the mockup: use the real --rainty-* tokens, .rainty-* classes and @rainty/ui. Names, roles and messages in the mockup are invented and are at most test fixtures.
What follows from it. The mockup ("Two columns") is a direction, not a pixel spec. LEGGIMI.md lists what is fixed (the two-column module page with the conversation list on the left and the open conversation on the right, one after the other on the phone with a back arrow; search above the list, whose results replace the list and open the conversation at the highlighted message; "New conversation" from the header, opening the organisation's directory and reopening an existing conversation with the same person; quiet receipts, one tick delivered and two coloured ticks read, written out in full on your last message; typing under the name in the header and as dots at the bottom of the thread, never as a notification; the offline band, queued messages dashed with a clock and "Waiting to be sent", writing still possible; read-only with the composer absent, not disabled, a line saying why, and the sender's name above every bubble; the notice about admins once, in the empty state; Enter sends, Shift+Enter adds a line; text only, no attach, microphone, emoji, edit or delete buttons, and no filter by role or organisation) and what is free (list width and density, preview lines, dialog or panel for the directory and the exact place of its button, icons, spacing, wording, typing dots animation, loading and error states beyond the ones shown, grouping by day, component structure).
Use the impeccable skill for every piece of frontend, and check the result in light and dark, on desktop and at 375 px. Say in the PR what you checked.
What the core gives you, and what it does not
Available in development today: authentication and the user's organisation, per-user module activation, @rainty/api, the design system, and the module shell. From your proposal: the tables, the data routes with the permission rules.
Not available, and not yours to build or wait for: push notifications, the customer portal, tenant encryption. If you need something from the core that is not there, ask for it in the "what I use from the core" section of the proposal; do not wait for it.
The proposal
Your first commit, in the rainty PR, is frontend/modules/messaggi/PROPOSTA.md, and your PRs are open as soon as it exists. Beyond the proposal model of the anatomy it says: the tables, the data routes you need (with their request and answer), the service API and the stream messages, how offline sending stays free of duplicates. We answer within the next working day: tables and data routes on development, the nginx location and your dev users enabled, or the corrections we ask for. Later changes follow the same path. Keep the first proposal small.
Expected deliverables
- One PR on rainty from
feature/messaggi:services/messaging-service/with tests, its compose entries, the module folder withPROPOSTA.mdaligned with the final code, the manifest (sensitive fields marked,it/encatalogues complete), pages, components, hooks, the API client, tests, and a shortREADME.mdsaying what surprised you, how you handled each mismatch with the documents, and where you departed from the mockup.
Acceptance criteria
The common criteria of the common brief apply in full (green checks, switch on/off behaviour, PROPOSTA.md matching the code, desktop and phone in light and dark). In addition:
- two members of the same organisation exchange text messages; each arrives in real time in every open tab of the recipient, without reloading;
- delivered and read receipts and the typing indicator work both ways;
- a message written offline is shown as waiting, survives a page reload and is sent on reconnect, in order and exactly once;
- search finds a message by its text and opens the conversation at that message;
- user and organisation are never sent by the service or the frontend: they come only from the token; the service and the module contain no filter by user, organisation or role;
- the stream forwards an event only after the data routes confirm the user can see that conversation;
- a conversation returned with
puoScriverefalse is read-only in the interface and rejected by the service; - members are told that admins can read the conversations;
- the layout follows the reference mockup (direction A, "Two columns"); deviations are explained in the README;
- the last message you sent shows when it was read, and the unread count is visible in the navigation (or in the module page, if the shell cannot show it yet);
- messages are text only; there is no way to attach files, edit or delete a message, in the API or in the interface;
- message content appears in no log, URL or error;
- the service never connects to the database and never uses
redis-ws-bridge; - the participant model holds a non-user participant kind without a schema change;
- nothing outside
services/messaging-service/, the service's compose entries,frontend/modules/messaggi/and your line infrontend/modules/index.tschanged in rainty.
If the brief is wrong
If something here turns out to be impossible or absent (a route that does not exist, a component that is not where it should be, a rule that contradicts another) say so on the challenge before you start. A brief that is wrong is our problem, and the window pauses while you wait for an answer.