A modern real-time chat application built with a Rust backend and React frontend, featuring user authentication, real-time messaging, direct messages, group chats, and message history.
This project was bootstrapped and enhanced with the help of a Gemini agent.
- Real-time messaging with WebSockets
- Direct messages - Private one-on-one conversations
- Group chats - Create or join different chat rooms
- Message history - Persistent chat history with SQLite database
- Online status - View user availability in real-time
- System notifications for user join/leave events
- Browse chat rooms and conversations
- User Registration: Create new accounts with username, email, and password
- User Login: Secure authentication with JWT tokens
- Password Security: Bcrypt encryption for password storage
- Token-based Auth: JWT tokens with automatic expiration
- User Profiles: View and manage user information
- Friends System: Add friends and manage friend requests
- User Search: Find and connect with other users
- Guest Mode: Option to chat without registration
- Clean, modern, and responsive design
- Real-time message updates with typing indicators
- Separate views for friends, rooms, and direct messages
- Mobile-friendly interface with touch optimization
- Dark theme optimized for readability
- Modal overlays for user search and friend management
- Rust - High-performance backend server
- Axum - Modern async web framework
- SQLite - Persistent data storage with SQLx
- WebSockets - Real-time communication
- JWT - Secure authentication tokens
- bcrypt - Password hashing
- uuid - Unique user identification
- React 18 - Modern UI framework
- Context API - State management
- Modern CSS - Responsive styling
- Vite - Fast development and build tool
- Bash scripts - Development automation
- Database migrations - SQLx migration support
- Hot reload - Fast development iteration
- Database initialization - Automated setup scripts
The simplest way to get the development environment running is to use the provided shell script.
-
Clone the repository (if you haven't already).
-
Make the development script executable:
chmod +x dev.sh
-
Run the development script:
./dev.sh
This command will automatically:
- Initialize SQLite database (if not exists)
- Install frontend dependencies (
npm install
) if they are not present - Build the React frontend for production
- Start the Rust backend server with static file serving
- Serve the complete application at
http://localhost:3000
Once the script is running, open your web browser and navigate to http://localhost:3000 to use the application.
For first-time setup, initialize the database:
chmod +x init_db.sh
./init_db.sh
Or use the development script with database initialization:
./dev.sh --init-db
If you prefer to run the services separately during development:
# Navigate to the backend directory
cd backend
# Run the server (serves both API and static files)
cargo run
For frontend development with hot reload:
# Navigate to the frontend directory
cd frontend
# Install dependencies
npm install
# Run the development server
npm run dev
Then access the dev server at http://localhost:5173
(will proxy API calls to backend).
- Navigate to the registration page
- Fill in username, email, and password (minimum 6 characters)
- Automatically logged in upon successful registration
- Use existing credentials to log in
- JWT token stored securely in browser
- Automatic token validation on page refresh
- Click on user avatar to view profile
- See user information and account details
- Sign out functionality
- Chat without creating an account
- Limited to current session only (no message history)
- Can upgrade to full account anytime
- Search users by username
- Send friend requests to connect with others
- Accept/decline incoming friend requests
- Start direct messages with friends
- See online status of friends in real-time
POST /api/auth/register
- Register new userPOST /api/auth/login
- User loginPOST /api/auth/verify
- Validate JWT token
GET /api/rooms
- Get user's chat rooms (direct + group)GET /api/rooms/:room_id/messages
- Get message historyWS /ws
- WebSocket connection for real-time chat
GET /api/users/search
- Search users by usernameGET /api/friends
- Get user's friends listGET /api/friends/requests
- Get pending friend requestsPOST /api/friends/request
- Send friend requestPOST /api/friends/accept
- Accept friend request
A test page is provided to verify the authentication system:
- Open
test_auth.html
in your browser - Ensure the backend is running (
cargo run
) - Test registration, login, and token verification
- View detailed API responses and error messages
-
JWT_SECRET
- JWT signing secret (default: development key)export JWT_SECRET="your-secret-key-for-production"
-
DATABASE_URL
- Database connection string (default: sqlite:chatx.db)export DATABASE_URL="sqlite:chatx.db"
- Change JWT_SECRET in production
- Use HTTPS in production
- Consider implementing rate limiting
- User data is stored persistently in SQLite database
- Passwords are hashed with bcrypt
- JWT tokens have automatic expiration
.
βββ backend/ # Rust backend
β βββ src/
β β βββ db/ # Database models and operations
β β β βββ mod.rs # SQLite database implementation
β β βββ main.rs # Main server with enhanced APIs
β βββ Cargo.toml # Dependencies with database support
β βββ migrations/ # Database migrations
βββ frontend/ # React frontend
β βββ src/
β β βββ components/
β β β βββ LoginPage.jsx # Login interface
β β β βββ RegisterPage.jsx # Registration interface
β β β βββ UserProfile.jsx # User profile modal
β β β βββ JoinForm.jsx # Updated for room types
β β β βββ FriendsList.jsx # Friends management
β β β βββ UserSearch.jsx # User search component
β β β βββ RoomsList.jsx # Room browser
β β β βββ ... # Other chat components
β β βββ context/
β β β βββ AuthContext.jsx # Enhanced authentication state
β β βββ App.jsx # Main app with new features
β β βββ App.css # Updated styles
β βββ package.json
β βββ index.html
βββ dev.sh # Enhanced development script
βββ init_db.sh # Database initialization script
βββ build.sh # Production build script
βββ clean.sh # Clean build artifacts
βββ chatx.db # SQLite database (created automatically)
βββ test_auth.html # Authentication testing page
βββ demo.md # Feature demonstration guide
βββ README.md # This file
# Initialize database (first time only)
./init_db.sh
# Build frontend for production
cd frontend && npm run build
# Run backend (serves built frontend)
cd ../backend && cargo run --release
# Set production environment variables
export JWT_SECRET="your-production-secret-key"
export DATABASE_URL="sqlite:chatx.db"
# Run in production mode
cd backend && cargo run --release
Create a Dockerfile for containerized deployment:
# Build frontend
FROM node:18 AS frontend
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ ./
RUN npm run build
# Build backend
FROM rust:1.70 AS backend
WORKDIR /app
COPY backend/ ./
RUN cargo build --release
# Final image
FROM debian:bullseye-slim
WORKDIR /app
COPY --from=backend /app/target/release/backend ./
COPY --from=frontend /app/frontend/dist ./frontend/dist
EXPOSE 3000
CMD ["./backend"]
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is open source and available under the MIT License.
- Built with assistance from Gemini AI
- Rust community for excellent crates
- React team for the amazing framework
- All contributors and users of this project