Contributing Guide

April 7, 2026 ยท View on GitHub

Thank you for your interest in 0trace! This document will help you get started with development.

๐Ÿš€ Development Environment

Prerequisites

  • Rust 1.75+
  • Cargo
  • Git

Clone Repository

git clone https://github.com/momo2029/0trace
cd 0trace

๐Ÿ› ๏ธ Development Workflow

Start Development Server

Method 1: Hot-reload Mode (Recommended)

./dev.sh

Features:

  • โœ… Automatically watches for code changes
  • โœ… Automatically recompiles
  • โœ… Automatically restarts server

Watch scope:

  • backend/src/**/*.rs - Backend code
  • shared/src/**/*.rs - Shared library code

Method 2: Normal Mode

make dev

Modify Code

Backend Code

  1. Edit backend/src/*.rs or shared/src/*.rs
  2. Hot-reload mode: auto-restart โœ…
  3. Normal mode: Ctrl+C to stop โ†’ make dev to restart

Frontend Code

  1. Edit frontend/static/*.{html,css,js}
  2. Copy to backend: cp frontend/static/* backend/static/
  3. Refresh browser โœ…

Shortcut commands:

# Update all frontend files
cp -r frontend/static/* backend/static/

# Or update individually
cp frontend/static/style.css backend/static/
cp frontend/static/app.js backend/static/

๐Ÿงช Testing

Run Tests

make test

Local File Transfer Test

  1. Open two browser windows (or use incognito mode)

    Window 1: http://localhost:2029
    Window 2: http://localhost:2029
    
  2. Window 1 (Sender):

    • Select "Send Files" tab
    • Choose test file (recommended < 10MB)
    • Copy share link
  3. Window 2 (Receiver):

    • Paste link into address bar
    • Auto-start receiving

Suggested Test Files

File TypeSizePurpose
Text file< 1MBQuick test
Image1-10MBRegular test
Video10-100MBPerformance test

๐Ÿ› Debugging

Enable Detailed Logs

RUST_LOG=debug ./dev.sh

Log levels:

  • error - Errors only
  • warn - Warnings and above
  • info - Info and above (default)
  • debug - Debug info
  • trace - All info

Browser Debugging

  1. Open Developer Tools: F12
  2. Console tab: View JS logs
  3. Network tab: View requests
  4. Application tab: View localStorage

๐Ÿ“ฆ Building

Development Build

cargo build

Production Build

make build
# Binary: backend/target/release/backend

Docker Build

docker build -t 0trace .
docker run -p 2029:2029 0trace

๐Ÿ“ Code Standards

Rust Code

# Format
cargo fmt

# Lint
cargo clippy

# Fix warnings
cargo clippy --fix

JavaScript Code

  • Use ES6+ syntax
  • Avoid frameworks (stay lightweight)
  • Add necessary comments

Commit Convention

Use semantic commit messages:

feat: Add new feature
fix: Fix bug
docs: Update documentation
style: Code formatting changes
refactor: Refactor code
test: Add tests
chore: Build/toolchain updates

Examples:

git commit -m "feat: Add multi-file transfer support"
git commit -m "fix: Fix memory overflow for large files"
git commit -m "docs: Update README deployment instructions"

๐Ÿ—๏ธ Project Structure

0trace/
โ”œโ”€โ”€ shared/              # Shared library (protocol definitions)
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ protocol.rs  # Signaling protocol
โ”‚   โ”‚   โ””โ”€โ”€ room.rs      # Room management
โ”‚   โ””โ”€โ”€ Cargo.toml
โ”‚
โ”œโ”€โ”€ backend/             # Rust backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ main.rs      # Server entry point
โ”‚   โ”‚   โ”œโ”€โ”€ room.rs      # Room manager
โ”‚   โ”‚   โ””โ”€โ”€ ws.rs        # WebSocket handling
โ”‚   โ””โ”€โ”€ static/          # Static files (production)
โ”‚
โ”œโ”€โ”€ frontend/            # Frontend development
โ”‚   โ””โ”€โ”€ static/
โ”‚       โ”œโ”€โ”€ index.html   # Main page
โ”‚       โ”œโ”€โ”€ app.js       # WebRTC logic
โ”‚       โ”œโ”€โ”€ style.css    # Styles
โ”‚       โ”œโ”€โ”€ i18n.js      # Multilingual system
โ”‚       โ””โ”€โ”€ i18n/        # Translation files
โ”‚
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ Makefile
โ””โ”€โ”€ README.md

๐Ÿค Submitting Pull Requests

  1. Fork the project
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m "feat: Add new feature"
  4. Push branch: git push origin feature/amazing-feature
  5. Submit Pull Request

PR Checklist

  • Code formatted with cargo fmt
  • Code passes cargo clippy checks
  • Added necessary tests
  • Updated relevant documentation
  • Tested locally
  • Commit messages follow convention

๐Ÿ”ง Common Issues

Port Already in Use

# Find process using port
lsof -ti:2029

# Kill process
lsof -ti:2029 | xargs kill -9

Hot-reload Not Working

# Install cargo-watch
cargo install cargo-watch

# Check version
cargo watch --version

Frontend Changes Not Applied

# Confirm files copied
ls -la backend/static/

# Force refresh browser
Cmd+Shift+R (Mac)
Ctrl+Shift+R (Windows/Linux)

Compilation Errors

# Clean build cache
make clean

# Update dependencies
cargo update

# Rebuild
make build

๐Ÿ“š Resources

๐Ÿ’ก Development Tips

  1. Small commits - Each commit should do one thing
  2. Write comments - Add comments for complex logic
  3. Test first - Write tests before modifying features
  4. Keep it simple - Avoid over-engineering
  5. Performance mindset - Consider memory and performance impact

๐ŸŽฏ Optimization Ideas

Contributions welcome for:

Short-term

  • Add transfer speed display
  • Support resumable transfers
  • Add file preview
  • Optimize large file transfers

Medium-term

  • Integrate TURN server
  • Add file encryption option
  • Support batch transfers
  • Mobile optimization

Long-term

  • Text message transfer
  • QR code sharing
  • Transfer history
  • Custom STUN/TURN configuration

๐Ÿ“ง Contact

Questions or suggestions?

Thank you for your contributions! ๐ŸŽ‰