How retrogtx/youtube-clipper works
Project type and purpose
• This is a full-stack SaaS web application (“YouTube Clipper”) that lets authenticated users submit YouTube URLs and time-ranges, clips the video on the server, and streams/downloads the result.
• Frontend: Next.js 13 “app” directory + TailwindCSS + Shadcn/UI, with Drizzle ORM for user/session data.
• Backend: Bun-powered Node.js/Express microservice handling the heavy lifting (yt-dlp + ffmpeg).
File structure
• Top-level “backend” and “frontend” directories clearly separate UI/API from processing logic.
• Frontend “app”, “components”, “lib” + Drizzle config indicate an MVC/BFF-style pattern:
• “app” holds pages + Next API routes (auth).
• “lib” holds client/server helpers (auth-client, DB, schema).
• “drizzle” contains DB migrations and metadata.
• Backend is a single Express service (src/index.ts) with no UI.
• Presence of bun.lock in both indicates Bun runtime for each.
README for additional insights
• Mentions next-auth (via [...all] route), Drizzle ORM for database, and external CLI tools (yt-dlp, ffmpeg).
• No cloud storage: processed clips are streamed back, downloaded client-side.
Main components and their interactions
a. Frontend (Next.js UI + API)
• UI Layer: React pages (login/page.tsx, page.tsx) + Shadcn/UI components.
• Auth API: /api/auth/[...all] for sign-in/sign-out, backed by Drizzle + database.
• DB Layer: Drizzle ORM connects to Postgres/SQLite via lib/db.ts + lib/schema.ts.
• Clip Request UI: form that POSTs to Backend service.
b. Backend (Express microservice on Bun)
• Clip API endpoint (POST /clip): parses URL + timestamps.
• Video Processor: spawns yt-dlp to fetch raw media, then invokes ffmpeg to trim/encode.
• Response: streams binary clip.mp4 back to the frontend for client download.
• (Optional) Temporary storage: /uploads folder or in-memory streams.
c. External Services
• yt-dlp CLI for partial YouTube downloads.
• ffmpeg CLI for editing and re-encoding.
d. Database
• Stores user accounts, sessions, and maybe clipping history.
Architectural patterns and design principles
• Clear separation of concerns:
• Frontend handles user interaction, authentication, and display.
• Backend focuses on CPU-heavy I/O tasks (video processing).
• Database isolates state.
• BFF pattern: Frontend’s Next API routes act as a middle layer for auth/DB.
• Microservice for video processing: can be scaled or containerized independently.
• Use of CLI tools via child processes for specialized workloads.