Development
This guide covers building, developing, and contributing to aMuTorrent.
Table of Contents
Section titled “Table of Contents”Prerequisites
Section titled “Prerequisites”- Node.js: v18 or higher
- npm: v9 or higher
- aMule: Running instance with EC enabled (for testing)
Project Structure
Section titled “Project Structure”amutorrent/├── server/ # Backend (Node.js/Express)│ ├── server.js # Main entry point│ ├── database.js # SQLite database setup│ ├── lib/ # Utility libraries│ │ ├── qbittorrent/ # qBittorrent API compatibility layer│ │ ├── torznab/ # Torznab API handler│ │ ├── logger.js # Logging utility│ │ └── ... # Other utilities│ ├── modules/ # Feature modules│ │ ├── amuleManager.js # aMule EC connection manager│ │ ├── queuedAmuleClient.js # Queued aMule operations│ │ ├── webSocketHandlers.js # WebSocket message handlers│ │ ├── metricsAPI.js # Historical metrics API│ │ ├── historyAPI.js # Download history API│ │ ├── torznabAPI.js # Torznab indexer routes│ │ ├── qbittorrentAPI.js # qBittorrent-compatible routes│ │ ├── config.js # Configuration management│ │ └── ... # Other modules│ ├── middleware/ # Express middleware│ ├── data/ # Runtime data (SQLite, config)│ └── logs/ # Application logs│├── static/ # Frontend (React)│ ├── app.js # Application entry point│ ├── index.html # HTML template│ ├── components/ # React components│ │ ├── AppContent.js # Main app component│ │ ├── common/ # Shared components (Table, Icon, Button, etc.)│ │ ├── views/ # Page views (Downloads, Search, Settings, etc.)│ │ ├── modals/ # Modal dialogs│ │ ├── layout/ # Layout components (Header, Sidebar, Footer)│ │ ├── dashboard/ # Dashboard widgets│ │ └── settings/ # Settings-specific components│ ├── contexts/ # React contexts (Auth, Theme, WebSocket)│ ├── hooks/ # Custom React hooks│ ├── utils/ # Utility functions│ └── dist/ # Built JavaScript bundle│├── src/ # Source files│ └── input.css # Tailwind CSS input│├── docs/ # Documentation├── build.mjs # Frontend build script (esbuild)├── tailwind.config.js # Tailwind configuration├── package.json # Frontend dependencies└── Dockerfile # Docker build configurationDevelopment Setup
Section titled “Development Setup”1. Clone the Repository
Section titled “1. Clone the Repository”git clone https://github.com/got3nks/amutorrent.gitcd amutorrent2. Install Dependencies
Section titled “2. Install Dependencies”# Install frontend dependenciesnpm install
# Install server dependenciescd server && npm install && cd ..3. Start Development Mode
Section titled “3. Start Development Mode”Open two terminals:
Terminal 1 - Frontend (CSS + JS watching):
npm run watchTerminal 2 - Server with auto-reload:
# Run from project root (not from server directory)npx --prefix ./server/ nodemon server/server.js4. Access the Application
Section titled “4. Access the Application”Open http://localhost:4000 in your browser.
Building
Section titled “Building”Production Build
Section titled “Production Build”# Build CSS and JavaScriptnpm run build
# Start server (run from project root)node server/server.jsIndividual Build Commands
Section titled “Individual Build Commands”# Build Tailwind CSS onlynpm run build:css
# Build JavaScript bundle onlynpm run build:js
# Watch CSS changesnpm run watch:css
# Watch JavaScript changesnpm run watch:jsDocker Build
Section titled “Docker Build”# Build Docker imagedocker build -t amutorrent .
# Run containerdocker run -p 4000:4000 amutorrentArchitecture Overview
Section titled “Architecture Overview”Backend
Section titled “Backend”The server uses a modular architecture where each feature is encapsulated in its own module:
- Express.js serves the REST API and static files
- WebSocket (ws) provides real-time updates to clients
- SQLite (better-sqlite3) stores metrics, history, and configuration
- amule-ec-node handles communication with aMule via EC protocol
Request Flow:
- HTTP requests → Express routes → Module handlers
- WebSocket messages → webSocketHandlers.js → Module operations
- Background tasks → arrManager.js, autoRefreshManager.js
Frontend
Section titled “Frontend”The frontend is built with React using createElement syntax (no JSX) for simplicity:
import React from 'https://esm.sh/react@18.2.0';const { createElement: h } = React;
// Components use h() instead of JSXconst MyComponent = () => { return h('div', { className: 'container' }, h('h1', null, 'Title'), h('p', null, 'Content') );};Key Patterns:
- Contexts provide global state (Auth, Theme, WebSocket, Data)
- Hooks encapsulate reusable logic
- Table component handles both desktop and mobile views with
mobileCardRender
Build System
Section titled “Build System”The frontend build uses:
- esbuild for JavaScript bundling (fast, handles esm.sh imports)
- Tailwind CSS for styling
Contributing
Section titled “Contributing”Code Style
Section titled “Code Style”- Use ES6+ features
- Follow existing patterns in the codebase
- Use meaningful variable and function names
- Keep functions focused and small
Component Guidelines
Section titled “Component Guidelines”React Components:
- Use function components with hooks
- Use
createElementsyntax, not JSX - Memoize callbacks with
useCallbackwhen passed as props - Use
useMemofor expensive computations
Server Modules:
- Extend
BaseModulefor consistent initialization - Use the logger utility for consistent logging
- Handle errors gracefully and return appropriate HTTP status codes
Testing Changes
Section titled “Testing Changes”Before submitting:
- Test the feature manually in both desktop and mobile views
- Verify dark mode works correctly
- Check browser console for errors
- Test with aMule disconnected to ensure graceful handling
Pull Request Process
Section titled “Pull Request Process”- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes
- Test thoroughly
- Commit with descriptive messages
- Push and create a Pull Request
Useful Commands
Section titled “Useful Commands”# View server logstail -f server/logs/server.log
# Reset configuration (start fresh)rm server/data/config.json
# Clear metrics databaserm server/data/metrics.dbDebugging
Section titled “Debugging”Server-side
Section titled “Server-side”Enable verbose logging:
DEBUG=* node server/server.jsOr check the log files:
tail -f server/logs/server.logClient-side
Section titled “Client-side”- Open browser DevTools (F12)
- Check Console for errors
- Use Network tab to inspect WebSocket messages
- React DevTools extension helps debug component state
Common Issues
Section titled “Common Issues”“Cannot connect to aMule”
- Verify aMule EC is enabled and the password is correct
- Check if the port is accessible
“Module not found” during build
- Run
npm installin both root andserver/directories
CSS changes not appearing
- Ensure
npm run watch:cssis running - Check for Tailwind class typos