# gignac-cha/tjmedia-popular-youtube architecture

> Architecture diagram of the GitHub repository gignac-cha/tjmedia-popular-youtube, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gignac-cha/tjmedia-popular-youtube
- Repository: https://github.com/gignac-cha/tjmedia-popular-youtube

## Overview

##### Main Components

A. Frontend (UI Layer):
- React-based web application (evident from the UI directory structure)
- Main components:
- Navigation system
- Main content area (List and Video display)
- Common UI components
- State management using Context API (QueryContext, VideoContext)

B. Backend (Serverless Functions):
- Two distinct Lambda functions:
- tjmedia-popular: Fetches ranking data from TJMedia
- youtube-search: Handles YouTube API interactions

C. External Services:
- TJMedia Website (Data Source)
- YouTube API (Video Search)

##### Component Relationships

**[Frontend UI] ←→ [API Gateway]**
- ↓
- [TJMedia Website] ← [tjmedia-popular Lambda] → [Frontend UI]
- [YouTube API] ← [youtube-search Lambda] → [Frontend UI]

##### Detailed Component Breakdown

Frontend (UI):
- Components Layer (Main, Navigation, Common)
- State Management Layer (Contexts, Reducers)
- Data Layer (Queries, Utilities)

Backend (Serverless):
- Their specific responsibilities
- API Gateway as the entry point

##### Important Flows to Highlight

A. Data Fetching Flow:
**User → UI → API Gateway → Lambda → External Service → UI**

B. Video Search Flow:
**List Item Click → YouTube Search Lambda → YouTube API → Video Preview**

##### Additional Elements

- Notes about the main features:
- Date filtering
- Song type filtering (가요, POP, JPOP)
- Video navigation capabilities
- State management flow between components

##### Technical Details

- TypeScript usage throughout the project
- Serverless architecture
- React with Context API for state management
- Story book integration for component development
- Build and deployment workflow (.github/workflows)

##### Video navigation and control

Remember to indicate asynchronous operations and data transformation points, as the application deals with data from multiple sources that need to be integrated and displayed cohesively.

This architecture represents a modern, serverless web application with clear separation of concerns between data fetching, business logic, and presentation layers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[Web Application]
        
        subgraph Components
            MC[Main Content]:::component
            NAV[Navigation]:::component
            COM[Common UI]:::component
            
            subgraph MainContent
                LIST[List Display]:::component
                VID[Video Display]:::component
                VCTRL[Video Controls]:::component
            end
            
            subgraph NavigationSystem
                NAVMAIN[Main Navigation]:::component
                NAVCTRL[Navigation Controls]:::component
            end
            
            subgraph CommonUI
                BTN[Button Components]:::component
                LOAD[Loading Components]:::component
                ERR[Error Components]:::component
                INP[Input Components]:::component
            end
        end
        
        subgraph StateManagement
            QCTX[Query Context]:::state
            VCTX[Video Context]:::state
            QRED[Query Reducer]:::state
            VRED[Video Reducer]:::state
        end
        
        subgraph DataLayer
            TJQ[TJMedia Query]:::data
            YTQ[YouTube Query]:::data
            UTIL[Utilities]:::data
        end
    end
    
    subgraph Backend
        API[API Gateway]:::infra
        
        subgraph LambdaFunctions
            TJL[TJMedia Popular Lambda]:::lambda
            YTL[YouTube Search Lambda]:::lambda
        end
    end
    
    subgraph ExternalServices
        TJ[TJMedia Website]:::external
        YT[YouTube API]:::external
    end
    
    %% Relationships
    UI --> API
    API --> TJL
    API --> YTL
    TJL --> TJ
    YTL --> YT
    TJL --> UI
    YTL --> UI
    
    %% Component Relationships
    MC --> LIST & VID & VCTRL
    NAV --> NAVMAIN & NAVCTRL
    COM --> BTN & LOAD & ERR & INP
    
    %% State Management Flow
    QCTX --> QRED
    VCTX --> VRED
    
    %% Click Events
    click MC "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/Main/"
    click LIST "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/components/Main/List.tsx"
    click VID "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/components/Main/Video.tsx"
    click VCTRL "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/components/Main/VideoControls.tsx"
    click NAV "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/Navigation/"
    click NAVMAIN "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/components/Navigation/Navigation.tsx"
    click NAVCTRL "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/components/Navigation/Controls.tsx"
    click COM "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/common/"
    click BTN "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/common/Button/"
    click LOAD "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/common/Loading/"
    click ERR "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/common/Error/"
    click INP "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/components/common/InputDate/"
    click QCTX "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/contexts/QueryContext.tsx"
    click VCTX "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/contexts/VideoContext.tsx"
    click QRED "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/reducers/queryReducer.ts"
    click VRED "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/reducers/videoReducer.ts"
    click TJL "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/functions/tjmedia-popular/"
    click YTL "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/functions/youtube-search/"
    click TJQ "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/queries/useTJMediaQuery.ts"
    click YTQ "https://github.com/gignac-cha/tjmedia-popular-youtube/blob/main/ui/src/queries/useYouTubeQuery.ts"
    click UTIL "https://github.com/gignac-cha/tjmedia-popular-youtube/tree/main/ui/src/utilities/"
    
    %% Styling
    classDef component fill:#3498db,stroke:#2980b9,color:#fff
    classDef state fill:#e74c3c,stroke:#c0392b,color:#fff
    classDef data fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef lambda fill:#f1c40f,stroke:#f39c12,color:#fff
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:#fff
    classDef infra fill:#9b59b6,stroke:#8e44ad,color:#fff
```
