Rektube is a mobile music streaming application built with Flutter for the ACS314 Mobile Development course at Daystar University. It allows users to search for music, play audio streams, manage playlists, like songs, and view playback history. The application leverages a self-hosted Piped instance (acting as a frontend for YouTube data) and a PostgreSQL database for user data persistence.
- User Authentication: Secure Signup and Login using email/username and password (passwords hashed with bcrypt).
- Music Discovery: Search for tracks via the self-hosted Piped instance.
- Playback: Stream audio using the
media_kitpackage. Includes standard controls (play/pause, seek), shuffle, and repeat modes. - Mini Player: Persistent player control visible across core app screens.
- Library Management:
- Liked Songs: Mark favorite tracks.
- Playlists: Create custom playlists and add tracks to them.
- History: Automatically tracks recently played songs.
- Explore: View trending music (fetched from Piped).
- Dashboard: Personalized view showing recently played and liked songs.
- Settings: Basic app settings including theme toggling (Light/Dark) and app info.
- Dynamic Theming: Supports both Light and Dark themes.
- Frontend: Flutter & Dart
- State Management: GetX (UI state, routing, simple controllers), Riverpod (Data fetching, async state, dependency injection)
- Audio Playback:
media_kit - Database ORM:
drift+drift_postgres - Database: PostgreSQL
- API Backend: Self-Hosted Piped (Dockerized, using Caddy reverse proxy within Docker)
- Networking:
dio(for direct Piped API calls),http - Local Storage:
get_storage(preferences),flutter_secure_storage(user session) - Utilities:
flutter_dotenv,bcrypt,intl,package_info_plus,equatable,flutter_native_splash,flutter_launcher_icons
configs/: Color definitions, theme data (ThemeData), app-wide constants.controllers/: GetX controllers managing UI state and user interactions for specific features (auth, player, navigation, settings).database/: Drift setup including:connection/: PostgreSQL connection logic.tables/: Database table schemas defined using Drift.daos/: Data Access Objects with methods for querying tables (generated code included).type_converters.dart: Custom converters (e.g., for PostgreSQL timestamps).database.dart: Main Drift database class definition.
models/: Plain Dart Objects representing data structures (User, Track, Playlist).providers/: Riverpod providers for injecting repositories, DAOs, and managing application-level state (auth, player state checks).repositories/: Abstraction layer handling data fetching (Piped, DB) and business logic (Auth, Player, Library).utils/: Helper functions, route definitions, exception classes, secure storage wrapper, input validators.views/: Contains UI code:screens/: Top-level application screens for different features.widgets/: Reusable UI components (common, core-feature specific, player).
main.dart: Application entry point, initialization logic, root widget (MyApp).
Follow these steps to set up the project for development. Instructions are provided primarily for Ubuntu, with notes for Windows where applicable.
- Flutter SDK: Install Flutter for your operating system by following the official Flutter installation guide. Ensure
flutteranddartcommands are available in your PATH. - Git: Install Git (https://git-scm.com/).
- Docker & Docker Compose:
- Ubuntu: Follow the official Docker documentation to install Docker Engine and the Docker Compose plugin. Ensure your user is added to the
dockergroup to run commands withoutsudo. - Windows: Install Docker Desktop. WSL2 backend is highly recommended. Docker Compose is typically included.
- Ubuntu: Follow the official Docker documentation to install Docker Engine and the Docker Compose plugin. Ensure your user is added to the
- PostgreSQL Client: You need
psqlor a GUI client (like DBeaver, pgAdmin) to interact with the database.- Ubuntu:
sudo apt update && sudo apt install postgresql-client - Windows: Can be installed as part of the PostgreSQL server installation or separately.
- Ubuntu:
- PostgreSQL Server: You need a running PostgreSQL server accessible from your development machine. This can be:
- A local installation on your host machine (Ubuntu/Windows).
- A separate Docker container.
- Note: The Piped Docker setup includes its own PostgreSQL container, but the Flutter app connects to a different one defined in your
.envfile. Ensure this separate DB server is running.
- Ngrok (Recommended for Mobile Testing):
- Sign up for a free account at ngrok.com.
- Install the Ngrok CLI (https://ngrok.com/download).
- Authenticate the CLI with your authtoken:
ngrok config add-authtoken YOUR_AUTH_TOKEN(replaceYOUR_AUTH_TOKENwith the token from your Ngrok dashboard).
- IDE/Editor: Android Studio or VS Code with Flutter extensions installed.
- Android Emulator / Physical Device: For running the Flutter app. Ensure USB debugging is enabled for physical devices.
-
Clone the Rektube Repository:
git clone https://github.com/andomeder/rektube.git cd rektube -
Set up Self-Hosted Piped Backend:
- Clone Official Piped Docker Repo: First, clone the official setup repository from TeamPiped separately from the Rektube project folder:
git clone https://github.com/TeamPiped/Piped-Docker.git cd Piped-Docker - Run Configuration Script: Execute the configuration script. When prompted:
- Enter desired hostnames (e.g.,
piped.rektube,pipedapi.rektube,pipedproxy.rektube- these are mainly used internally by Docker). - Choose
caddyas the reverse proxy. - Choose
httpwhen asked about reachability (as we are not setting up TLS within Docker here).
./configure-instance.sh
- Enter desired hostnames (e.g.,
- Replace Configuration File: Copy the customized
Caddyfilefrom the Rektube project'spiped/directory into thePiped-Docker/config/directory, overwriting the file generated by the script:# Assuming you are inside the Piped-Docker directory # Adjust the path to your Rektube project's piped folder if necessary cp ../rektube/piped/Caddyfile ./config/
- Replace Docker Compose File: Copy the customized
docker-compose.ymlfrom the Rektube project'spiped/directory into thePiped-Docker/directory, overwriting the generated one:# Assuming you are inside the Piped-Docker directory cp ../rektube/piped/docker-compose.yml ./ - Start Services: Start the Docker containers using the modified configuration:
Wait a minute for services to initialize. Use
docker compose up -d
docker compose logs -f caddyordocker compose logs -f piped-backendto check status.
- Clone Official Piped Docker Repo: First, clone the official setup repository from TeamPiped separately from the Rektube project folder:
-
Set up PostgreSQL Database (for Rektube App):
- Connect to your main PostgreSQL server (local install or separate container).
- Create the database user (e.g.,
yourusername) and database (e.g.,rektubeorpostgres- match.env!). Grant privileges.-- Example using psql sudo -u postgres psql # Or connect as your admin user CREATE DATABASE rektube; -- Or your chosen DB name from .env CREATE USER yourusername WITH ENCRYPTED PASSWORD 'admin'; -- Use a STRONG password! GRANT ALL PRIVILEGES ON DATABASE rektube TO yourusername; \q
- Connect to the app's database:
psql -U yourusername -d rektube -h localhost # Or your DB host - Execute the SQL commands from
database.sql(or copy-paste from previous response) to create the required tables (users,playlists, etc.) and theupdated_attrigger.
-
Set up Ngrok (Recommended for Mobile Testing):
- Ensure Ngrok CLI is installed and authenticated.
- Copy the
ngrok.ymlfile from the Rektube project root to your Ngrok config directory:- Ubuntu:
cp ngrok.yml ~/.config/ngrok/ngrok.yml - Windows: Copy
ngrok.ymlto%HOMEPATH%\.config\ngrok\
- Ubuntu:
- Start Ngrok in a separate terminal:
ngrok start --all --config=ngrok.yml
- Note the TCP forwarding address/port for PostgreSQL and the HTTPS forwarding URL for Caddy/Piped.
-
Configure Flutter App (
.env):- Navigate back to the Rektube project root (
cd ../rektube). - Copy
.env.exampleto.env:cp .env.example .env - Edit
.envwith your specific details:DATABASE_HOST: Ngrok TCP hostname (e.g.,0.tcp.eu.ngrok.io).DATABASE_PORT: Ngrok TCP port (e.g.,15405).DATABASE_NAME: Your app's database name (e.g.,rektube).DATABASE_USER: Your DB user (e.g.,yourusername).DATABASE_PASSWORD: Your DB user's password.PIPED_INSTANCE_URL: Ngrok HTTPS URL for Caddy (e.g.,https://d05f....ngrok-free.app).NGROK_HOST: Hostname part of thePIPED_INSTANCE_URL(e.g.,d05f....ngrok-free.app).
- Navigate back to the Rektube project root (
-
Build & Run Flutter App:
- Get dependencies:
flutter pub get - Generate Drift code:
flutter pub run build_runner build --delete-conflicting-outputs - Generate icons/splash (Optional):
flutter pub run ... - No
adb reverseneeded if using Ngrok URLs in.env. - Run the app:
flutter run
- Get dependencies:
If you prefer not to use Ngrok and your development machine and mobile device are on the same local Wi-Fi network:
- Find Laptop IP: Use
ip addr(Linux/macOS) oripconfig(Windows) to find your laptop's local IP address (e.g.,192.168.1.10). - Configure
.env:- Set
DATABASE_HOSTto your laptop's local IP address. - Set
DATABASE_PORTto your PostgreSQL server's port (5432). - Set
PIPED_INSTANCE_URLtohttp://YOUR_LAPTOP_IP:3142(using your IP and the host port mapped to Caddy indocker-compose.yml). - Set
NGROK_HOSTto your laptop's IP address (used by the rewrite helper).
- Set
- Firewall: Ensure your host machine's firewall allows incoming connections on the PostgreSQL port (5432) and the Piped Caddy port (3142) from your local network.
- PostgreSQL
listen_addresses: Ensure your PostgreSQL server is configured to listen on your network IP (or*) inpostgresql.conf. - PostgreSQL
pg_hba.conf: Ensure connections are allowed from your local network range for your database user. - Run App: Run
flutter run.
The piped/piped.conf file is an example Apache configuration for setting up a reverse proxy on your host machine if you were not using Docker's Caddy or Ngrok as the primary entry point. If you are using the recommended Docker Caddy setup and Ngrok, you generally do not need to configure Apache for this project. This file is provided for reference if you choose a different hosting/proxy strategy.
- Connection Refused (Database): Verify PostgreSQL server status,
.envdetails match Ngrok TCP or local IP/port, Ngrok tunnel active (if used), firewall rules,pg_hba.conf,listen_addresses. - Connection Refused / 404 / 50x Errors (Piped API): Verify Piped Docker containers running (
docker ps,docker compose logs caddy,docker compose logs piped-backend),.envdetails match Ngrok HTTPS URL or local IP/port, Ngrok tunnel active (if used), firewall rules. Test API endpoints directly via the URL in.env. - Thumbnail Errors (
No host specified...): EnsurepipedInstanceUrlconstant is loading correctly (checkmain.dartprints). VerifyrewritePipedUrlForLocalDevuses the correct Ngrok/local host. EnsureTrackListItemetc. use thetrack.thumbnailUrlgetter. Check DB values (track_thumbnail_path). - "Add to Playlist" Fails: Check Flutter console for errors. Add print statements in the dialog
onTapandLibraryRepository.addTrackToPlaylist. EnsureTrackListItemis aConsumerWidget.
- Implement full playlist management (rename, delete, remove tracks, reorder).
- Implement full Liked Songs screen.
- Add queue management features to the player screen.
- Implement actual Appearance/Account settings.
- Add pull-to-refresh on library/dashboard screens.
- Implement caching for API requests (search, trending).
- Add unit and widget tests.
- Refine error handling and user feedback.
- Investigate integrating native Android features if needed (e.g., background playback services, notifications).
- Developed for ACS314 Mobile Development, Daystar University.
- Uses the Piped API (https://docs.piped.video/).
- Relies on various open-source Flutter packages.
