AlphaChat has evolved into a fully synchronized, multi-platform ecosystem. Both the Web (AlphaChat-V2) and Mobile (Alpha-Chat-Native) applications now operate in perfect harmony, powered by a single shared backend infrastructure.
| Aspect | AlphaChat-V2 (Web) | Alpha-Chat-Native (Mobile) |
|---|---|---|
| Backend | Express 5 + MongoDB | Express 5 + MongoDB (via API) |
| Frontend | React 19 + Redux | Jetpack Compose |
| Real-time | Socket.IO | Socket.IO |
| Auth | GitHub OAuth | GitHub OAuth (via Web View/API) |
| Storage | Cloudinary | Cloudinary |
| Sync | Real-time | Real-time + Offline-First (Room) |
Important
Unified Architecture: The "Two Independent Systems" model has been deprecated. The mobile app has successfully migrated from Firebase to the unified Express/MongoDB backend, ensuring consistent data, authentication, and real-time communication across all platforms.
flowchart TB
subgraph Frontend["Frontend (React 19)"]
App[App.jsx]
Redux[Redux Store]
Socket[useSocket Hook]
Pages[Pages: Chat, Login, Profile]
end
subgraph Backend["Backend (Express 5)"]
Server[index.js]
SocketIO[Socket.IO Server]
Routes[API Routes]
Controllers[Controllers]
Middleware[Auth Middleware]
end
subgraph Database["MongoDB"]
User[(User)]
Channel[(Channel)]
ChannelMessage[(ChannelMessage)]
DirectMessage[(DirectMessage)]
Conversation[(Conversation)]
end
subgraph External["External Services"]
GitHub[GitHub OAuth]
Cloud[Cloudinary]
end
App --> Redux
App --> Socket
Socket <--> SocketIO
Pages --> Routes
Routes --> Middleware --> Controllers
Controllers --> Database
Controllers --> Cloud
Server --> GitHub
The Web Backend defines the source of truth for all data models (User, Channel, Message) and real-time events (directMessage, channelMessage, typing, onlineUsers).
The mobile application has been re-architected to act as a proper client of the main backend, mirroring the web client's capabilities while adding offline reliance.
flowchart TB
subgraph UI["UI Layer (Jetpack Compose)"]
Screens[Screens]
ViewModels[ViewModels]
Nav[Navigation Routes]
end
subgraph Data["Data Layer"]
Repo[ChatRepository]
SocketManager[SocketManager]
Retrofit[AlphaChatApi]
LocalDB[Room Database]
end
subgraph Backend["Shared Backend"]
API[REST API]
SocketServer[Socket.IO]
end
Screens --> ViewModels
ViewModels --> Repo
Repo --> Retrofit
Repo --> SocketManager
Repo --> LocalDB
Retrofit <--> API
SocketManager <--> SocketServer
The mobile app achieves harmony with the web platform through a three-pronged synchronization strategy:
The mobile app uses Retrofit to consume the same REST endpoints as the web frontend.
- Tools: Retrofit, Moshi, OkHttp
- Endpoints:
api/auth/me,api/users,api/channels,api/messages/dm/... - Authentication: Usage of session cookies shared with the backend.
The SocketManager class in the mobile app listens to the exact same events as the React frontend, ensuring instant updates.
| Event | Mobile Action | Web Action | Result |
|---|---|---|---|
directMessage |
Stores in Room, updates UI | Updates Redux, updates UI | Seamless conversation sync |
channelMessage |
Stores in Room, updates UI | Updates Redux, updates UI | Unified group chat experience |
onlineUsers |
Updates live list | Updates live list | Consistent presence data |
userTyping |
Shows "Typing..." | Shows "Typing..." | Real-time awareness |
To handle mobile network flakiness, the app implements a "Single Source of Truth" pattern using the Room database.
- Load: UI observes Room database flow.
- Fetch: Repository fetches fresh data from API.
- Cache: Fresh data is inserted into Room.
- Update: Room emits new data to UI automatically.
Defines the contract with the unified backend.
interface AlphaChatApi {
@GET("api/auth/me")
suspend fun getCurrentUser(): CurrentUserResponse
@POST("api/messages/dm/{recipientId}")
suspend fun sendDirectMessage(...): ApiResponse<MessageResponse>
@GET("api/channels")
suspend fun getAllChannels(): ApiResponse<ChannelsListResponse>
}Handles the heartbeat of the application.
socket.on("directMessage") { args ->
val message = parseDirectMessage(args)
_directMessages.tryEmit(message)
}The harmonization was achieved through the following key changes:
- Backend Migration: We abandoned the Firebase-only architecture for the mobile app and pointed it to the
onrender.comExpress backend. - Model Alignment: The mobile
MessageandUserdata classes were refactored to match the MongoDB schemas (e.g., using_idinstead ofuid,usernameinstead of justemail). - Auth Consolidation: Adopted a session-based auth flow compatible with the backend's GitHub OAuth, allowing users to log in on mobile and access the same profile as on web.
- Socket.IO Adoption: Replaced Firestore listeners with a custom
SocketManagerto handle the specific event protocol defined by the web backend.
Both applications now "speak the same language." A message sent from the web app:
- Goes to the Express Backend.
- Is saved in MongoDB.
- Is broadcast via Socket.IO.
- Is received by the Mobile App via
SocketManager. - Is displayed instantly to the user on their phone.
This completes the transition to a unified architecture.