Flows category icon
App Builder
Intermediate
Generated

Add Real-Time Presence Indicators to a Chat App with WebSockets

A step-by-step flow for implementing real-time online, offline, and typing presence in a chat app using WebSockets, including backend presence tracking, frontend updates, reconnect handling, and verification.

10 steps50 verify checks60-120 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

AI-generated draft. This flow was created by the custom generator. Review the steps and Definition of Done before running - curated flows in the library are hand-crafted and research-backed.

The Route

0/10 verified
01

Inspect the existing chat architecture and choose presence data flow

Establish where WebSocket connections, user identity, and chat participants already exist so presence can be added without breaking the app.

02

Define the presence event contract and server-side state model

Create a reliable event schema and in-memory or persistent tracking model before implementation.

03

Implement authenticated WebSocket connection handling on the server

Ensure the backend can identify users on socket connect and maintain a real presence registry.

04

Broadcast presence changes to relevant chat participants

Send online and offline updates only to users who should see them.

05

Add initial presence sync and frontend presence state management

Ensure the UI has the correct presence map when the chat screen first loads and stays updated from socket events.

06

Render presence indicators in the chat UI

Display presence in conversation headers, user lists, or message panes using the live presence state.

07

Implement conversation-scoped typing indicators

Add real-time typing state that appears only in the relevant conversation and clears correctly.

08

Handle reconnects, stale sockets, and edge cases

Make presence resilient during refreshes, temporary network drops, and multi-tab usage.

09

Test with two or more real clients and instrument debug output

Verify that presence is actually driven by backend socket events across separate clients.

10

Fix discovered issues and clean up implementation details

Resolve mismatches, remove temporary hacks, and leave a maintainable presence system.

Every step ends at a Verify Gate. Do not continue until every check passes.

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
The project is an existing chat application that already supports user accounts, conversations, and message sending. The goal is to add real-time presence indicators so users can see whether other users are online, recently active, or currently typing in a conversation.

GOAL:
Implement real working presence indicators in the chat app using WebSockets, with backend-tracked online state, frontend subscription and rendering, typing indicators, disconnect handling, and testable real-time behavior across multiple clients.

REQUIREMENTS:
- Use WebSockets for real-time presence updates instead of polling
- Track whether a user is online based on active socket connections
- Broadcast presence changes to relevant chat participants
- Show online or offline state in the chat UI
- Optionally show last seen or recently active timestamp when offline
- Support typing indicators per conversation in real time
- Handle multiple tabs or multiple devices for the same user correctly
- Do not mark a user offline if they still have another active connection
- Handle reconnects and stale disconnects safely
- Initialize presence state correctly when the chat view loads

CONSTRAINTS:
- Must integrate into the existing chat app rather than replacing it
- Presence must reflect real backend connection state, not fake UI-only toggles
- Typing indicators must expire or clear correctly when typing stops or disconnect happens
- Do not break existing messaging flows while adding WebSocket presence

DEFINITION OF DONE:
- When User A opens the app, User B sees User A become online without refreshing
- When User A closes their last active tab or disconnects, User B sees User A become offline or last seen
- If User A opens two tabs, closing one tab does not mark them offline
- Typing indicators appear only inside the relevant conversation and disappear when typing stops or the user disconnects
- Presence state loads correctly on initial page load before or immediately after socket connection is established
- Reconnect after temporary network loss restores socket connection and correct presence state
- Backend logs or debug output confirm presence events are driven by real socket connect and disconnect activity

COMMON FAILURES TO AVOID:
- AI adds a green dot UI but never connects it to real WebSocket events
- AI marks users offline on any disconnect without checking for other active connections
- AI implements typing indicators that never clear or clear globally across all chats
- AI only updates local client state and does not broadcast to other participants
- AI uses polling or fake timers instead of actual socket presence tracking

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More App Builder flows that share ground with this one.

Flows category icon
App Builder
Generated

Build a Habit Tracker React App

A step-by-step flow for building a real habit tracker app in React with working habit creation, daily check-ins, streak tracking, persistence, validation, and basic testing.

01Set up the app structure and data model
02Implement real habit state and habit creation
03Render the habit list with empty states

+6 more steps to Done

Best foryour first pass at this - no prior setup assumed

9 steps45-90 minutesBeginner
Flows category icon
App Builder
Generated

Add Team Invites to a SaaS App

Build a real team invitation system for a SaaS app, including invite creation, email/share flow, acceptance, membership creation, role assignment, validation, and end-to-end testing.

01Audit Existing Team, User, and Auth Models
02Add Invitation Data Model and Migration
03Implement Secure Invite Creation API

+7 more steps to Done

Best forbuilders who have shipped a basic app before

10 steps60-120 minutesIntermediate
Flows category icon
App Builder
Generated

Add a Working Team Invite System to a SaaS App

Build a real invite flow for a SaaS app so existing users can invite teammates by email, store invite records, validate tokens, accept invitations, and join the correct workspace with proper permissions.

01Audit the current auth and workspace model
02Add the invite data model and migration
03Build secure invite creation on the server

+6 more steps to Done

Best forbuilders who have shipped a basic app before

9 steps60-120 minutesIntermediate

Made with Emergent