OpenPlaud / Introduction

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.

Kotlin · Spring Boot 4 ejabberd 26.9 · XMPP PostgreSQL + Redis Next.js 16 · React 19 Strophe 5

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:

ComponentRoleStack
openplaud-srv-adminKotlin REST API + ejabberd sync (source of truth)Kotlin · Spring Boot 4 · PG · Redis
openplaud-fed-adminAdmin console: operators, groups, dashboardNext.js 16 · React 19
openplaud-fed-operatorOperator console: live call cards, 1:1 chat, transferNext.js 16 · React 19 · Strophe 5
openplaud-fed-clientEmbeddable customer chat bubble + demo pagesNext.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.

02 Architecture

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.

HTTP /api/proxy HTTP /customers · /chatroom JPA · source of truth groups cache · 5 min mod_http_api :5280 XMPP WS · MucSub HTTP /api/proxy XMPP WS · temp account (direct) Admin console Next.js 16 · React 19 :3000 Customer bubble openplaud.js · Strophe 5 temp account + room Kotlin REST API Spring Boot 4 · :8080/api/v1 source of truth PostgreSQL :5432 · ddl-auto=validate Redis :6379 · groups cache ejabberd 26.9 XMPP · conference MUC :5280 · mod_http_api mucsub · mam modules Operator console Next.js 16 · Strophe 5 :3000 · live call cards
HTTP / REST XMPP (WebSocket) Data / cache

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.

03 Concepts & Data Model

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.

TermMeaning
OperatorA 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.
GroupA persistent, members-only MUC room node@conference, titled with the group's display name, with message logging enabled.
MembershipAn operator added to a group (operator_groups row) is made an affiliated MUC admin of the group's room.
Temp roomA 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.
MucSubCustom 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.
AffiliationMUC 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.
OutcastRevokes 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.
SlugName → lowercased alphanumeric, 2–30 chars (a valid XMPP localpart). Names that don't produce a valid localpart are rejected (422).
operatorsoperators table
PK idUUID
nameVARCHAR · NOT NULL
usernameVARCHAR · NOT NULL
emailVARCHAR · NOT NULL
groupsgroups table
PK idUUID
nameVARCHAR · NOT NULL
nodeVARCHAR · NOT NULL
serviceVARCHAR · NOT NULL
operator_groupsjunction · membership
PK operator_idFK → operators.id
PK group_idFK → groups.id

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

operator JID johndoe@localhost group room supportteam@conference temp room <userUUID>_<groupUUID>@conference customer nick room@conference/Jane Doe

Derivation

display name→slugify→localpart→XMPP user

"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.
04 API Reference

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

MethodPathDescription
POST/operatorsRegister an operator: creates the XMPP user and an operators row
GET/operatorsList all operators (auth-gated)
GET/operators/{operatorId}/groupsList 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:

request
{ "name": "John Doe", "email": "john@example.com", "password": "optional" }
201 response
{ "id": "…", "name": "John Doe", "email": "john@example.com",
  "xmppUser": "johndoe", "initialPassword": "…" }

Groups

MethodPathDescription
POST/groupsCreate a group: persistent MUC room + groups row
GET/groupsList all groups (Redis cache, 5 min TTL, evicted on create/delete)
GET/groups/{groupId}/operatorsList 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)
POST /groups → 201
{ "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.

MethodPathDescription
POST/chatroomCreate temp room <user>_<groupId>: user is member+subscribed, every operator of the group is admin+subscribed (urn:xmpp:mucsub:nodes:messages)
POST/chatroom/joinOperator joins the room: all other operators of the group are set to outcast
POST/chatroom/transferTransfer to another operator: new operator admin+subscribed, previous operator outcast
POST /chatroom → 201
{ "user": "c04582c4-…", "name": "Jane Doe",
  "groupId": "c7fc5856-…", "service": "conference" }
→
{ "room": "c04582c4-…_c7fc5856-…", "service": "conference" }
POST /chatroom/join → 200
{ "operatorId": "…", "groupId": "…", "room": "c04582c4-…_c7fc5856-…" }
POST /chatroom/transfer → 200
{ "room": "c04582c4-…", "operatorId": "…", "previousOperatorId": "…",
  "service": "conference" }

Login checks

MethodPathDescription
GET/operator/loginVerify an operator's Basic auth credentials via ejabberd check_password
GET/admin/loginVerify 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.

error body
{ "status": 409, "code": "conflict", "message": "duplicate slug", "fields": { "name": "…" } }
StatusMeaning
400Validation errors
401Unauthorized (login / auth-gated)
404Not Found
409Conflict (duplicate slugs / memberships)
422Unprocessable Entity (invalid slug)
5xxUpstream ejabberd failures proxied with the original status code
05 Admin Console

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

WhereVariableDefaultPurpose
.env.localAPI_BASE_URLhttp://localhost:8080/api/v1Kotlin 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

app/ ├── api/proxy/[...path]/route.ts # server-side proxy to the Kotlin API ├── login/ # admin login page └── (panel)/ # auth-gated shell (sidebar + guard) ├── page.tsx # dashboard ├── operators/page.tsx # operators CRUD + view-groups └── groups/page.tsx # groups CRUD + member management components/ # modal, toasts, icons… lib/ # api client, auth context, types

Out of scope: the temp-room endpoints (/chatroom, /join) are conversation-side and are not part of the admin surface.

06 Operator Console

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

Next.js 16.4.3 · App Router React 19 · TypeScript Bootstrap 5.3.8 Strophe 5.0.0

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. 1 Customer writes

    A temp-room message reaches the MUC; MucSub republishes it as a pubsub event to subscribed admins.

  2. 2 Card lights up

    The operator subscribed to the group MUC receives the event and a call card appears in the queue.

  3. 3 Accept

    POST /chatroom/join — operator becomes MUC admin of the temp room; all other operators are outcast.

  4. 4 Chat 1:1

    The operator chats with the customer in a draggable conversation window; the rest of the group is outcast.

  5. 5 Transfer

    POST /chatroom/transfer — new operator becomes admin + subscribed; the previous operator is outcast.

  6. 6 Handoff

    The new operator's window takes over; the MucSub subscription list moves with the affiliation.

  7. 7 Close

    The conversation is closed in the UI; history remains capped in sessionStorage for the tab.

Configuration

VariableDefaultPurpose
API_BASE_URLhttp://localhost:8080/api/v1Kotlin API base (server-side proxy target)
NEXT_PUBLIC_XMPP_WS_URLws://localhost:5280/xmpp-websocketejabberd WebSocket endpoint for Strophe
NEXT_PUBLIC_XMPP_DOMAINlocalhostBare-JID domain
NEXT_PUBLIC_XMPP_SERVICEconferenceMUC service for group/temp rooms

Scripts

ScriptWhat it does
npm run devNext.js dev server (port 3000)
npm run buildProduction build (App Router)
npm run lintESLint — baseline: 1 error + 1 warning are intentional (kept so CI diff is stable)
npm run strophe:testRuns the strophe-test/ harness (below)

Layout

app/ ├── api/proxy/[...path]/route.ts # server-side API proxy ├── login/page.tsx # operator login └── (desk)/ # auth-gated agent desktop └── page.tsx # queue, windows, transfer actions lib/xmpp/ # Strophe connection, MucSub subscribe, presence strophe-test/ # Node harness (scripts + fixtures)

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.

07 Customer Bubble

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):

html
<!-- 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

Keydata-* attributePurpose
apiBasedata-api-baseKotlin API base — used for /customers + /chatroom
operatorGroupdata-operator-groupGroup UUID the customer's temp room belongs to
xmppUrldata-xmpp-urlejabberd WebSocket endpoint
xmppDomaindata-xmpp-domainBare-JID domain (localhost)
xmppServicedata-xmpp-serviceMUC service (conference)

Programmatic API — window.OpenPlaud

MemberBehavior
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
stateRead-only lifecycle: idle → connecting → connected → closed

How it works

  1. 1 Register

    On first open the bubble posts POST /customers and gets a one-time password for the temp account.

  2. 2 Room

    POST /chatroom creates the temp room <userUUID>_<groupUUID>@conference; the customer joins as member+subscribed.

  3. 3 Session

    Strophe connects to xmppUrl with the temp credentials, sends the initial $pres(), joins the MUC.

  4. 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. 5 Handoff

    First message lights the operator's call card; from there the operator console takes over (join / transfer).

Customer API contract

http
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

/ · pre-configured demo (group 18c4c671-…) /select · pick group, then bubble
shell
npm run build:bubble   # runs scripts/build-bubble.mjs → public/openplaud.js
08 XMPP Protocol

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.

GotchaWhy it bites
Handlers must return trueA handler that returns false/undefined gets its stanza dropped — the message "never arrives".
Connection is not a root exportThe namespace changed in 5.x; import/instantiate it the documented way or the connection silently no-ops.
sendIQ auto-ids, raw send doesn'tIQs fired via send() need an explicit id or the reply never matches the request.
Initial $pres() requiredNo 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 rightsAfter an outcast, the list IQ answers 403 — that's the server confirming the drop.

Call lifecycle — step player

Press Play to walk a customer's first message through to a transfer, or step through manually.

Step 0 / 10
  1. 1 · Registercustomer → APIPOST /customers

    The bubble creates the temp account and receives a one-time password.

  2. 2 · Create roomcustomer → APIPOST /chatroom

    Temp MUC <userUUID>_<groupUUID>@conference is created; customer joins as member+subscribed.

  3. 3 · XMPP connectcustomer → ejabberdws + $pres()

    Strophe opens the WebSocket and sends the initial presence; the stream is authorized.

  4. 4 · First messagecustomer → MUCroom message

    The customer's first line lands in the temp room; MucSub republishes it as a pubsub event.

  5. 5 · Card lights upoperator ← MUCpubsub event

    An operator subscribed to the group MUC receives the event; a call card appears in the queue.

  6. 6 · Acceptoperator → APIPOST /chatroom/join

    The operator becomes MUC admin of the temp room; every other operator is outcast.

  7. 7 · Chat 1:1customer ↔ operatorMUC messages

    Only that operator can see the conversation now; the rest of the group is outcast.

  8. 8 · Transferoperator → APIPOST /chatroom/transfer

    A new operator becomes admin+subscribed; the previous operator is outcast.

  9. 9 · Subscription handoffejabberdMucSub

    The old operator's MucSub subscriptions are dropped server-side; the new one is live (old list now 403).

  10. 10 · Closeoperator → UIwindow close

    The conversation window closes; history stays in sessionStorage, capped at 500 entries.

09 Deployment

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

ServicePortNotes
PostgreSQL5432Source of truth — operators, groups, operator_groups
Redis6379Sessions/caches for the API
ejabberd 26.95280mod_http_api + conference MUC + MucSub module; WS at /xmpp-websocket
Kotlin API8080/api/v1 — REST surface + mirror into ejabberd
Frontends3000admin / operator / client (all Next.js dev)

Database

sql
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. 1 PostgreSQL & Redis

    Both up before anything else — the API refuses to start without a reachable DB.

  2. 2 ejabberd

    With mod_http_api on 5280, the conference MUC service, and the MucSub module loaded.

  3. 3 Kotlin API

    ./gradlew bootRun → http://localhost:8080/api/v1. It reconciles the DB into ejabberd on startup.

  4. 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

KeyDefaultPurpose
spring.datasource.urljdbc:postgresql://localhost:5432/openplaudPostgreSQL JDBC URL
spring.data.redis.hostlocalhost:6379Redis endpoint
openplaud.ejabberd.urlhttp://localhost:5280/apimod_http_api base
openplaud.ejabberd.useradmin@localhostManagement JID
openplaud.ejabberd.passwordadminManagement password (dev default)

Project layout & tooling

openplaud-srv-admin/ ├── src/main/kotlin/ │ ├── api/ # REST controllers (/api/v1) │ ├── ejabberd/ # mod_http_api client + MucSub glue │ ├── db/ # Flyway DDL + repositories │ └── OpenPlaudApp.kt # Spring Boot entrypoint └── build.gradle.kts
shell
./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
10 Test & Troubleshooting

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

PartWhat it does
Node scriptsHeadless drivers: connect → $pres() → MUC join → MucSub subscribe → message round-trip → outcast, each step asserted.
FixturesRecorded stanzas — the <subscribe> IQ, the double-wrapped MucSub delivery, the 403 list reply — reused as expected outputs.
Runnpm run strophe:test
shell
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

SymptomUsual cause → fix
Login 401 even with right credentialsejabberd check_password disagrees with the API — the operator was never mirrored (API down at create time). Re-run the API boot reconcile.
Proxy answers 502The Kotlin API on :8080 is down — start it (boot order: PG → Redis → ejabberd → API).
No call card after customer writesOperator 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 renderedHandler 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 403Expected after an outcast — the server dropped the subscriptions on transfer. Not an error to chase.
Temp room never createdPOST /chatroom got a 404 customer (already deleted → 204) or the group UUID in the bubble config is stale — re-issue POST /customers.