A feature-rich Discord-like chat application implemented in Rust, featuring real-time messaging, voice chat, file sharing, and user authentication.
Discord is banned in our country 🇹🇷, so I require a custom application to serve as an in-house solution for tracking logs, managing notes, sharing files and more. Feel free to use, contribute, and enhance the application to fit your needs!
- 💬 Real-time text messaging
- 🔒 User authentication with JWT
- 📁 File sharing capabilities
- 🎤 Voice chat support
- 📱 Direct messaging
- 🔐 Secure password hashing
- 📦 Database persistence
- Asynchronous runtime with Tokio
- TCP-based networking
- Opus codec for voice compression
- PostgreSQL database backend
- Chunk-based file transfer
- Argon2 password hashing
- Rust (latest stable version)
- PostgreSQL (14.0 or higher)
- libopus development files
- pkg-config
- Build essentials
sudo apt update
sudo apt install -y \
build-essential \
pkg-config \
libssl-dev \
postgresql \
postgresql-contrib \
libopus-dev \
libasound2-dev
brew install \
pkg-config \
opus \
postgresql
- Install PostgreSQL
- Install Opus
- Install Visual Studio Build Tools
- Clone the repository:
git clone https://github.com/makalin/clearcomm
cd clearcomm
- Set up the database:
# Connect to PostgreSQL
psql postgres
# Create the database
CREATE DATABASE clearcommdb;
\c clearcommdb
# Create required tables
CREATE TABLE users (
id UUID PRIMARY KEY,
username VARCHAR(255) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL
);
CREATE TABLE messages (
id UUID PRIMARY KEY,
from_user VARCHAR(255) NOT NULL,
to_user VARCHAR(255),
content TEXT NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL
);
- Create a
.env
file:
DATABASE_URL=postgres://username:password@localhost/clearcomm
SERVER_SECRET=your_secret_key_here
- Build the project:
cargo build --release
- Start the server:
cargo run --release --bin server
- In a separate terminal, start the client:
cargo run --release --bin client
- Follow the authentication prompts to create an account or log in.
Once connected, the following commands are available:
- Regular chat: Just type your message and press Enter
/dm <username> <message>
- Send a direct message/file <path>
- Share a file/voice
- Join voice chat/quit
- Exit the application
graph TD
A[Client] -- TCP --> B[Server]
B -- Authentication --> C[Auth Handler]
B -- File Transfer --> D[File Handler]
B -- Voice Data --> E[Voice Handler]
B -- Messages --> F[Message Handler]
C -- Verify --> G[JWT]
C -- Store --> H[(Database)]
F -- Store --> H
- Server: Handles client connections and routes messages
- Auth Handler: Manages user authentication and session tokens
- File Handler: Manages file uploads and downloads
- Voice Handler: Processes voice chat data
- Message Handler: Handles text message routing and storage
- Database: Stores user data and message history
clearcomm/
├── src/
│ ├── auth.rs # Authentication logic
│ ├── client.rs # Client implementation
│ ├── common.rs # Shared types and utilities
│ ├── db.rs # Database operations
│ ├── file_handler.rs # File transfer logic
│ ├── server.rs # Server implementation
│ └── voice.rs # Voice chat implementation
├── Cargo.toml
├── .env
└── README.md
cargo test
cargo doc --no-deps --open
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
- All passwords are hashed using Argon2
- Authentication uses JWT tokens
- File transfers are chunked for reliability
- Voice data is compressed using Opus codec
- Database credentials are stored in environment variables
This project is licensed under the MIT License - see the LICENSE file for details.
- The Rust community for excellent crates and documentation
- Discord for inspiration
- Contributors and testers