https://github.com/fabiconcept/secret-room-backend
A secure, lightweight Node.js server handling encrypted messaging, file sharing, custom usernames, and self-destructing servers.
https://github.com/fabiconcept/secret-room-backend
anonymous anonymous-chat chat-app secret-room
Last synced: 10 months ago
JSON representation
A secure, lightweight Node.js server handling encrypted messaging, file sharing, custom usernames, and self-destructing servers.
- Host: GitHub
- URL: https://github.com/fabiconcept/secret-room-backend
- Owner: fabiconcept
- Created: 2025-03-06T12:48:45.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-23T22:55:17.000Z (about 1 year ago)
- Last Synced: 2025-05-23T23:32:10.163Z (about 1 year ago)
- Topics: anonymous, anonymous-chat, chat-app, secret-room
- Language: TypeScript
- Homepage:
- Size: 6.92 MB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# ๐ต๏ธโโ๏ธ Secret Room - Backend
Built with these tools and technologies:
**Secret Room** is a fully anonymous, real-time chat web app that lets users create temporary servers and invite others to chat without ever revealing their identity. This is the backend service powering the chat experience, built with **Node.js**, **Express**, **MongoDB**, and **Socket.io**.
> ๐ก This is my first personal Node.js backend project. It focuses heavily on secure communication, temporary server lifecycles, and anonymous user management.
---
## ๐ Features
- ๐ JWT Authentication for secure access
- ๐ง Anonymous user identification via fingerprinting
- ๐ฌ Real-time chat between host and guests (powered by Socket.io)
- โก Instant join/leave/typing notifications
- โณ Self-destructing servers based on a lifespan
- ๐จ Global & Unique server invitation system
- ๐ป Deterministic anonymous usernames per server
- ๐ฆ Clean modular structure: Models, Routes, Controllers, Middleware
---
## ๐ Project Structure
```
.
โโโ controllers/
โ โโโ userController.js
โ โโโ serverController.js
โ โโโ messagesController.js
โโโ middleware/
โ โโโ authenticateJWT.js
โโโ models/
โ โโโ User.js
โ โโโ Server.js
โ โโโ Message.js
โ โโโ Invitation.js
โโโ socket/
โ โโโ socketHandler.js
โโโ routes/
โ โโโ ...
```
---
## ๐ฆ Tech Stack
- **Node.js**
- **Express**
- **MongoDB** (Mongoose)
- **Socket.io** for real-time communication
- **JWT** for authentication
- **UUID + Custom Encryption** for anonymous ID and secure communication
---
## ๐ Authentication
- Uses JWT tokens to secure private routes
- Fingerprinting used to generate a unique ID for users (without collecting sensitive info)
---
## ๐ฌ Real-time Communication (Socket.io)
- Users join a room corresponding to the serverId
- On joining, a deterministic **anonymous username** is generated using a `serverId-userId` combo (see below)
- Events include:
- `user:join` โ Notify server members of a new user
- `user:leave` โ Broadcast when a user disconnects
- `user:active` - Broadcast when the user is active
- `server:deleted` - Broadcast when the server is deleted
- `message:send` โ Relay messages between users
- `message:read` โ Relay messages between users
- Socket connections are JWT-authenticated and scoped to server rooms
---
## ๐ป Username Generation (Anonymity)
Usernames are deterministically generated per server using a salted pattern based on the combination: `serverId-userId`.
```ts
// utils/generateUsername.ts
export function generateUsername(salt: string): string {
// uses custom hash + either consonant-vowel or alphanumeric pattern
}
```
### Why this matters:
- Ensures each user has a **unique, anonymous identity** _per server_
- Zero chance of real user data leaks
- No usernames are ever reused across different servers
---
## ๐งช API Endpoints
### ๐ Authentication Required
| Method | Endpoint |
|--------|----------|
| `POST` | `/` โ Create a new server |
| `POST` | `/invitation/:globalInvitationId` โ Join with a global invite |
| `POST` | `/unique-invitation/:inviteCode` โ Join with a unique invite |
| `GET` | `/:serverId` โ Get server data |
| `GET` | `/:serverId/active-users` โ Get current active users |
| `GET` | `/:serverId/generate-unique-server-invitation-id` โ Generate a unique invite |
| `GET` | `/:serverId/messages` โ Fetch messages in the server |
| `DELETE` | `/:serverId` โ Delete a server |
---
## ๐งฌ Mongoose Models
### ๐งโ๐ป User
```ts
userId, isOnline, lastSeen, currentServer, createdAt, bgColor, textColor
```
### ๐ฌ Message
```ts
serverId, senderId, receiverId, content, attachmentUrl, sent, readBySender, readByReceiver
```
### ๐ Server
```ts
serverId, owner, serverName, salt, globalInvitationId, expiresAt, approvedUsers, allUsers
```
### ๐๏ธ Invitation
```ts
inviteCode, used, serverId, expiresAt
```
---
## โ๏ธ Setup Instructions
```bash
# 1. Clone the repo
git clone [https://github.com/your-username/secret-room-backend](https://github.com/fabiconcept/secret-room-backend.git)
# 2. Navigate into the folder
cd secret-room-backend
# 3. Install dependencies
npm install
# 4. Create a `.env` file and add:
# PORT
# HOST
# CORS_ORIGIN
# JWT_SECRET
# MONGODB_URI
# API_KEY
# 5. Run the server
npm run dev
```
---
## ๐ Author
Made with โค๏ธ by [Favour Tochukwu Ajokubi](https://github.com/FavourBE)
---
## ๐ก๏ธ License
This project is open-source and available under the [MIT License](LICENSE).