Overview
OfflineTube consists of two separate services that need to run simultaneously during development:- Frontend: Next.js 16 (App Router) running on port 3000
- Backend: FastAPI with yt-dlp running on port 8001
Prerequisites
Before starting development, ensure you have the following installed:System Requirements
- Node.js 20 or higher
- npm 10 or higher
- Python 3.10 or higher
- ffmpeg and ffprobe (must be available in PATH)
Verify FFmpeg Installation
Installation
cd mini-services/offlinetube-api
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
Running in Development Mode
You’ll need two terminal windows to run both services simultaneously.Configuration
Backend URL Configuration
The frontend automatically resolves the backend API URL:- If
NEXT_PUBLIC_API_URLis set, it uses that value - Otherwise, it uses
http(s)://<current-host>:8001
.env.local in the project root (optional):
Directory Structure
The backend creates these directories automatically:Hot Reload and Development Features
Frontend Hot Reload
- Automatic: Changes to components, pages, and styles are reflected immediately
- Fast Refresh: React state is preserved during updates
- Error Overlay: Build errors and runtime errors appear in the browser
Backend Auto-Reload
- File Watching: Changes to
main.pytrigger automatic restart - Fast Startup: Uvicorn reloads quickly for rapid iteration
Debugging
Frontend Debugging
Browser DevTools:- Open Chrome/Firefox DevTools (F12)
- Console tab shows logs and errors
- Network tab shows API requests to backend
.vscode/launch.json:
Backend Debugging
Print Debugging:.vscode/launch.json:
API Testing
Test backend endpoints directly:http://localhost:8001/docs
Common Development Issues
Failed to Fetch / Connection Refused
Symptoms: Frontend shows “Failed to fetch” errors Solutions:- Verify backend is running on port 8001
- Check that no firewall is blocking port 8001
- Ensure
NEXT_PUBLIC_API_URLpoints to correct backend
FFmpeg Not Found
Symptoms: Downloads fail with “FFmpeg no está instalado” Solutions:Port Already in Use
Symptoms:EADDRINUSE or Address already in use
Solutions:
Python Virtual Environment Issues
Symptoms: Import errors, module not found Solutions:Thumbnails Not Displaying
Symptoms: Gray placeholder images instead of video thumbnails Cause: Backend falls back to remote YouTube thumbnails when local cache fails Note: This is expected behavior. Thumbnails are cached locally after first download.No Audio in Downloaded Files
Symptoms: Video plays but has no sound Cause: Backend validates audio tracks using ffprobe and marks downloads as error if audio is missing Solutions:- Try different quality/format selection
- Check yt-dlp logs in terminal for format issues
CORS Errors
Symptoms: Browser console shows CORS policy errors Cause: Backend CORS middleware misconfiguration Note: Backend is configured withallow_origins=["*"] for development (main.py:82). This should not be an issue in dev mode.
Development Workflow Tips
- Keep both terminals visible to catch errors in real-time
- Check dev.log for frontend logs:
tail -f dev.log - Use the API docs at
http://localhost:8001/docsto test endpoints - Clear downloads folder periodically to save disk space
- Monitor network tab in browser DevTools to debug API calls
LAN Access for Testing
To test on other devices (phone, tablet) on the same network:Next Steps
Once development is complete:- See Production Deployment for building and running in production
- See Docker Deployment for containerized deployment