Skip to content

Shawnzheng011019/rusty-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Rusty Chat

A real-time chat application built with Rust (Axum) backend and React frontend.

Features

  • πŸ” User Authentication (Registration/Login)
  • πŸ’¬ Real-time Messaging
  • πŸ‘₯ Friend Management System
  • 🏒 Group Chat
  • πŸ“ File Upload and Sharing
  • 🎀 Voice Messages
  • πŸ“· Image and Video Sharing
  • πŸ”” Real-time Notifications
  • πŸ“± Responsive Design

Tech Stack

Backend

  • Rust - Systems programming language
  • Axum - Modern async web framework
  • PostgreSQL - Primary database
  • Redis - Caching and session storage
  • WebSocket - Real-time communication
  • JWT - Authentication
  • SQLx - Database ORM

Frontend

  • React 19 - UI framework
  • TypeScript - Type safety
  • Tailwind CSS - Styling framework
  • Vite - Build tool
  • Socket.IO - WebSocket client
  • Axios - HTTP client

Quick Start

Prerequisites

  • Rust 1.70+
  • Node.js 18+
  • PostgreSQL 13+
  • Redis 6+

Installation Steps

  1. Clone the repository

    git clone <repository-url>
    cd rusty-chat
  2. Setup database

    # Run database setup script
    ./scripts/setup_db.sh
    
    # Or setup manually
    createdb rusty_chat
    psql -d rusty_chat -f migrations/001_initial.sql
  3. Configure environment variables

    # Copy environment template
    cp .env.example .env
    
    # Edit .env file and set your database and Redis connection info
  4. Start Redis

    # macOS
    brew services start redis
    
    # Linux
    sudo systemctl start redis
    
    # Or run directly
    redis-server
  5. Install frontend dependencies

    cd frontend
    npm install
  6. Start development servers

    Backend (Terminal 1):

    cargo run

    Frontend (Terminal 2):

    cd frontend
    npm run dev
  7. Access the application

Project Structure

rusty-chat/
β”œβ”€β”€ src/                    # Rust backend source code
β”‚   β”œβ”€β”€ handlers/          # API handlers
β”‚   β”œβ”€β”€ models/            # Data models
β”‚   β”œβ”€β”€ services/          # Business logic
β”‚   β”œβ”€β”€ config.rs          # Configuration management
β”‚   β”œβ”€β”€ database.rs        # Database connection
β”‚   β”œβ”€β”€ websocket.rs       # WebSocket handling
β”‚   └── main.rs            # Application entry point
β”œβ”€β”€ frontend/              # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ contexts/      # React Context
β”‚   β”‚   β”œβ”€β”€ pages/         # Page components
β”‚   β”‚   β”œβ”€β”€ services/      # API services
β”‚   β”‚   └── types/         # TypeScript types
β”‚   └── public/            # Static assets
β”œβ”€β”€ migrations/            # Database migrations
β”œβ”€β”€ scripts/               # Utility scripts
└── uploads/               # File upload directory

API Documentation

Authentication Endpoints

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • POST /api/auth/refresh - Refresh token

User Endpoints

  • GET /api/users/me - Get current user info
  • GET /api/users/search - Search users

Friend Endpoints

  • GET /api/friends - Get friends list
  • POST /api/friends/requests - Send friend request
  • POST /api/friends/requests/:id/accept - Accept friend request
  • POST /api/friends/requests/:id/reject - Reject friend request
  • DELETE /api/friends/:id - Remove friend

Group Endpoints

  • GET /api/groups - Get groups list
  • POST /api/groups - Create group
  • GET /api/groups/:id/members - Get group members
  • POST /api/groups/:id/members - Add group member
  • DELETE /api/groups/:id/members/:user_id - Remove group member

Message Endpoints

  • GET /api/messages/:chat_id - Get chat messages
  • POST /api/messages - Send message

File Endpoints

  • POST /api/upload - Upload file
  • GET /api/files/:id - Download file

WebSocket Events

Client Sends

  • authenticate - Authentication
  • join_chat - Join chat room
  • leave_chat - Leave chat room
  • send_message - Send message
  • typing_indicator - Typing status indicator

Server Sends

  • new_message - New message
  • typing_indicator - Typing status
  • user_online - User online
  • user_offline - User offline
  • friend_request - Friend request
  • group_invitation - Group invitation

Development Guide

Backend Development

# Run tests
cargo test

# Check code
cargo clippy

# Format code
cargo fmt

Frontend Development

cd frontend

# Run tests
npm test

# Code linting
npm run lint

# Build for production
npm run build

Deployment

Production Build

# Build frontend
cd frontend
npm run build

# Build backend
cargo build --release

Docker Deployment

# Build image
docker build -t rusty-chat .

# Run container
docker run -p 3000:3000 rusty-chat

Using Docker Compose

# Start all services (database, redis, app)
docker-compose up -d

# Stop all services
docker-compose down

Quick Development Setup

# Use the development script for automatic setup
./scripts/dev.sh

Contributing

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For questions or suggestions, please create an Issue or contact the project maintainers.

About

A real-time chat application built with Rust (Axum) backend and React frontend.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published