Random Connect is a full stack web application that lets users connect with strangers through one to one text or video chat. Users can also create an account to send private messages by searching usernames.
The project was built to explore real time communication in Go using WebSockets and WebRTC, while learning how Redis and PostgreSQL can be used together to manage live users and persistent data.
- Random one to one text chat
- Random one to one video chat
- Instant matchmaking
- Leave and reconnect anytime
- Search users by username
- Start direct conversations
- View previous conversations
- Persistent chat history
- User registration
- Login
- Session based authentication
- Protected routes and APIs
- Block users
- Unblock users
- Mute conversations
- Report users
- Delete conversations
- Go
- net/http
- Gorilla WebSocket
- WebRTC
- PostgreSQL
- Redis
- HTML
- CSS
- JavaScript
- Go HTML Templates
When a user joins a random chat, they are placed into a waiting queue stored in Redis. As soon as another user becomes available, both users are matched and connected through a WebSocket.
For video chat, WebSockets are only used for signaling. Once signaling is complete, WebRTC establishes a direct peer to peer connection for audio and video streaming.
Registered users can search for other users by username and start private conversations. User information, authentication data, messages, and conversation history are stored in PostgreSQL.
random-connect/
│
├── cmd/
│ └── server/ # Application entry point
│
├── internal/
│ ├── cache/ # Redis client
│ ├── db/ # PostgreSQL connection
│ ├── handlers/ # HTTP & WebSocket handlers
│ ├── middleware/ # Authentication & logging
│ ├── models/ # Data models
│ ├── services/ # Business logic
│ └── utils/ # Helper functions
│
├── web/
│ ├── auth/
│ ├── home/
│ ├── 121-chat/
│ ├── videoroom/
│ ├── PM/
│ ├── chatrooms/
│ ├── anony-forum/
│ └── global/
│
├── go.mod
├── go.sum
└── README.md
The backend follows a simple layered architecture.
HTTP Request
│
▼
Middleware
│
▼
Handlers
│
▼
Services
│
├────────► PostgreSQL
│
└────────► Redis
Responsible for processing HTTP requests, WebSocket connections, rendering templates, and returning API responses.
Contain the application's business logic including authentication, matchmaking, messaging, and user management.
Provides authentication and request logging before requests reach the handlers.
PostgreSQL stores persistent application data.
Redis is used for temporary application state and random matchmaking.
Redis is used for:
- Random matchmaking queue
- Connected user information
- Active session metadata
- Temporary matchmaking state
- User accounts
- Authentication data
- Chat history
- Conversations
- User reports
- Conversation metadata
| Method | Endpoint |
|---|---|
| POST | /api/register |
| POST | /api/login |
| Method | Endpoint |
|---|---|
| GET | /api/me |
| GET | /api/users/search |
| Method | Endpoint |
|---|---|
| POST | /api/dm/start |
| GET | /api/messages |
| GET | /api/conversations |
| POST | /api/conversation/delete |
| POST | /api/conversation/mute |
| POST | /api/conversation/block |
| POST | /api/conversation/unblock |
| POST | /api/conversation/report |
| Endpoint | Description |
|---|---|
/ws |
Handles random chat, messaging, and WebRTC signaling |
git clone https://github.com/devmt04/random-connect.git
cd random-connectgo mod downloadMake sure PostgreSQL is running and create a database named:
randomconnect
redis-serverUpdate the PostgreSQL connection string inside cmd/server/main.go.
postgres://username:password@localhost:5432/randomconnect?sslmode=disablego run ./cmd/serverThe application will be available at:
http://localhost:8000
- Friend requests
- Group chat
- Voice calls
- Media sharing
- Push notifications
- Mobile responsive UI
- End to end encrypted messaging
- Docker support
Mohit
Computer Science Engineering Student
Interested in Backend Development, Distributed Systems, Real Time Communication, and Full Stack Development.