A complete, production-ready peer-to-peer torrent system built with React, Node.js, and WebRTC. This implementation includes a full BitTorrent protocol implementation, built-in tracker, WebRTC-based peer connections, and Docker deployment support.
- Complete torrent file parsing and creation
- SHA-1 piece validation and verification
- Efficient piece and block management
- Support for single and multi-file torrents
- WebRTC-based peer connections
- Built-in signaling server
- Automatic peer discovery and connection management
- DHT-like peer discovery system
- Connection pooling and management
- Built-in HTTP tracker implementation
- Swarm management and peer tracking
- Statistics and health monitoring
- Rate limiting and security features
- Input validation and sanitization
- Rate limiting on API endpoints
- Secure file upload handling
- Docker containerization
- Health checks and monitoring
- Graceful shutdown handling
- Error handling and logging
- Modern, responsive React interface
- Real-time download/upload statistics
- Drag-and-drop torrent management
- Live peer connection visualization
- Dark theme with glass morphism effects
- Node.js 18+ and npm 8+
- Docker and Docker Compose (for containerized deployment)
# Clone the repository
git clone <repository-url>
cd p2p-torrent-system
# Install dependencies
npm install
# Start development servers
npm run devThe application will be available at:
- Frontend: http://localhost:5173
- Backend: http://localhost:3000
- WebSocket: ws://localhost:3000/ws
# Build and run with Docker Compose
npm run docker:compose:build
# Or use individual Docker commands
npm run docker:build
npm run docker:run# Build the application
npm run build
npm run build:server
# Start in production mode
npm run start:prodGET /api/announce- BitTorrent tracker announceGET /api/dht/nodes- DHT bootstrap nodes
POST /api/torrents- Upload torrent fileGET /api/torrents- List all torrentsDELETE /api/torrents/:infoHash- Remove torrent
GET /api/health- System health checkGET /api/stats- Detailed system statistics
- Components: Modular React components for UI
- Services: TorrentEngine for protocol implementation
- Utils: Crypto, parsing, and utility functions
- HTTP Server: Express.js with security middleware
- WebSocket Server: Real-time peer signaling
- Tracker: BitTorrent protocol tracker implementation
- Storage: In-memory with persistent backup
- WebRTC: Peer-to-peer data channels
- WebSocket: Signaling and coordination
- HTTP: Tracker announces and API
NODE_ENV=production
PORT=3000The application includes comprehensive Docker configuration:
- Multi-stage builds for optimization
- Health checks and monitoring
- Volume management for persistent data
- Nginx reverse proxy configuration
- Torrent file format validation
- File size and type restrictions
- URL and parameter sanitization
- API endpoint protection
- Connection attempt limiting
- Resource usage monitoring
- CORS configuration
- Secure WebSocket connections
- Connection timeout management
src/
├── components/ # React components
├── services/ # Core services (TorrentEngine, etc.)
├── utils/ # Utilities (crypto, parsing)
├── types/ # TypeScript definitions
server/
├── index.ts # Main server file
├── healthcheck.js # Health check script
# Frontend build
npm run build
# Server build
npm run build:serverThe system includes comprehensive error handling and logging for debugging.
- Efficient piece management and validation
- Connection pooling and reuse
- Memory-efficient data structures
- Optimized Docker builds
- Rate limiting and resource management
- Application health endpoint
- Docker health checks
- Connection monitoring
- Real-time peer statistics
- Torrent swarm information
- System resource usage
- Network connection stats
Complete deployment with Nginx reverse proxy and persistent storage.
Single container deployment with built-in web server.
Direct Node.js deployment with process management.
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues, questions, or contributions, please use the GitHub issue tracker.