# yudswin/nettubefe architecture

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

- Interactive diagram: https://gitdiagram.com/yudswin/nettubefe
- Repository: https://github.com/yudswin/nettubefe

## Overview

##### Project type and purpose
- This is a single‐page frontend application (“NetTube Frontend”) built with React (v19), TypeScript, and Vite.
- Purpose: Provide a responsive UI for browsing, searching, authenticating, and playing video streams (HLS) via a backend API.

##### File structure
- Top level:
- index.html + public/ → Static assets and HTML shell.
- src/main.tsx → React app entry point.
- src/App.tsx → Root component, mounts Router & Context providers.
- src/routes/index.ts → Defines React Router route‐to‐page mappings.
- src/pages/… → Page components (e.g., home.tsx, browse.tsx, person.tsx, movie.tsx, plus nested /contents tabs).
- src/components/… → Reusable UI pieces organized by feature (create modals, feedback, forms, layout, search, ui cards/modals, user views).
- src/contexts/… → React Context providers (AuthContext, LanguageContext).
- src/services/… → API service layer using Axios (auth, content, streaming, user, genre, etc.).
– services/http/client.ts sets up Axios instance & interceptors.
– services/junction holds many‐to‐many endpoints.
- src/types/… → TypeScript defs for API requests/responses.
- src/utils, src/libs → Utility functions (e.g., jwtUtils) and helpers.
- Configuration: vite.config.ts, tsconfig*.json, tailwind.config.js, eslint.config.js.

##### Extract architecture insights from README
- Component‐based UI
- React Router for navigation
- Context API for global state (Auth, Language, Player)
- Axios + interceptors for RESTful API calls
- HLS.js for adaptive video playback
- TailwindCSS + DaisyUI for styling
- Vite for build & dev server
- Deployment targets: static hosts or Docker/Nginx

a. Main Components
- Browser / Client
- Static Host / CDN (serves index.html + JS/CSS bundle)
- React SPA
- Routing Layer (React Router)
- UI Presentation Layer (Components & Pages)
- State Management Layer (Context Providers)
- Service Layer (Axios HTTP client & service modules)
- External Services
- Backend API (user, auth, content, media metadata)
- Media Server (HLS segments)
b. Relationships & Data Flow
1. User interacts with UI → triggers React component events.
2. Components call service methods → Axios client attaches JWT header via interceptor.
3. Axios sends HTTP requests → Backend API (VITE_API_URL).
4. API returns JSON → Service layer normalizes → updates Context or local component state.
5. For video playback, HLS.js in <video> tag fetches media segments directly from Media Server (VITE_MEDIA_URL).
6. Context Providers wrap App: provide auth state, language prefs, player state to component tree.
c. Architectural Patterns & Principles
- Separation of concerns:
- Presentation (components/pages) vs. Data fetching (services) vs. State (contexts)
- Container/Presentational split within components (e.g., cards vs. model modals)
- Dependency Injection via Context
- Single Responsibility: each service module handles one entity
d. Key Technologies
- React + TS + Vite
- React Router
- TailwindCSS + DaisyUI
- Axios + interceptors
- HLS.js
- Context API

##### Detailed Capture of Architectural Elements
- Inter‐context connections (AuthContext → Axios interceptor).
- Environment variables (VITE_API_URL, VITE_MEDIA_URL).
- Where HLS.js is initialized (MediaCard or Player page).
- Build pipeline (Vite dev server vs. production build).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Static Hosting Layer
    StaticHost["Static Host / CDN"]:::external
    click StaticHost "https://github.com/yudswin/nettubefe/tree/main/public/"

    %% Browser Client
    Browser["Browser / Client"]:::external

    StaticHost -->|serves SPA| Browser

    %% SPA Layer
    subgraph "NetTube SPA" 
        direction TB

        Main["src/main.tsx"]:::frontend
        click Main "https://github.com/yudswin/nettubefe/blob/main/src/main.tsx"

        App["src/App.tsx"]:::frontend
        click App "https://github.com/yudswin/nettubefe/blob/main/src/App.tsx"

        Main --> App

        subgraph "Routing Layer"
            Router["src/routes/index.ts"]:::frontend
            click Router "https://github.com/yudswin/nettubefe/blob/main/src/routes/index.ts"
        end

        App --> Router

        subgraph "Page Components"
            direction TB
            Home["Home Page"]:::frontend
            click Home "https://github.com/yudswin/nettubefe/blob/main/src/pages/home.tsx"
            Browse["Browse Page"]:::frontend
            click Browse "https://github.com/yudswin/nettubefe/blob/main/src/pages/browse.tsx"
            CollectionList["Collection List Page"]:::frontend
            click CollectionList "https://github.com/yudswin/nettubefe/blob/main/src/pages/collectionList.tsx"
            CollectionDetail["Collection Detail Page"]:::frontend
            click CollectionDetail "https://github.com/yudswin/nettubefe/blob/main/src/pages/collection.tsx"
            Movie["Movie Page"]:::frontend
            click Movie "https://github.com/yudswin/nettubefe/blob/main/src/pages/movie.tsx"
            Person["Person Page"]:::frontend
            click Person "https://github.com/yudswin/nettubefe/blob/main/src/pages/person.tsx"
            Player["Player Page"]:::frontend
            click Player "https://github.com/yudswin/nettubefe/blob/main/src/pages/player.tsx"

            subgraph "Contents Tabs"
                AdminContent["Admin Content"]:::frontend
                click AdminContent "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/AdminContent.tsx"
                CategoryTab["Category Tab"]:::frontend
                click CategoryTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/CategoryTab.tsx"
                CollectionTab["Collection Tab"]:::frontend
                click CollectionTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/CollectionTab.tsx"
                CountryTab["Country Tab"]:::frontend
                click CountryTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/CountryTab.tsx"
                DepartmentTab["Department Tab"]:::frontend
                click DepartmentTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/DepartmentTab.tsx"
                FavoriteContent["Favorite Content"]:::frontend
                click FavoriteContent "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/FavoriteContent.tsx"
                GenreTab["Genre Tab"]:::frontend
                click GenreTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/GenreTab.tsx"
                HistoryContent["History Content"]:::frontend
                click HistoryContent "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/HistoryContent.tsx"
                LibraryContent["Library Content"]:::frontend
                click LibraryContent "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/LibraryContent.tsx"
                MovieTab["Movie Tab"]:::frontend
                click MovieTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/MovieTab.tsx"
                PersonTab["Person Tab"]:::frontend
                click PersonTab "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/PersonTab.tsx"
                SettingContent["Setting Content"]:::frontend
                click SettingContent "https://github.com/yudswin/nettubefe/blob/main/src/pages/contents/SettingContent.tsx"
            end
        end

        Router --> Home
        Router --> Browse
        Router --> CollectionList
        Router --> CollectionDetail
        Router --> Movie
        Router --> Person
        Router --> Player
        Player --> MovieTab

        subgraph "UI Components" 
            direction TB
            Layout["src/components/layout/*"]:::frontend
            click Layout "https://github.com/yudswin/nettubefe/tree/main/src/components/layout"
            Form["src/components/form/*"]:::frontend
            click Form "https://github.com/yudswin/nettubefe/tree/main/src/components/form"
            Search["src/components/search/*"]:::frontend
            click Search "https://github.com/yudswin/nettubefe/tree/main/src/components/search"
            Feedback["src/components/feedback/*"]:::frontend
            click Feedback "https://github.com/yudswin/nettubefe/tree/main/src/components/feedback"
            CreateModals["src/components/create/*"]:::frontend
            click CreateModals "https://github.com/yudswin/nettubefe/tree/main/src/components/create"
            UICards["src/components/ui/*"]:::frontend
            click UICards "https://github.com/yudswin/nettubefe/tree/main/src/components/ui"
            UserViews["src/components/user/*"]:::frontend
            click UserViews "https://github.com/yudswin/nettubefe/tree/main/src/components/user"
        end

        subgraph "Context Providers"
            AuthContext["AuthContext"]:::service
            click AuthContext "https://github.com/yudswin/nettubefe/blob/main/src/contexts/AuthContext.tsx"
            LanguageContext["LanguageContext"]:::service
            click LanguageContext "https://github.com/yudswin/nettubefe/blob/main/src/contexts/LanguageContext.tsx"
        end

        App --> Layout
        App --> AuthContext
        App --> LanguageContext

        subgraph "Service Layer"
            HTTPClient["http/client.ts"]:::service
            click HTTPClient "https://github.com/yudswin/nettubefe/blob/main/src/services/http/client.ts"
            AuthService["auth.service.ts"]:::service
            click AuthService "https://github.com/yudswin/nettubefe/blob/main/src/services/auth.service.ts"
            ContentService["content.service.ts"]:::service
            click ContentService "https://github.com/yudswin/nettubefe/blob/main/src/services/content.service.ts"
            StreamingService["streaming.service.ts"]:::service
            click StreamingService "https://github.com/yudswin/nettubefe/blob/main/src/services/streaming.service.ts"
            MediaService["media.service.ts"]:::service
            click MediaService "https://github.com/yudswin/nettubefe/blob/main/src/services/media.service.ts"
            JunctionServices["junction/*.service.ts"]:::service
            click JunctionServices "https://github.com/yudswin/nettubefe/tree/main/src/services/junction"
            EntityServices["genre|country|department|..."]:::service
            click EntityServices "https://github.com/yudswin/nettubefe/tree/main/src/services"
        end

        Layout --> HTTPClient
        AuthContext --> HTTPClient
        Router --> HTTPClient

        subgraph "Utilities & Types"
            Types["src/types/*"]:::config
            click Types "https://github.com/yudswin/nettubefe/tree/main/src/types"
            JWTUtils["src/libs/jwtUtils.ts"]:::config
            click JWTUtils "https://github.com/yudswin/nettubefe/blob/main/src/libs/jwtUtils.ts"
            StringUtils["src/utils/string.utils.ts"]:::config
            click StringUtils "https://github.com/yudswin/nettubefe/blob/main/src/utils/string.utils.ts"
        end

        subgraph "Configuration & Styles"
            TailwindConfig["tailwind.config.js"]:::config
            click TailwindConfig "https://github.com/yudswin/nettubefe/blob/main/tailwind.config.js"
            ViteConfig["vite.config.ts"]:::config
            click ViteConfig "https://github.com/yudswin/nettubefe/blob/main/vite.config.ts"
            TSConfig["tsconfig*.json"]:::config
            click TSConfig "https://github.com/yudswin/nettubefe/blob/main/tsconfig.json"
            ESLintConfig["eslint.config.js"]:::config
            click ESLintConfig "https://github.com/yudswin/nettubefe/blob/main/eslint.config.js"
            Styles["src/index.css"]:::config
            click Styles "https://github.com/yudswin/nettubefe/blob/main/src/index.css"
        end

    end

    %% External Services
    BackendAPI["Backend API (VITE_API_URL)"]:::external
    MediaServer["Media Server (HLS) (VITE_MEDIA_URL)"]:::external

    HTTPClient -->|requests| BackendAPI
    StreamingService -->|stream metadata| BackendAPI
    Player -->|HLS.js fetch| MediaServer

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef service fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFD580,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
```
