Welcome to the comprehensive technical documentation for Throne Chat, a premium, state-of-the-art real-time messaging system built with a high-performance distributed architecture.
Throne Chat offers a seamless, premium dark/light mode experience across iOS, Android, and Web platforms with instant messaging, advanced status receipts, interactive media uploads, and live user presence indicators.
Throne Chat is structured as a robust, modern three-tier architecture:
graph TD
A[Mobile Frontend - Expo SDK 54] -->|REST / HTTPS| C(Express Gateway Server)
B[Web Frontend - React Vite] -->|REST / HTTPS| C
A -->|WS / Socket.io| D(Real-time Socket.io Coordinator)
B -->|WS / Socket.io| D
C -->|Mongoose ODM| E[(MongoDB Database)]
D -->|Mongoose ODM| E
D -->|Key-Value Store| F[(Redis Cache Server)]
- Built with React Native & Expo SDK 54 targeting iOS and Android natively.
- High-quality fluid animations using
expo-hapticsand responsive screen mechanics. - Centrally-managed dynamic safe-area offsets utilizing
useSafeAreaInsetsto ensure the layout never clashes with top status bars, camera notches, or dynamic islands.
- Engineered with React and Vite for super-fast hot module reloading and lightweight production builds.
- Premium styling using CSS variables and curated modern color schemes.
- Node.js & Express gateway providing scalable HTTP REST APIs.
- Socket.io coordinator managing persistent TCP connections for instant real-time events.
- MongoDB & Mongoose ODM storing durable transactional data (Users, Chats, Messages).
- Redis Cache Server acting as a high-speed memory coordinator for tracking active socket IDs, mapping user sessions, and keeping track of instant online presence arrays.
- Fully distributed messaging with instant sub-100ms delivery using persistent websockets.
- Localized haptic feedback cues triggered upon receiving new direct messages.
- Fully integrated gallery image and video selection using
expo-image-picker. - Auto-boundary Multipart Uploading: Re-architected frontend file uploading via native standard
fetchAPIs. The runtime dynamically formulates headers with boundary keys, avoiding standard multipart parsing bugs on the backend. - Inline media rendering for loaded assets with beautifully styled adaptive media preview bubbles.
- Beautifully stylized grey and blue checkmarks reflecting the accurate delivery state:
✓Sent: The message has successfully reached the gateway database.✓✓(Grey) Delivered: The recipient's active socket is connected and has acknowledged receiving the packet.✓✓(Blue#34B7F1) Read: The recipient has actively opened the chat room containing the message.
- Real-time user typing notification triggers (
typinganduser_typingsocket events). - Synchronized
selectedChatRefcallbacks ensure that state closures are bypassed. - If the other user is typing, a sleek green
typing...label displays instantly inside the active chat's header.
- Real-time online state arrays managed in MongoDB and Redis.
- If a user is online: shows green
Onlinebadge. - If a user goes offline: prints the exact date they disconnected:
Last seen today at 04:30 PMorLast seen on May 20 at 12:00 PM.
- Dynamic UI coloring utilizing a responsive React Context provider (
useTheme). - Instant toggle transitions between Sleek Dark Mode (vibrant surface tones, high readability) and Premium HSL Light Mode.
Ensure you have the following installed on your machine:
- Node.js (v18+)
- MongoDB (Running locally or via MongoDB Atlas)
- Redis Server (Running locally on
127.0.0.1:6379)
- Navigate into the backend directory:
cd backend - Install the server dependencies:
npm install
- Create a
.envfile in thebackend/directory:PORT=3000 MONGODB_URL=your_mongodb_connection_string JWT_SECRET=your_jwt_signing_secret_key REDIS_HOST=127.0.0.1 REDIS_PORT=6379
- Start the server:
npm start
- Navigate into the mobile directory:
cd APP_frontend - Install package dependencies:
npm install
- Create a
.envfile inAPP_frontend/to assign public environment parameters:EXPO_PUBLIC_API_URL=http://your_computer_local_ip_address:3000/api/v1
- Start the Metro Bundler with cleared cache:
npx expo start -c
- Scan the generated QR code using the Expo Go application on your physical device.
All API endpoints are prefixed with /api/v1.
| Method | Endpoint | Description | Headers |
|---|---|---|---|
POST |
/auth/signup |
Creates a new user profile. | None |
POST |
/auth/login |
Validates credentials and returns JWT token. | None |
GET |
/auth/users |
Lists all users for starting direct chats. | Authorization: Bearer <token> |
GET |
/auth/me |
Fetches the authenticated user's profile. | Authorization: Bearer <token> |
| Method | Endpoint | Description | Headers |
|---|---|---|---|
GET |
/chats |
Retrieves all active direct and group chats. | Authorization: Bearer <token> |
POST |
/chats/group |
Creates a new multi-participant group chat. | Authorization: Bearer <token> |
GET |
/chats/user/:userId |
Retrieves or initializes a direct chat with a user. | Authorization: Bearer <token> |
| Method | Endpoint | Description | Headers |
|---|---|---|---|
GET |
/messages/:chatId |
Retrieves the message log of a chat room. | Authorization: Bearer <token> |
| Method | Endpoint | Description | Headers |
|---|---|---|---|
POST |
/upload |
Receives multipart/form-data files and returns URLs. | Authorization: Bearer <token> |
Socket connection is authenticated using handshake tokens:
const socket = io(SOCKET_URL, {
auth: { token: JWT_TOKEN }
});send_message: Sends a new text or media message packet.{ "chatId": "65b4c102f9...", "text": "Hello!", "media": "http://...", // Optional "messageType": "image" // 'text' | 'image' | 'video' }typing: Notifies the recipient that the current user is active.{ "chatId": "65b4c102f9...", "receiverId": "65b4c09ef9...", "isTyping": true }mark_read: Marks a specific message as read.{ "messageId": "65b4c2ef09...", "chatId": "65b4c102f9..." }
receive_message: Broadcasts a new message in real-time to active participants.message_sent: Confirms to the sender that their packet was saved in the database.message_delivered: Informs the sender that their message reached the recipient's phone (✓✓grey tick).message_read: Informs the sender that the recipient has read the message (✓✓blue tick).user_typing: Broadcasts typing statuses dynamically to chat headers.online_users: Broadcasts an array of all currently online user IDs.
The system themes are organized in ThemeContext.js for premium visuals:
export const themes = {
light: {
background: '#FFFFFF',
surface: '#F2F2F7',
primary: '#007AFF', // Premium Royal Blue
text: '#000000',
textSecondary: '#8E8E93',
border: '#C6C6C8',
sentBubble: '#007AFF',
receivedBubble: '#E5E5EA',
sentText: '#FFFFFF',
receivedText: '#000000',
headerBackground: '#FFFFFF',
statusBar: 'dark'
},
dark: {
background: '#0F0F12', // Pure Sleek Obsidian Black
surface: '#1C1C1E', // Dark Metallic Slate
primary: '#0A84FF', // Premium Indigo Blue
text: '#FFFFFF',
textSecondary: '#8E8E93',
border: '#2C2C2E',
sentBubble: '#0A84FF',
receivedBubble: '#2C2C2E',
sentText: '#FFFFFF',
receivedText: '#FFFFFF',
headerBackground: '#1C1C1E',
statusBar: 'light'
}
};- Avoid committing
.envconfigurations: Make sure.envis listed inside.gitignorefiles at the root, frontend, and backend directories before push operations. - Dynamic Insets Compliance: When styling new headers or top-tier banners, avoid utilizing hardcoded layout heights. Always inherit safety parameters from
insets.topto keep screens fully responsive on modern iPhone notches and Android screens. - Socket Reference Management: When setting up socket callbacks that check active views, always map values to
React.useRefvariables to guarantee closures read updated states in real-time.