# MASTER ARCHITECTURE & DEVELOPMENT PROMPT ## Project: "Chalchitra" (A Pixel-Perfect, Login-Less YouTube Clone) **Context:** The goal is to build a highly advanced, 1-to-1 visual and functional replica of YouTube using Next.js. This clone must operate entirely in a **Login-Less** environment. This means all user-specific data (History, Subscriptions, Playlists, Settings) MUST be stored client-side (using `localStorage`, `IndexedDB`, or a state manager with persistence like `Zustand`). Below are the detailed, heavily researched technical specifications to implement every requested feature precisely. --- ### MODULE 1: THE "DOUBLE CLICK" BUG RESOLUTION (UI/UX Interactivity) **Background:** Users currently have to double-click elements (video cards, buttons, links) to trigger actions. This is a severe UX anti-pattern typically caused by Next.js `` mishandling, overlapping hitboxes, or event propagation issues. **Implementation Steps:** 1. **Remove Next.js Link Overlays:** Ensure that `` tags or `` components wrap the entire clickable component rather than having overlapping absolute `
` tags capturing the first click. 2. **Event Bubbling & Stop Propagation:** For elements that have multiple actions (e.g., clicking a video thumbnail routes to `/watch`, but clicking the channel icon routes to `/channel`), use `e.stopPropagation()` and `e.preventDefault()` on the inner elements. 3. **Hydration & State Sync:** Ensure buttons aren't disabled on the initial client render due to hydration mismatches. Use `suppressHydrationWarning` if necessary. 4. **Touch vs. Mouse Events:** If using custom gesture libraries, ensure `onPointerDown` or `onTouchStart` isn't blocking the native `onClick` event. --- ### MODULE 2: ADVANCED QUALITY SELECTOR (144p to 1080p) **Background:** By default, simple YouTube API parsers only extract "pre-muxed" (Audio + Video combined) formats, which typically max out at 360p or 720p. To get 144p, 240p, 480p, and 1080p, we must use YouTube's `adaptiveFormats` (DASH streams). **Implementation Steps:** 1. **DASH Parsing (`lib/innertube.ts` / `lib/parser.ts`):** - Parse `player_response.streamingData.adaptiveFormats`. - Filter out the video tracks (`mimeType: 'video/mp4'`) and audio tracks (`mimeType: 'audio/mp4'`). - Group the video formats by resolution: `144p`, `240p`, `360p`, `480p`, `720p`, `1080p`. 2. **Audio/Video Sync System:** Since higher qualities are video-only, the video player must play the audio stream and video stream simultaneously. - You can use standard HTML5 by having `