A real-time chat application built with Rust, featuring a WebSocket-based backend and a modern web frontend.
- Real-time messaging - Instant message delivery via WebSocket connections
- User management - Dynamic username changes and user list updates
- Modern UI - Clean, responsive interface built with Yew (Rust frontend framework)
- System notifications - Automatic notifications for user events (username changes, etc.)
- Scalable architecture - Modular design with separate backend, frontend, and common libraries
This project is organized as a Rust workspace with three main components:
- Framework: Rocket with WebSocket support
- Features:
- WebSocket connection management
- Real-time message broadcasting
- User session handling
- System notifications
- Framework: Yew (Rust frontend framework)
- Features:
- Real-time message display
- User list management
- Username change functionality
- Responsive Bootstrap-based UI
- Purpose: Shared data structures and types
- Features:
- WebSocket message definitions
- Chat message structures
- Serialization/deserialization types
- Rust 1.70+ (latest stable version recommended)
- Cargo (comes with Rust)
- Web browser with WebSocket support
-
Clone the repository
git clone https://github.com/philodi-dev/rust-chat-websocket cd rust-chat-websocket -
Build the project
cargo build
-
Run the backend server
cargo run -p backend
The server will start on
http://127.0.0.1:8000 -
Run the frontend (in a separate terminal)
cargo run -p frontend
The frontend will be available at the URL shown in the terminal (typically
http://127.0.0.1:8000)
- Connect to the chat - Open your browser and navigate to the frontend URL
- Send messages - Type your message in the input field and press Enter
- Change username - Use the username field to set your display name
- View users - See the current list of connected users in the sidebar
rust-chat/ βββ backend/ # WebSocket server implementation βββ frontend/ # Yew-based web frontend βββ common/ # Shared types and structures βββ Cargo.toml # Workspace configuration βββ README.md # This file Backend:
rocket- Web frameworkrocket_ws- WebSocket supportserde- Serializationchrono- Date/time handling
Frontend:
yew- Rust frontend frameworkyew-hooks- React-like hooks for Yewweb-sys- Web API bindings
Common:
serde- Serializationchrono- Date/time handling
# Build backend only cargo build -p backend # Build frontend only cargo build -p frontend # Build common library only cargo build -p common# Run all tests cargo test # Run tests for specific component cargo test -p backend cargo test -p frontend cargo test -p common- Messages are instantly broadcast to all connected users
- System notifications for user events
- Persistent message history during session
- Dynamic username changes
- Real-time user list updates
- Automatic user assignment on connection
The application uses a custom WebSocket message protocol:
#[derive(Serialize, Deserialize)] pub enum WebSocketMessageType { NewMessage, // Chat message UsersList, // Updated user list UsernameChange, // Username change request }- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Philodi
- Email: me@philodi.com
- Website: https://philodi.com
- Built with Rocket web framework
- Frontend powered by Yew Rust framework
- Real-time communication via WebSocket protocol
Note: This is a demonstration project showcasing Rust's capabilities for building full-stack web applications with real-time features.