# PlayTube — Deployment, PWA & Android/iOS guide

> **On cPanel shared hosting?** Follow `docs/CPANEL.md` instead: it covers the Node.js app
> setup, PostgreSQL, the 6-step web installer at `/setup`, and the one-shot
> `bash scripts/cpanel-install.sh` script.

## 1. Server deployment (any Node 20+ host with HTTPS)

```bash
git clone <repo> && cd playtube
cp .env.example .env            # fill DATABASE_URL, AUTH_SECRET, SITE_URL
npm ci
npx drizzle-kit push            # creates all tables (or: npx drizzle-kit generate + migrate)
npm run build
npm start                       # listens on :3000
```

- Put it behind HTTPS (Caddy / Nginx / Vercel-style platform). **HTTPS is required for PWA install.**
- Install `ffmpeg` + `ffprobe` on the host (`apt install ffmpeg`). Uploads are then transcoded to a
  144p→2160p HLS ladder with auto-thumbnails. Without FFmpeg the original file is served progressively.
- Persist `STORAGE_DIR` on a volume, or set `S3_UPLOAD_ENDPOINT` / `S3_PUBLIC_BASE_URL` for object storage.
- Realtime uses in-process SSE. For multiple instances, replace `publish()` in `src/lib/notify.ts` with Redis pub/sub.
- Optional: `RESEND_API_KEY` + `MAIL_FROM` (emails), `GOOGLE_CLIENT_ID/SECRET` (Google login;
  redirect URI `https://YOUR_DOMAIN/api/auth/google/callback`).

## 2. Test the install on a physical phone (no APK needed)

1. Deploy to an HTTPS URL (or use the preview URL provided by your platform).
2. **Android (Chrome):** open the URL → tap **Install app** in the PlayTube header (or ⋮ → Install app).
3. **iPhone (Safari):** Share → **Add to Home Screen**.
4. **Desktop (Chrome/Edge):** click the install icon in the address bar or the Install app button.
5. Verify: opens standalone, offline page appears in airplane mode, `/install` page lists steps.

## 3. Build the Android APK / AAB (on your computer)

Prerequisites: Node 20, JDK 17, Android Studio (SDK 34).

```bash
npm i @capacitor/core @capacitor/cli @capacitor/android @capacitor/ios \
      @capacitor/splash-screen @capacitor/status-bar @capacitor/app
# edit capacitor.config.ts → server.url = your deployed HTTPS URL (or set SITE_URL)
npx cap add android
npx cap sync android
npx cap open android
```

In Android Studio:
- **APK (testing):** Build → Build Bundle(s)/APK(s) → Build APK(s) → `android/app/build/outputs/apk/debug/app-debug.apk`.
  Copy to your phone and install (allow "install unknown apps").
- **AAB (Play Store):** Build → Generate Signed Bundle / APK → Android App Bundle → create a keystore → release.
  Output: `android/app/release/app-release.aab`.
- Command line: `cd android && ./gradlew assembleDebug` / `./gradlew bundleRelease`.

Native features: splash screen + status bar are configured in `capacitor.config.ts`;
back button is handled in `app-shell.tsx` (closes the drawer first); the `<input type="file" accept="video/*">`
upload opens the system file picker / camera / gallery; permissions are declared in `android/app/src/main/AndroidManifest.xml`
(copy those `uses-permission` lines into the generated manifest).

## 4. iOS

```bash
npx cap add ios && npx cap sync ios && npx cap open ios
```
Set a signing team in Xcode, then Product → Archive for TestFlight / App Store.
(Requires macOS.) iOS users can also install via Safari Add to Home Screen.

## 5. Play Store checklist

Signed AAB, 512×512 icon (`public/icons/icon-512.png`), privacy policy URL, content rating
(user-generated content → provide report/block tools: implemented), data-safety form.
