Viralio — Architecture Reference
A quick reference for the architecture behind Viralio, an AI video clipper CMS: paste a YouTube URL in, get scored/subtitled/vertical clips out, optionally auto-published to YouTube.
Stack
| Layer | Technology |
|---|---|
| App | Laravel 12, PHP 8.4 |
| Admin UI | Filament v4 |
| Data | PostgreSQL, Redis |
| Queue | Horizon |
| Media | FFmpeg, yt-dlp |
| AI | Google Gemini (highlight scoring + optional transcription) |
Project Layout
app/
Actions/Video/ CreateVideo, RegenerateHighlight, GenerateClip
Contracts/ YoutubeDownloader, VideoProcessor, TranscriptionInterface, HighlightAnalyzer
DTO/ VideoMetadataData, TranscriptData, HighlightData, ...
Enums/ VideoStatus, ClipStatus, ProcessingStep, TranscriptionProvider
Jobs/ the pipeline (below) + YouTube upload/analytics/token-refresh jobs
Repositories/ Video, Highlight, Clip, Settings
Services/
Youtube/ yt-dlp wrapper
Ffmpeg/ ffmpeg wrapper
Gemini/ GeminiClient, GeminiService, Prompts (centralized)
Transcription/ TranscriptionManager → Gemini | Whisper
Subtitle/ SRT generation
Filament/ Resources, Pages, Widgets
Bindings in App\Providers\DomainServiceProvider — swapping transcription provider or storage disk is a config change, not a pipeline edit.
Processing Pipeline
CreateVideoAction
└─ Bus::chain:
DownloadYoutubeJob → ExtractAudioJob → TranscribeAudioJob → AnalyzeHighlightJob
│
Bus::batch (one chain per highlight) ───────────┘
GenerateClipJob → GenerateSubtitleJob → GenerateThumbnailJob
│
FinishVideoJob (batch → then)
- First 4 steps: strict
Bus::chain— must run in order. - Per-highlight clip generation:
Bus::batch, runs in parallel, one chain per highlight. - Every step writes
processing_logs+queue_histories. A failed clip chain marks only that clip failed — doesn’t cancel siblings or the batch.
AI Highlight Scoring
Gemini scores each candidate segment 0–100 on: hook, curiosity, emotion, education, entertainment, shareability + overall. Strict JSON response, validated before persisting — invalid output → GeminiException, never silently saved. Prompts centralized in App\Services\Gemini\Prompts.
YouTube Publishing (OAuth2)
- Connect channel: Google OAuth2, scopes
youtube.upload,youtube.readonly,youtube.force-ssl. Redirect URI must match{APP_URL}/oauth/youtube/callbackexactly. - Upload:
CreateUploadJobAction→UploadSchedulerService→UploadYoutubeVideoJob→TokenRefreshService+YouTubeUploadService(resumable/chunked) →UploadRepository. - Scheduled publish = job dispatched with a delay, no separate cron needed.
- Retry re-runs the same job (keeps metadata/history), doesn’t duplicate.
- Tokens auto-refresh before every upload + hourly for soon-to-expire ones. Revoked refresh token → account flagged Reconnect Required + notification.
- Analytics (views/likes/comments):
SyncYoutubeAnalyticsJob, hourly per connected channel via scheduler. - Data:
youtube_accounts,upload_jobs,youtube_uploads.
Debugging
| Symptom | Where to look |
|---|---|
| Upload stuck/failing | Horizon (/horizon) → video-processing queue → UploadYoutubeVideoJob |
| Error detail | Upload Queue → View Error / upload_jobs.error_message |
redirect_uri_mismatch | Redirect URI in Google Cloud must match exactly (scheme/host/port/path) |
| Consent blocked | Add Google account under Test users on consent screen |
| Quota exceeded | YouTube Data API daily quota (~1600 units/upload); retries back off automatically |
Admin Panel
Filament v4 — Resources/Pages/Widgets cover CRUD + status views without a custom dashboard build. API keys and OAuth secrets encrypted at rest. Runtime-tunable config (Gemini model, binary paths, clip defaults) lives in system_settings, DB-overrides-env, cached after first read.
REST API
Sanctum bearer token auth.
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/videos | Submit YouTube URL → starts processing |
| GET | /api/videos | List videos (paginated) |
| GET | /api/videos/{id} | Video + highlights + clips |
| GET | /api/generated-clips | List clips (filter video_id, status) |
| POST | /api/regenerate-highlight | Re-run analysis |
| POST | /api/generate-clip | (Re)generate one clip |
Deployment
| Service | Purpose |
|---|---|
nginx | Internal web entrypoint → Filament + API |
app | PHP-FPM, Laravel + ffmpeg + yt-dlp baked in |
horizon | Queue worker for the pipeline |
scheduler | schedule:work — snapshots, pruning, hourly analytics/token-refresh |
postgres | Database |
redis | Cache / queue / sessions |
cp .env.example .env # set GOOGLE_API_KEY
docker compose up -d --build
TLS: Caddy sits in front of internal nginx, auto-provisions/renews Let’s Encrypt certs. nginx stays HTTP-only on the Docker network.
{$APP_DOMAIN} {
reverse_proxy nginx:80
request_body { max_size 512MB } # clips can be sizeable
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
}
}
Key Env Vars
GOOGLE_API_KEY, GEMINI_MODEL, FFMPEG_PATH, FFPROBE_PATH, YTDLP_PATH, TRANSCRIPTION_DRIVER, VIRALIO_CLIP_*, VIRALIO_JOB_*, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, GOOGLE_REDIRECT_URI, YOUTUBE_DEFAULT_CATEGORY, YOUTUBE_DEFAULT_PRIVACY.
Checklist When Extending
- New pipeline step? Decide chain (must be sequential) vs batch (can run in parallel) — don’t default to chain for everything.
- New external API call (AI or otherwise)? Validate the response shape before persisting, same as any untrusted input.
- New per-clip side effect? Give it its own job — retry granularity and Horizon visibility both depend on it.
- New publishing target beyond YouTube? Roadmap seam exists; mirror the OAuth + queued-upload + token-refresh + retry pattern already built for YouTube.