OpenPlaud
A real-time chat call-center platform. Customers open a chat bubble on any website; operators watch live call cards appear, accept to go 1:1, and transfer calls to colleagues — all in real time over XMPP.
What it does
OpenPlaud pairs a management plane — a Kotlin REST API that owns the source of truth in PostgreSQL and mirrors every change into an ejabberd XMPP server — with a conversation plane — a temporary MUC room per customer call, where operators are granted (and revoked) real-time access to messages. The platform is four components:
| Component | Role | Stack |
|---|---|---|
openplaud-srv-admin | Kotlin REST API + ejabberd sync (source of truth) | Kotlin · Spring Boot 4 · PG · Redis |
openplaud-fed-admin | Admin console: operators, groups, dashboard | Next.js 16 · React 19 |
openplaud-fed-operator | Operator console: live call cards, 1:1 chat, transfer | Next.js 16 · React 19 · Strophe 5 |
openplaud-fed-client | Embeddable customer chat bubble + demo pages | Next.js 16 · single-file bubble |
How a call flows, in one line
A customer submits the bubble → POST /customers + POST /chatroom create a temp XMPP account and a temp MUC room → the customer's first message lights up an operator call card → an operator accepts (POST /chatroom/join, others outcast, now 1:1) → POST /chatroom/transfer hands the call to another operator in the same group.
Architecture
Two planes: a management plane (PostgreSQL is the source of truth, mirrored into ejabberd) and a conversation plane (a temp MUC room per call over XMPP). Hover a node to highlight its connections; click it for details.
Click a node in the diagram to inspect its role, port, and responsibilities.
The two planes
Management plane
PostgreSQL is authoritative. Every operator/group/membership change writes a DB row and mirrors it into ejabberd via mod_http_api. If the DB write fails, the remote change is compensated; on compensation failure the entity is logged as orphaned.
Conversation plane
Each call is a temp MUC room <user>_<group>@conference. The customer is member + subscribed; group operators are admin + subscribed to room messages. Accept outcasts everyone but the accepting operator; transfer re-applies admin to the new operator.
Concepts & data model
Three entities — Operator, Group, Membership — plus the per-call temp room and the custom MucSub module that turns room messages into push events.
| Term | Meaning |
|---|---|
| Operator | A registered user on the XMPP server, addressed as localpart@localhost. Created via POST /operators; the XMPP user is the slug of the operator's name. |
| Group | A persistent, members-only MUC room node@conference, titled with the group's display name, with message logging enabled. |
| Membership | An operator added to a group (operator_groups row) is made an affiliated MUC admin of the group's room. |
| Temp room | A per-conversation MUC room <userUUID>_<groupUUID>@conference titled with the customer's display name. Customer is member + subscribed; group operators are admin + subscribed to the room's messages. |
| MucSub | Custom ejabberd module that pushes room messages as pubsub events (urn:xmpp:mucsub:nodes:messages) so operators see a call light up without joining the room. |
| Affiliation | MUC role: none / member / admin / outcast. Accept sets everyone but the acceptor to outcast; transfer sets the previous operator to outcast and the target to admin. |
| Outcast | Revokes access — and, crucially, server-side drops the operator's MucSub subscriptions, which is why transfer candidates come from GET /groups/{id}/operators, not the subscription list. |
| Slug | Name → lowercased alphanumeric, 2–30 chars (a valid XMPP localpart). Names that don't produce a valid localpart are rejected (422). |
The operator_groups junction is the membership: each row corresponds to an MUC admin affiliation on the group's persistent room. Temp rooms are not persisted — they live only in ejabberd for the life of a call.
Identifiers
Derivation
"John Doe" → johndoe (lowercase, alphanumerics, 2–30 chars). "Support Team" → supportteam → room supportteam@conference.
Slug rules: must be a valid XMPP localpart — lowercased, alphanumeric only, 2–30 characters. Invalid names are rejected with 422 Unprocessable Entity.
Consistency model
Every operation pairs a remote ejabberd call with a local database write. The database is authoritative:
- If the DB write fails after a successful ejabberd call, the remote change is compensated (unregister user / destroy room / remove affiliation) and the error is propagated.
- If compensation itself fails, the log marks the remote entity as orphaned so it can be cleaned up manually.
API reference
All endpoints live under /api/v1. Base URL: http://localhost:8080/api/v1. OpenAPI at /v3/api-docs; Swagger UI at /swagger-ui.html.
Operators
| Method | Path | Description |
|---|---|---|
| POST | /operators | Register an operator: creates the XMPP user and an operators row |
| GET | /operators | List all operators (auth-gated) |
| GET | /operators/{operatorId}/groups | List the groups the operator belongs to |
| DELETE | /operators/{operatorId} | Remove an operator (membership rows + XMPP user) |
POST /operators — password is optional; when omitted the server generates one and returns it once in the 201 response:
{ "name": "John Doe", "email": "john@example.com", "password": "optional" }{ "id": "…", "name": "John Doe", "email": "john@example.com",
"xmppUser": "johndoe", "initialPassword": "…" }Groups
| Method | Path | Description |
|---|---|---|
| POST | /groups | Create a group: persistent MUC room + groups row |
| GET | /groups | List all groups (Redis cache, 5 min TTL, evicted on create/delete) |
| GET | /groups/{groupId}/operators | List the operators of the group |
| POST | /groups/{groupId}/operators/{operatorId} | Add operator to group (MUC affiliation admin) |
| DELETE | /groups/{groupId}/operators/{operatorId} | Remove operator from group (affiliation none) |
| DELETE | /groups/{groupId} | Remove group (destroys the MUC room, deletes membership rows) |
{ "name": "Support Team", "service": "conference" }
→
{ "id": "…", "name": "Support Team", "room": "supportteam",
"service": "conference" }Temp rooms
Temp-room endpoints do not require the caller to be authenticated — the configured ejabberd admin account is used. service is optional in all three and defaults to ejabberd.muc-service.
| Method | Path | Description |
|---|---|---|
| POST | /chatroom | Create temp room <user>_<groupId>: user is member+subscribed, every operator of the group is admin+subscribed (urn:xmpp:mucsub:nodes:messages) |
| POST | /chatroom/join | Operator joins the room: all other operators of the group are set to outcast |
| POST | /chatroom/transfer | Transfer to another operator: new operator admin+subscribed, previous operator outcast |
{ "user": "c04582c4-…", "name": "Jane Doe",
"groupId": "c7fc5856-…", "service": "conference" }
→
{ "room": "c04582c4-…_c7fc5856-…", "service": "conference" }{ "operatorId": "…", "groupId": "…", "room": "c04582c4-…_c7fc5856-…" }{ "room": "c04582c4-…", "operatorId": "…", "previousOperatorId": "…",
"service": "conference" }Login checks
| Method | Path | Description |
|---|---|---|
| GET | /operator/login | Verify an operator's Basic auth credentials via ejabberd check_password |
| GET | /admin/login | Verify admin credentials (user must be ejabberd.username) via check_password |
Both read the Authorization header and return 200 on a successful check_password; a missing header, wrong user, or bad password returns 401 Unauthorized. GET /operators and GET /operators/{id}/groups are gated the same way but any valid operator passes; GET /groups/{id}/operators requires the configured admin account.
Errors
Failures are mapped to a consistent JSON body by a global exception handler.
{ "status": 409, "code": "conflict", "message": "duplicate slug", "fields": { "name": "…" } }| Status | Meaning |
|---|---|
| 400 | Validation errors |
| 401 | Unauthorized (login / auth-gated) |
| 404 | Not Found |
| 409 | Conflict (duplicate slugs / memberships) |
| 422 | Unprocessable Entity (invalid slug) |
| 5xx | Upstream ejabberd failures proxied with the original status code |
Admin console
The openplaud-fed-admin console — Next.js (App Router, TypeScript) + React 19 — talks to the Kotlin API and, through it, manages ejabberd. Everything is auth-gated.
Features
Auth-gated panel
Everything behind /login. Credentials are verified against GET /admin/login (Basic auth) and kept in sessionStorage for the tab; any 401 logs the session out back to the login screen.
Operators
Create (name, email, optional password — a server-generated initialPassword is shown once with a copy button), list, delete (confirm dialog), and view which groups an operator belongs to.
Groups & members
Create (name + MUC service), list, delete (destroys the MUC room), and a Members manager: add operators to a group (MUC affiliation) or remove them.
Dashboard
Operator/group counts plus recent lists. Backend errors (409 duplicate, 422 invalid slug, 400 validation fields) are mapped from the API's {status, code, message, fields?} body into toasts and field errors.
Configuration
| Where | Variable | Default | Purpose |
|---|---|---|---|
| .env.local | API_BASE_URL | http://localhost:8080/api/v1 | Kotlin admin API base URL |
Server-side proxy: browser requests go to app/api/proxy/[...path]/route.ts, a Next.js route handler that forwards to API_BASE_URL/<path> and passes the Authorization: Basic … header through. The URL never ships to the client bundle (no CORS, no env leakage). If the backend is down the proxy answers 502.
Project layout
Out of scope: the temp-room endpoints (/chatroom, /join) are conversation-side and are not part of the admin surface.
Operator console
The live agent desktop — where calls are answered, chatted and transferred. Everything XMPP happens over a raw Strophe Connection the operator opens after logging in through the API.
Stack
How it works
Login — /login posts to GET /operator/login (Basic auth). On success the operator's credentials are stored in sessionStorage for the tab and the XMPP session is opened: a Strophe connection to NEXT_PUBLIC_XMPP_WS_URL binds the localpart@localhost JID, sends the initial $pres() and — only once CONNECTED — subscribes to every group MUC via the MucSub <subscribe> IQ.
Message-driven call cards — the operator is subscribed to all group MUCs; a customer's first message in a temp room surfaces as a call card in the queue. History is kept in sessionStorage, capped at 500 entries.
Accept & transfer — accepting posts POST /chatroom/join: the operator becomes MUC admin of the temp room and every other operator is outcast (the 1:1 conversation is theirs alone). Transferring posts POST /chatroom/transfer: the new operator becomes admin + subscribed, the previous one is outcast server-side (their MucSub subscriptions are dropped — a subscription-list IQ now returns 403).
UX — conversations open in draggable windows; toasts confirm joins/transfers; leaving a conversation just closes its window — no API call.
Walkthrough — from message to transfer
- 1 Customer writes
A temp-room message reaches the MUC; MucSub republishes it as a pubsub event to subscribed admins.
- 2 Card lights up
The operator subscribed to the group MUC receives the event and a call card appears in the queue.
- 3 Accept
POST /chatroom/join — operator becomes MUC admin of the temp room; all other operators are outcast.
- 4 Chat 1:1
The operator chats with the customer in a draggable conversation window; the rest of the group is outcast.
- 5 Transfer
POST /chatroom/transfer — new operator becomes admin + subscribed; the previous operator is outcast.
- 6 Handoff
The new operator's window takes over; the MucSub subscription list moves with the affiliation.
- 7 Close
The conversation is closed in the UI; history remains capped in sessionStorage for the tab.
Configuration
| Variable | Default | Purpose |
|---|---|---|
| API_BASE_URL | http://localhost:8080/api/v1 | Kotlin API base (server-side proxy target) |
| NEXT_PUBLIC_XMPP_WS_URL | ws://localhost:5280/xmpp-websocket | ejabberd WebSocket endpoint for Strophe |
| NEXT_PUBLIC_XMPP_DOMAIN | localhost | Bare-JID domain |
| NEXT_PUBLIC_XMPP_SERVICE | conference | MUC service for group/temp rooms |
Scripts
| Script | What it does |
|---|---|
| npm run dev | Next.js dev server (port 3000) |
| npm run build | Production build (App Router) |
| npm run lint | ESLint — baseline: 1 error + 1 warning are intentional (kept so CI diff is stable) |
| npm run strophe:test | Runs the strophe-test/ harness (below) |
Layout
Verified end-to-end 2026-11-03: full login → card → join → transfer cycle exercised against a live ejabberd 26.9 with the MucSub module loaded.
Customer chat bubble
The thing customers actually see: a single-file, embeddable chat bubble that opens a Strophe 5 session straight into the operator's temp room. It is not an app — it is a drop-in script.
Embed it
Add the built file and configure it with data-* attributes on the script tag (or call the global API after load):
<!-- Mode A · declarative (attributes on the script tag) -->
<script
src="/openplaud.js"
data-api-base="http://localhost:8080/api/v1"
data-operator-group="18c4c671-9ced-454b-b7ce-a5eb333b331e"
data-xmpp-url="ws://localhost:5280/xmpp-websocket"
data-xmpp-domain="localhost"
data-xmpp-service="conference"></script>
<!-- Mode B · programmatic -->
<script src="/openplaud.js"></script>
<script>
OpenPlaud.open({
apiBase: "http://localhost:8080/api/v1",
operatorGroup: "18c4c671-9ced-454b-b7ce-a5eb333b331e",
xmppUrl: "ws://localhost:5280/xmpp-websocket",
xmppDomain: "localhost",
xmppService: "conference"
});
</script>
The file is public/openplaud.js, built by scripts/build-bubble.mjs (bundler output, committed) — host it next to your page and the bubble floats in.
Config keys
| Key | data-* attribute | Purpose |
|---|---|---|
| apiBase | data-api-base | Kotlin API base — used for /customers + /chatroom |
| operatorGroup | data-operator-group | Group UUID the customer's temp room belongs to |
| xmppUrl | data-xmpp-url | ejabberd WebSocket endpoint |
| xmppDomain | data-xmpp-domain | Bare-JID domain (localhost) |
| xmppService | data-xmpp-service | MUC service (conference) |
Programmatic API — window.OpenPlaud
| Member | Behavior |
|---|---|
| open(config?) | Create/attach the bubble; config optional when already set via data-* |
| close() | Close the conversation panel (bubble stays) |
| destroy() | Tear everything down, including the Strophe connection |
| state | Read-only lifecycle: idle → connecting → connected → closed |
How it works
- 1 Register
On first open the bubble posts POST /customers and gets a one-time password for the temp account.
- 2 Room
POST /chatroom creates the temp room <userUUID>_<groupUUID>@conference; the customer joins as member+subscribed.
- 3 Session
Strophe connects to xmppUrl with the temp credentials, sends the initial $pres(), joins the MUC.
- 4 Chat
Every temp-room message is pushed by MucSub as a pubsub event; the bubble renders them and sends replies into the room.
- 5 Handoff
First message lights the operator's call card; from there the operator console takes over (join / transfer).
Customer API contract
POST /api/v1/customers { "email": "customer@example.com" }
→ 201 { "id": "…", "initialPassword": "…(one-time)" }
DELETE /api/v1/customers/{id} → 204 (drops the temp account)
POST /api/v1/chatroom { "customerId": "…", "group": "…<groupUUID>" }
→ 201 { "room": "<userUUID>_<groupUUID>@conference", "password": "…" }
No CORS: the API does not speak CORS, so in the demo app the bubble's calls are routed through the app's /api/proxy server-side proxy — same pattern as the two consoles.
Demo pages
npm run build:bubble # runs scripts/build-bubble.mjs → public/openplaud.js
Protocol & Strophe 5
Everything real-time runs over XMPP: MUC rooms for the group and temp conversations, and a custom MucSub module that republishes room messages as pubsub events so operators can subscribe without being members. Here is the protocol surface — and the player that animates one full call.
| Gotcha | Why it bites |
|---|---|
| Handlers must return true | A handler that returns false/undefined gets its stanza dropped — the message "never arrives". |
| Connection is not a root export | The namespace changed in 5.x; import/instantiate it the documented way or the connection silently no-ops. |
| sendIQ auto-ids, raw send doesn't | IQs fired via send() need an explicit id or the reply never matches the request. |
| Initial $pres() required | No first presence, no stream authorization — and no MUC join will stick. |
| MucSub subscribe IQ is type="set" | <subscribe xmlns='urn:xmpp:mucsub:0'><nick/></subscribe> must go out only after CONNECTED. |
| Delivery is a double-wrapped <message> | Outer <message from='room@conference'> → pubsub <event> → <items node='urn:xmpp:mucsub:nodes:messages'> → the inner MUC message. |
| Subscription-list IQ needs moderator rights | After an outcast, the list IQ answers 403 — that's the server confirming the drop. |
<!-- MucSub subscribe — after CONNECTED -->
<iq type="set" to="room@conference" id="op-1">
<subscribe xmlns="urn:xmpp:mucsub:0">
<nick>operator-1</nick>
</subscribe>
</iq>
<!-- MucSub delivery of a room message -->
<message from="room@conference">
<event xmlns="http://jabber.org/streams/pubsub">
<items node="urn:xmpp:mucsub:nodes:messages">
<item id="…">
<body>Hello</body>
<from>customer@example.com</from>
</item>
</items>
</event>
</message>
Call lifecycle — step player
Press Play to walk a customer's first message through to a transfer, or step through manually.
- 1 · Registercustomer → APIPOST /customers
The bubble creates the temp account and receives a one-time password.
- 2 · Create roomcustomer → APIPOST /chatroom
Temp MUC <userUUID>_<groupUUID>@conference is created; customer joins as member+subscribed.
- 3 · XMPP connectcustomer → ejabberdws + $pres()
Strophe opens the WebSocket and sends the initial presence; the stream is authorized.
- 4 · First messagecustomer → MUCroom message
The customer's first line lands in the temp room; MucSub republishes it as a pubsub event.
- 5 · Card lights upoperator ← MUCpubsub event
An operator subscribed to the group MUC receives the event; a call card appears in the queue.
- 6 · Acceptoperator → APIPOST /chatroom/join
The operator becomes MUC admin of the temp room; every other operator is outcast.
- 7 · Chat 1:1customer ↔ operatorMUC messages
Only that operator can see the conversation now; the rest of the group is outcast.
- 8 · Transferoperator → APIPOST /chatroom/transfer
A new operator becomes admin+subscribed; the previous operator is outcast.
- 9 · Subscription handoffejabberdMucSub
The old operator's MucSub subscriptions are dropped server-side; the new one is live (old list now 403).
- 10 · Closeoperator → UIwindow close
The conversation window closes; history stays in sessionStorage, capped at 500 entries.
Deployment
Five ports, three moving parts (PostgreSQL, Redis, ejabberd 26.9 + MucSub), one Kotlin API, three frontends. Boot them in dependency order and the API is the only thing the frontends ever talk to.
Prerequisites & ports
| Service | Port | Notes |
|---|---|---|
| PostgreSQL | 5432 | Source of truth — operators, groups, operator_groups |
| Redis | 6379 | Sessions/caches for the API |
| ejabberd 26.9 | 5280 | mod_http_api + conference MUC + MucSub module; WS at /xmpp-websocket |
| Kotlin API | 8080 | /api/v1 — REST surface + mirror into ejabberd |
| Frontends | 3000 | admin / operator / client (all Next.js dev) |
Database
CREATE TABLE operators (
id UUID PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE groups (
id UUID PRIMARY KEY,
slug TEXT NOT NULL UNIQUE, -- lowercased a-z0-9, 2–30 chars
name TEXT NOT NULL,
muc_service TEXT NOT NULL DEFAULT 'conference',
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE TABLE operator_groups (
operator_id UUID REFERENCES operators(id) ON DELETE CASCADE,
group_id UUID REFERENCES groups(id) ON DELETE CASCADE,
PRIMARY KEY (operator_id, group_id)
);
Boot order
- 1 PostgreSQL & Redis
Both up before anything else — the API refuses to start without a reachable DB.
- 2 ejabberd
With mod_http_api on 5280, the conference MUC service, and the MucSub module loaded.
- 3 Kotlin API
./gradlew bootRun → http://localhost:8080/api/v1. It reconciles the DB into ejabberd on startup.
- 4 Frontends
Any order — each is npm run dev on 3000 with its own API_BASE_URL pointing at the API.
API configuration — application.properties
| Key | Default | Purpose |
|---|---|---|
| spring.datasource.url | jdbc:postgresql://localhost:5432/openplaud | PostgreSQL JDBC URL |
| spring.data.redis.host | localhost:6379 | Redis endpoint |
| openplaud.ejabberd.url | http://localhost:5280/api | mod_http_api base |
| openplaud.ejabberd.user | admin@localhost | Management JID |
| openplaud.ejabberd.password | admin | Management password (dev default) |
Project layout & tooling
./gradlew bootRun # run the API
./gradlew test # unit + integration
./gradlew build -x test # assemble the jar
# Swagger / OpenAPI (while running)
http://localhost:8080/swagger-ui
http://localhost:8080/api/v1/openapi.json
Testing & troubleshooting
The operator project ships a strophe-test/ harness — plain Node, no browser — that drives a real Strophe 5 connection against a live ejabberd so the XMPP behavior can be asserted outside the UI.
strophe-test harness
| Part | What it does |
|---|---|
| Node scripts | Headless drivers: connect → $pres() → MUC join → MucSub subscribe → message round-trip → outcast, each step asserted. |
| Fixtures | Recorded stanzas — the <subscribe> IQ, the double-wrapped MucSub delivery, the 403 list reply — reused as expected outputs. |
| Run | npm run strophe:test |
cd openplaud-fed-operator
npm run strophe:test # needs ejabberd on :5280 with MucSub loaded
Verified E2E 2026-11-03: the full login → call card → join → transfer cycle ran green against a live ejabberd 26.9 with the MucSub module — the same path the harness exercises.
Troubleshooting
| Symptom | Usual cause → fix |
|---|---|
| Login 401 even with right credentials | ejabberd check_password disagrees with the API — the operator was never mirrored (API down at create time). Re-run the API boot reconcile. |
| Proxy answers 502 | The Kotlin API on :8080 is down — start it (boot order: PG → Redis → ejabberd → API). |
| No call card after customer writes | Operator isn't subscribed to the group MUC — they must be a member via operator_groups, and the MucSub subscribe IQ must be sent only after CONNECTED. |
| Messages arrive but aren't rendered | Handler didn't return true (Strophe 5 drops the stanza) — check the MucSub delivery unwrap: outer message → <event> → <items node='…mucsub:nodes:messages'>. |
| Subscription-list IQ returns 403 | Expected after an outcast — the server dropped the subscriptions on transfer. Not an error to chase. |
| Temp room never created | POST /chatroom got a 404 customer (already deleted → 204) or the group UUID in the bubble config is stale — re-issue POST /customers. |