UTracker is a full-stack BitTorrent Tracker Aggregator that aggregates peers across multiple protocols (HTTP, UDP, and WebSocket) to provide a unified, high-performance torrent tracking service. The application consists of:
- Backend: A FastAPI-based server implementing BEP-3 (BitTorrent Protocol) and BEP-15 (UDP Tracker Protocol)
- Frontend: A React-based dashboard for monitoring tracker statistics and swarm activity
- Real-time Updates: WebSocket integration for live peer/swarm monitoring
- Multi-protocol support (HTTP, UDP, WebSocket) for maximum client compatibility
- Real-time peer aggregation across all protocols
- Public tracker discovery and validation
- Performance metrics and monitoring
- Ultra-low latency swarm management
- Framework: FastAPI (Python 3.x)
- Database: MongoDB (via Motor async driver)
- Protocols: HTTP (BEP-3), UDP (BEP-15), WebSocket
- Key Dependencies: aiohttp, bencode.py, pydantic, uvicorn
- Framework: React (v19) with Create React App
- Styling: Tailwind CSS with Radix UI components
- API Client: Axios
- Routing: React Router DOM
- UI Components: Radix UI primitives, Lucide icons
UTracker/
├── backend/
│ ├── server.py # Main FastAPI application with all endpoints
│ └── requirements.txt # Python dependencies
├── frontend/
│ ├── public/ # Static assets
│ ├── src/
│ │ ├── App.js # Main React application component
│ │ ├── components/ # Reusable UI components
│ │ ├── hooks/ # Custom React hooks
│ │ └── lib/ # Utility functions
│ ├── package.json # Frontend dependencies and scripts
│ ├── craco.config.js # CRA customization configuration
│ └── tailwind.config.js # Tailwind CSS configuration
├── tests/ # Test directory
├── backend_test.py # Comprehensive backend testing suite
├── additional_tests.py # Additional protocol compliance tests
└── README.md
-
Install Python dependencies:
cd backend pip install -r requirements.txt -
Set up environment variables (create
.envfile):MONGO_URL=mongodb://localhost:27017 DB_NAME=tracker_db CORS_ORIGINS=http://localhost:3000,http://localhost:3001 -
Start the backend server:
cd backend uvicorn server:app --host 0.0.0.0 --port 8001The HTTP tracker will be available at
http://localhost:8001/api/announceThe UDP tracker will automatically start on port 8002
-
Install Node.js dependencies:
cd frontend npm install -
Set up environment variables (create
.envfile):REACT_APP_BACKEND_URL=http://localhost:8001 -
Start the frontend development server:
cd frontend npm startThe dashboard will be available at
http://localhost:3000
A multi-stage Docker build has been implemented to containerize the application. The fixed Dockerfile addresses issues with missing executables in the final image.
Docker Configuration (Fixed Issues):
- The original Dockerfile was missing the uvicorn executable in the final image, causing container startup failures.
- Fixed by copying both Python packages and executables from the builder stage:
COPY --from=backend-builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages COPY --from=backend-builder /usr/local/bin /usr/local/bin
Docker Environment Variables:
- Backend:
- MONGO_URL: mongodb://mongodb:27017
- DB_NAME: tracker_db
- CORS_ORIGINS: http://localhost:3000,http://localhost:80,http://localhost
- Frontend:
- REACT_APP_BACKEND_URL: http://localhost:8001
- REACT_APP_DOCKER_ENV: true (indicates Docker environment)
Docker Network and API Proxy: The Docker setup uses nginx to proxy API requests from the frontend to the backend:
- Frontend runs on port 80
- API requests to
/apiare proxied to the backend service at port 8001 - WebSocket connections to
/api/announce_wsare also proxied - This allows the React app to make relative API calls that are handled by nginx
Running with Docker:
docker-compose up --buildThe application will be accessible at http://localhost (port 80), with API endpoints available at http://localhost/api/....
Backend tests:
cd backend
python backend_test.py
python additional_tests.pyGET /api/announce- BitTorrent announce endpoint
- Port
8002- UDP BitTorrent announce endpoint
WS /api/announce_ws- WebSocket announce endpoint
GET /api/stats- Tracker statisticsGET /api/swarms- Active swarms informationGET /api/trackers- Public tracker list with statusPOST /api/scrape_trackers- Refresh public tracker listGET /api/metrics- Prometheus-compatible metrics
- Follow FastAPI conventions for request/response models
- Use Pydantic models for data validation
- Async/await pattern for all I/O operations
- Thread-safe operations using asyncio.Lock
- Component-based architecture in React
- Use functional components with hooks
- Tailwind CSS for styling
- Environment variables for configuration
- Axios for API requests
- Comprehensive backend testing with aiohttp and websockets
- Protocol compliance tests following BEP standards
- Performance and load testing capabilities
- Error handling validation for malformed requests
The backend implements a SwarmManager class that provides thread-safe operations for tracking BitTorrent swarms and peers. The application supports three protocols simultaneously:
- HTTP (BEP-3) - Standard BitTorrent announce protocol
- UDP (BEP-15) - Low-overhead UDP tracker protocol
- WebSocket - Real-time bidirectional communication for modern clients
The frontend provides a comprehensive dashboard with real-time metrics, swarm monitoring, and tracker status visualization. All three protocols contribute to the same pool of peers, allowing for cross-protocol aggregation.