A global chat application using Couchbase Lite with Sync Gateway for multi-device synchronization.
- 📱 Global chat visible to all users
- 🔄 Real-time sync across devices via Sync Gateway
- 💾 Offline-first with local Couchbase Lite database
- 🎨 Modern dark theme UI
- Android Studio (Arctic Fox or later)
- Couchbase Server (7.0 or later)
- Sync Gateway (3.0 or later)
The app works offline without Sync Gateway. Messages are stored locally in Couchbase Lite.
- Open the project in Android Studio
- Sync Gradle files
- Run on emulator or device
- Start chatting!
- Download Couchbase Server from https://www.couchbase.com/downloads
- Install and start the server
- Create a bucket named
chat - Create a user with access to the bucket
- Download Sync Gateway from https://www.couchbase.com/downloads
- Use the provided
sync-gateway-config.jsonconfiguration - Update the configuration with your Couchbase Server credentials
Edit sync-gateway-config.json:
{
"databases": {
"chat": {
"server": "couchbase://localhost",
"bucket": "chat",
"username": "your_couchbase_admin",
"password": "your_password",
"users": {
"user": {
"password": "password",
"admin_channels": ["*"]
}
}
}
}
}./sync_gateway sync-gateway-config.jsonSync Gateway will start on:
- WebSocket:
ws://localhost:4984/chat - Admin API:
http://localhost:4985
- Open the app
- Tap "Connect" button
- Configure the Sync Gateway URI:
- Android Emulator:
ws://10.0.2.2:4984/chat - Physical Device:
ws://YOUR_MACHINE_IP:4984/chat
- Android Emulator:
- Enter username:
user - Enter password:
password - Tap Connect
Use 10.0.2.2 instead of localhost to reach the host machine.
- Ensure device and server are on the same network
- Find your machine's IP address:
- macOS/Linux:
ifconfigorip addr - Windows:
ipconfig
- macOS/Linux:
- Use that IP in the Sync Gateway URI
Ensure port 4984 is open for WebSocket connections.
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Android App │ │ Sync Gateway │ │ Couchbase Server│
│ │ │ │ │ │
│ ┌─────────────┐ │ │ │ │ ┌─────────────┐ │
│ │ Couchbase │ │◄───►│ │◄───►│ │ chat │ │
│ │ Lite DB │ │ WS │ │ │ │ bucket │ │
│ └─────────────┘ │ │ │ │ └─────────────┘ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
{
"_id": "auto-generated",
"type": "chat_message",
"senderName": "User_abc123",
"senderId": "abc123",
"message": "Hello, world!",
"timestamp": 1705590000000
}- Check Sync Gateway is running
- Verify the URI (use
10.0.2.2for emulator) - Check firewall settings
- Verify Sync Gateway logs for errors
- Check user credentials
- Ensure
continuousreplication is enabled
- Clean and rebuild the project
- Check Couchbase Lite initialization in logcat
app/src/main/java/com/couchbase/android/getstarted/kotlin/
├── ChatAdapter.kt # RecyclerView adapter for messages
├── ChatMessage.kt # Data class for messages
├── DBManager.kt # Couchbase Lite database manager
├── GettingStartedApplication.kt # Application class with Koin DI
├── MainActivity.kt # Main chat activity
└── MainViewModel.kt # ViewModel with chat logic
Apache License 2.0