Realtime Support Chat
Build the backend for a customer support chat with Spring Boot: website visitors open a chat, support agents see waiting conversations and pick them up, and messages flow instantly both ways over WebSockets (using STOMP, a simple messaging protocol on top of WebSockets). Agents see who's online, conversations are assigned so two agents never answer the same customer, and every message is saved in PostgreSQL so conversations can be reopened and reviewed. Customers who lose connection get the messages they missed when they return. You'll learn Spring WebSocket with STOMP, topics and user-specific destinations, securing WebSocket connections, presence tracking, saving and paging history with Spring Data JPA, and testing real-time code.
- Estimate
- ~12.5h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Spring Boot · PostgreSQL
Project roadmap
- 01
Define the chat flows
~1.5hWrite DESIGN.md: a conversation is created by a visitor (with a random visitor token), waits in a queue, is claimed by one agent, and is closed by the agent. List the STOMP destinations (sending to /app/conversations/{id}/send, subscribing to /topic/conversations/{id}, and /topic/queue for agents), the message format, and how visitors and agents are identified. Done when: DESIGN.md covers every flow and destination.
- 02
Store conversations and messages
~2hCreate a Spring Boot project with Web, WebSocket, Data JPA, Security, Validation and PostgreSQL, using Flyway for the schema. Model agents, conversations (visitor token, status waiting, active or closed, and the assigned agent) and messages (conversation, sender type, text, time and a client id for avoiding duplicates). Add a REST endpoint for paged history. Done when: conversations and messages can be saved and history is returned in pages.
- 03
Send messages over WebSockets
~2.5hConfigure a STOMP endpoint with the simple broker. Messages sent to a conversation are validated (length, and that the sender belongs to that conversation), saved, ignored when their client id was already saved, then broadcast to the conversation's topic. Write a simple HTML page for visitors and one for agents using the stomp.js client. Done when: a visitor and an agent can chat in real time.
- 04
Assign conversations to agents
~2hAgents log in (Spring Security with a form or basic login) and see waiting conversations live on /topic/queue. Claiming a conversation uses an update with a condition on the status (or optimistic locking), so if two agents claim at the same moment only one succeeds and the other is told. Secure the WebSocket handshake and check permissions on subscriptions with a ChannelInterceptor, so only the assigned agent and the visitor can join a conversation. Done when: two agents claiming the same conversation results in exactly one owner.
- 05
Track presence and missed messages
~2hTrack agents' online status from session connect and disconnect events (SessionConnectedEvent and SessionDisconnectEvent), and show online agents in the agent page. When a visitor reconnects, fetch messages after the last one they saw from the history endpoint. Tell the visitor when their agent disconnects, and return a conversation to the queue if the agent doesn't return within a few minutes. Done when: presence is accurate, and reconnecting shows missed messages.
- 06
Test it
~2.5hWrite integration tests with a real PostgreSQL (Testcontainers) and Spring's WebSocketStompClient: sending and receiving messages, duplicate client ids ignored, only authorized subscribers can join a conversation, two agents claiming at once, and history paging. Done when: all tests pass.
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack