# aayush9029/nativeyoutube architecture

> Architecture diagram of the GitHub repository aayush9029/nativeyoutube, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aayush9029/nativeyoutube
- Repository: https://github.com/aayush9029/nativeyoutube

## Overview

##### Project Type & Purpose
- Type: Native macOS menu-bar application, built with SwiftUI & MVVM.

##### File Structure
Top-level:
– .github/workflows/swift.yml → CI build/test
– NativeYoutube.xcodeproj → Xcode project files
– NativeYoutube/ → source root
Under NativeYoutube/:
- API/ → network request wrappers (PlaylistsRequest.swift, SearchRequest.swift)
- Models/ → data types, constants, enums
- ViewModels/ → state containers (AppStateViewModel, SearchViewModel, etc.)
- Views/ → SwiftUI screens & shared components
- ViewModifiers/ → SwiftUI style modifiers
- Extensions/ & Helpers/ → utility functions & view bridging
- Assets, Info.plist, entitlements, App entry (NativeYoutubeApp.swift)

##### Pull Architecture Hints from README
- macOS 13+ menu-bar app
- Requires Google API key
- Features: search, playlists, custom playlist ID, preferences UI

##### Main Components & Their Relationships
a. Frontend/UI Layer
– NativeYoutubeApp (App entry) creates a MenuBarIcon → On click, presents Views.
– Views: SearchVideosView, PlayListView, PreferencesView, Shared sub-views.
b. ViewModel Layer (MVVM)
– AppStateViewModel: orchestrates which view is visible & global state.
– SearchViewModel & PlayListViewModel: handle search and playlist flows.
– YoutubePreferenceViewModel: stores & retrieves API key & custom IDs.
c. Model Layer
– VideoModel, Enums, Constants describe data structures.
d. API / Network Layer
– PlaylistsRequest & SearchRequest: Perform HTTP calls to YouTube Data API (via URLSession/async).
– Parse JSON → Model objects.
e. Persistence & Settings
– UserDefaults (via ViewModels) or Keychain for API key.
f. External Service
– YouTube Data API (requires API key, returns JSON).

##### Important Architectural Patterns & Principles
- MVVM: clear separation of view logic (Views) from business logic (ViewModels).
- Single source of truth: AppStateViewModel manages global UI state.
- Dependency inversion: Views depend on abstracted ViewModels, not concrete network code.
- Async/await or Combine for reactive data flows.

##### Finishing Touches
– Label every component clearly.
– Show arrowheads to indicate data/control flow.

## Diagram (Mermaid)

```mermaid
graph TB
  %% UI Layer
  subgraph "UI Layer"
    direction TB
    App["NativeYoutubeApp"]:::ui
    Menu["MenuBarIcon"]:::ui
    SearchView["SearchVideosView"]:::ui
    PlaylistView["PlayListView"]:::ui
    PrefsView["PreferencesView"]:::ui
    GenPref["GeneralPreferenceView"]:::ui
    LogPref["LogPrefrenceView"]:::ui
    YTPref["YoutubePreferenceView"]:::ui
    Shared["Shared UI Components"]:::ui
  end

  %% ViewModel Layer
  subgraph "ViewModel Layer"
    direction TB
    AppStateVM["AppStateViewModel"]:::vm
    SearchVM["SearchViewModel"]:::vm
    PlaylistVM["PlayListViewModel"]:::vm
    PrefsVM["YoutubePreferenceViewModel"]:::vm
  end

  %% API Layer
  subgraph "API Layer"
    direction TB
    SearchReq["SearchRequest"]:::api
    PlaylistReq["PlaylistsRequest"]:::api
  end

  %% Model Layer
  subgraph "Model Layer"
    direction TB
    VideoModel["VideoModel"]:::model
    EnumsConst["Enums & Constants"]:::model
    Extensions["Extensions"]:::model
    Helpers["Helpers"]:::model
  end

  %% Persistence
  subgraph "Persistence"
    direction TB
    UserDefaults["UserDefaults"]:::persistence
  end

  %% External Service
  subgraph "External Service"
    direction TB
    YouTubeAPI["YouTube Data API"]:::external
  end

  %% Connections
  App -->|"launches"| Menu
  Menu -->|"shows"| SearchView
  Menu -->|"shows"| PlaylistView
  Menu -->|"shows"| PrefsView

  SearchView -->|"binds to"| SearchVM
  PlaylistView -->|"binds to"| PlaylistVM
  PrefsView -->|"binds to"| PrefsVM
  GenPref -->|"inside"| PrefsView
  LogPref -->|"inside"| PrefsView
  YTPref -->|"inside"| PrefsView
  Shared -->|"used by"| SearchView
  Shared -->|"used by"| PlaylistView

  AppStateVM -->|"controls"| SearchView
  AppStateVM -->|"controls"| PlaylistView
  AppStateVM -->|"controls"| PrefsView

  SearchVM -->|"calls"| SearchReq
  PlaylistVM -->|"calls"| PlaylistReq
  PrefsVM -->|"reads/writes"| UserDefaults

  SearchReq -->|"HTTP request"| YouTubeAPI
  PlaylistReq -->|"HTTP request"| YouTubeAPI
  YouTubeAPI -->|"JSON response"| SearchReq
  YouTubeAPI -->|"JSON response"| PlaylistReq

  SearchReq -->|"parses"| VideoModel
  PlaylistReq -->|"parses"| VideoModel
  VideoModel -->|"uses"| EnumsConst
  VideoModel -->|"uses"| Extensions
  VideoModel -->|"uses"| Helpers

  SearchReq -->|"returns data to"| SearchVM
  PlaylistReq -->|"returns data to"| PlaylistVM

  SearchVM -->|"updates state"| SearchView
  PlaylistVM -->|"updates state"| PlaylistView
  PrefsVM -->|"updates state"| PrefsView

  %% Click Events
  click App "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/NativeYoutubeApp.swift"
  click Menu "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/ContentView.swift"
  click SearchView "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Views/SearchView/SearchVideosView.swift"
  click PlaylistView "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Views/PlayListView/PlayListView.swift"
  click PrefsView "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Views/PreferencesView/PreferencesView.swift"
  click GenPref "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Views/PreferencesView/GeneralPreferenceView.swift"
  click LogPref "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Views/PreferencesView/LogPrefrenceView.swift"
  click YTPref "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Views/PreferencesView/YoutubePreferenceView.swift"
  click Shared "https://github.com/aayush9029/nativeyoutube/tree/main/NativeYoutube/Views/SharedViews"
  click AppStateVM "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/ViewModels/AppStateViewModel.swift"
  click SearchVM "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/ViewModels/SearchViewModel.swift"
  click PlaylistVM "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/ViewModels/PlayListViewModel.swift"
  click PrefsVM "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/ViewModels/YoutubePreferenceViewModel.swift"
  click SearchReq "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/API/SearchRequest.swift"
  click PlaylistReq "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/API/PlaylistsRequest.swift"
  click VideoModel "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Models/VideoModel.swift"
  click EnumsConst "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Models/Enums.swift"
  click EnumsConst "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Models/Constants.swift"
  click Extensions "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Extensions/NSViewRepresentable+Extension.swift"
  click Helpers "https://github.com/aayush9029/nativeyoutube/blob/main/NativeYoutube/Helpers/DateConverter.swift"

  %% Styles
  classDef ui fill:#cce5ff,stroke:#004085,color:#004085;
  classDef vm fill:#d4edda,stroke:#155724,color:#155724;
  classDef api fill:#ffe5b4,stroke:#ff8c00,color:#ff8c00;
  classDef model fill:#e2ccf0,stroke:#6f42c1,color:#6f42c1;
  classDef persistence fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
  classDef external fill:#f8d7da,stroke:#721c24,color:#721c24;
```
