A real-time chat application built with React, TypeScript, and Ably's LiveObjects + Chat SDK. Features a dual-panel interface with comprehensive profile management, online presence indicators, and intelligent unread message handling.
- Node.js 18+ and npm
- Ably account with API key
- Clerk account for authentication
git clone <repository-url>
cd whatsapp-chat
npm install
Create a .env
file in the root directory with the following variables:
# Ably Configuration
VITE_ABLY_API_KEY=your_ably_api_key_here
# Clerk Authentication
VITE_CLERK_PUBLISHABLE_KEY=pk_test_your_clerk_publishable_key
CLERK_SECRET_KEY=sk_test_your_clerk_secret_key
Getting your Ably API Key:
- Sign up at ably.com
- Create a new app in the Ably dashboard
- Go to the "API Keys" tab
- Copy the API key (it should start with something like
ALwA2Q.
) - Ensure the key has the following capabilities:
publish
subscribe
presence
history
object-subscribe
object-publish
Getting your Clerk Keys:
- Sign up at clerk.com
- Create a new application
- Go to "API Keys" in the dashboard
- Copy the "Publishable key" and "Secret key"
npm run dev
The application will be available at http://localhost:5173
(or another port if 5173 is busy).
# Build for production
npm run build
# Preview production build
npm run preview
# Run linter
npm run lint
- Frontend: React 19 with TypeScript and Vite
- Real-time Communication: Ably platform
- LiveObjects for room metadata and user profiles
- Chat SDK for messaging features
- Presence API for online status
- Authentication: Clerk with automatic profile synchronization
- UI Framework: Custom Ably Chat React UI Components
- Styling: Tailwind CSS with dark/light theme support
The application uses a dual-client architecture for optimal performance:
- Rooms List Client: Manages LiveObjects for room metadata on private channels
- Chat Window Client: Handles active chat conversations via Chat SDK
User Authentication (Clerk)
↓
Profile Creation (profile:userId channel)
↓
Room List Management (roomslist:userId channel)
↓
Chat Messaging (room:roomId$$chat channel)
↓
Real-time Updates (LiveObjects + Chat SDK)
Data Layer:
ProfileContext
: Manages user profile data from LiveObjectsRoomsList
: Handles room metadata and unread countsChatWindow
: Active chat interface with full messaging features
UI Layer:
RoomListItem
: Reusable component for displaying users and roomsUserProfileHeader
: Profile display with home navigationOnlinePresence
: Shows who's currently online
- Room Metadata:
roomslist:userId
(private per user) - User Profiles:
profile:userId
(public profile data) - Chat Messages:
room:roomId$$chat
(via Chat SDK) - Presence:
presence
(global presence channel)
Room IDs follow the pattern room:{hash}
where the hash is generated from sorted participant user IDs. This ensures consistent room identification across users.
Chat Functionality:
- Real-time messaging with typing indicators
- Message reactions, editing, and deletion
- Auto-room creation when visiting URLs
- URL-based navigation and deep linking
Profile and Presence:
- Real user profiles fetched from Ably LiveObjects
- Online presence indicators with green status dots
- Profile-based avatars throughout the application
- Live "Who's Online" list
Smart User Experience:
- Intelligent unread count management
- Automatic counter reset when user is active in rooms
- Focus detection for better unread handling
- Clean message previews with proper sender names
- Recipient-aware message input placeholders
User Interface:
- Consistent RoomListItem components across all user displays
- Blue unread badges positioned on the right
- Green online indicators on profile avatars
- Home navigation button for easy access
- Responsive design for different screen sizes
- Start the development server with
npm run dev
- Note the generated
demo-user-*
ID in the browser console - Open the application in multiple browser tabs/windows to test real-time features
- Use the browser's developer tools to monitor network requests and console logs
- For API testing, see
docs/curl_requests.md
for examples
src/
├── components/ # React components
│ ├── ChatWindow.tsx # Main chat interface
│ ├── RoomsList.tsx # Sidebar with room list
│ └── OnlinePresence.tsx
├── contexts/ # React contexts
│ └── ProfileContext.tsx
├── hooks/ # Custom React hooks
├── utils/ # Utility functions
├── ably-ui-kits/ # UI component library
└── main.tsx # Application entry point
docs/
└── curl_requests.md # API testing examples
- The application uses Vite's environment variable system (variables must start with
VITE_
) - Profile data is automatically synced on login and cached for performance
- Unread counters are managed through LiveObjects and reset intelligently based on user activity
- The UI components are imported from a local
ably-chat-react-ui-components
package
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature
) - Make your changes and test thoroughly
- Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature
) - Create a Pull Request
MIT License - see LICENSE file for details.