Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Random Connect

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.


Features

Anonymous Chat

  • Random one to one text chat
  • Random one to one video chat
  • Instant matchmaking
  • Leave and reconnect anytime

Private Messaging

  • Search users by username
  • Start direct conversations
  • View previous conversations
  • Persistent chat history

User Authentication

  • User registration
  • Login
  • Session based authentication
  • Protected routes and APIs

Conversation Management

  • Block users
  • Unblock users
  • Mute conversations
  • Report users
  • Delete conversations

Tech Stack

Backend

  • Go
  • net/http
  • Gorilla WebSocket
  • WebRTC
  • PostgreSQL
  • Redis

Frontend

  • HTML
  • CSS
  • JavaScript
  • Go HTML Templates

How It Works

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.


Project Structure

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

Backend Architecture

The backend follows a simple layered architecture.

HTTP Request
      │
      ▼
 Middleware
      │
      ▼
  Handlers
      │
      ▼
  Services
      │
      ├────────► PostgreSQL
      │
      └────────► Redis

Handlers

Responsible for processing HTTP requests, WebSocket connections, rendering templates, and returning API responses.

Services

Contain the application's business logic including authentication, matchmaking, messaging, and user management.

Middleware

Provides authentication and request logging before requests reach the handlers.

Database

PostgreSQL stores persistent application data.

Cache

Redis is used for temporary application state and random matchmaking.


Redis Usage

Redis is used for:

  • Random matchmaking queue
  • Connected user information
  • Active session metadata
  • Temporary matchmaking state

PostgreSQL Stores

  • User accounts
  • Authentication data
  • Chat history
  • Conversations
  • User reports
  • Conversation metadata

Main Endpoints

Authentication

Method Endpoint
POST /api/register
POST /api/login

User

Method Endpoint
GET /api/me
GET /api/users/search

Messaging

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

WebSocket

Endpoint Description
/ws Handles random chat, messaging, and WebRTC signaling

Running the Project

Clone the repository

git clone https://github.com/devmt04/random-connect.git
cd random-connect

Install dependencies

go mod download

Start PostgreSQL

Make sure PostgreSQL is running and create a database named:

randomconnect

Start Redis

redis-server

Configure the database

Update the PostgreSQL connection string inside cmd/server/main.go.

postgres://username:password@localhost:5432/randomconnect?sslmode=disable

Run the server

go run ./cmd/server

The application will be available at:

http://localhost:8000

Future Improvements

  • Friend requests
  • Group chat
  • Voice calls
  • Media sharing
  • Push notifications
  • Mobile responsive UI
  • End to end encrypted messaging
  • Docker support

Author

Mohit

Computer Science Engineering Student

Interested in Backend Development, Distributed Systems, Real Time Communication, and Full Stack Development.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages