An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

![Project Snapshot](https://github.com/fabiconcept/secret-room-backend/blob/main/image.png)
# ๐Ÿ•ต๏ธโ€โ™‚๏ธ Secret Room - Backend



Last Commit
TypeScript Usage
Languages

Built with these tools and technologies:


Express
JSON
Socket.io
npm
Mongoose



.ENV
Nodemon
TypeScript
ts-node
Socket

**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).