Skip to content

Rust Backend

RushChat's backend is written in Rust, based on the Axum framework.

Rust Backend Overview

Technology Stack

  • Rust - Systems programming language
  • Axum - Modern async web framework
  • Tokio - Async runtime
  • SQLx - Type-safe async SQL toolkit (MySQL)
  • Serde - Serialization/deserialization
  • Bcrypt - Password encryption

Project Structure

server-rust/
├── src/
│   ├── main.rs              # Entry point
│   ├── config.rs            # Configuration management
│   ├── db.rs                # Database connection
│   ├── models/              # Data models
│   │   ├── user.rs
│   │   ├── message.rs
│   │   ├── channel.rs
│   │   └── ...
│   ├── handlers/            # HTTP handlers
│   │   ├── auth.rs
│   │   ├── user.rs
│   │   ├── channel.rs
│   │   └── ...
│   ├── websocket/           # WebSocket handlers
│   │   ├── connection.rs
│   │   ├── events.rs
│   │   └── state.rs
│   └── utils/               # Utility functions
│       ├── rpc.rs           # RPC utilities (NFT verification, etc.)
│       └── permissions.rs
├── Cargo.toml
└── README.md

Core Functions

WebSocket Real-time Communication

  • Based on Tokio WebSocket
  • Supports broadcast messages
  • Connection management and heartbeat detection

RESTful API

  • User authentication
  • User management
  • Channel management
  • Message management
  • File upload

Database Integration

  • Uses SQLx for type-safe queries
  • Connection pool management
  • Async database operations

File Upload

  • Avatar upload
  • Sticker upload
  • Image compression

Development

Run Development Server

cd server-rust
cargo run

Build Production Version

cargo build --release

Run Tests

cargo test

Performance Optimization

  • Use connection pool to manage database connections
  • Async I/O processing
  • Broadcast channels for WebSocket message distribution
  • Type-safe database queries