# thejohnpg/inspiration-viral-youtube-videos architecture

> Architecture diagram of the GitHub repository thejohnpg/inspiration-viral-youtube-videos, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thejohnpg/inspiration-viral-youtube-videos
- Repository: https://github.com/thejohnpg/inspiration-viral-youtube-videos

## Overview

##### Project type and purpose
- This is a lightweight full-stack web application (“Viral Video Search”) built with Node.js and Express.js on the backend, and vanilla HTML/CSS/JavaScript on the frontend.
- Its sole business function is to let users enter a niche, hit “Search,” then display YouTube videos sorted by view count, using the Google YouTube Data API v3.

##### File structure
- Top-level files
- `.env` – stores the YouTube API key and other environment variables
- `index.js` – entry point and Express server setup
- `package.json` – lists dependencies (`express`, `dotenv`, etc.) and scripts
- `Readme.md` & `.gitignore`
- `public/` directory
- `index.html` – the UI shell
- `style.css` – styling
- `script.js` – client-side logic (XHR/fetch to your Express endpoints)
- There is no database or caching layer yet (planned future features include Redis, CDN, cloud hosting).

##### README for additional insights
- Confirms tech stack: Node.js, Express.js, Google YouTube Data API, plain HTML/CSS/JS
- Future roadmap: mobile-first CSS, Webpack/production build, Redis cache, cloud + CDN, mobile app
- No existing microservices or database—pure server-as-API approach.

a. Main components
- Client Browser (UI)
- Express.js Server
- YouTube Data API (external service)
- Environment/config layer (`.env` holds API key)
- (Future) Redis Cache, CDN, Cloud Hosting nodes
b. Relationships & data flows
1. User interacts with Browser UI → enters niche → clicks “Search.”
2. Browser (script.js) sends an HTTP request to Express endpoint (`/search?term=...`).
3. Express server reads API key from `.env`, constructs a request to YouTube Data API.
4. YouTube Data API responds with video metadata.
5. Server optionally caches results (future Redis), then returns JSON to the client.
6. Browser renders the results.
c. Architectural patterns / design principles
- Single-page server-rendered approach with client-side fetch calls (separation of concerns).
- 3-tier logical separation: Presentation (HTML/CSS/JS), Application (Express), External API (YouTube).
- Env-driven configuration (12-factor principles).
d. Key technologies & libraries
- Node.js & Express.js for HTTP server and routing
- `dotenv` to load `.env`
- Fetch/XHR in `script.js` for AJAX
- Google YouTube Data API v3 as external dependency
- Static assets served from `public/`

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        Browser["Browser / UI"]:::frontend
        Script["Client-side Logic"]:::frontend
        Style["Client-side Styling"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Express["Express.js Server"]:::backend
        Env[".env (API Keys)"]:::backend
        Package["package.json"]:::backend
        Doc["Readme.md"]:::backend
    end

    %% External Services
    subgraph "External Services"
        direction TB
        YouTube["YouTube Data API v3"]:::external
    end

    %% Future Components
    subgraph "Future Components (Scope)"
        direction TB
        Redis["Redis Cache"]:::future
        CDN["CDN"]:::future
        Cloud["Cloud Hosting"]:::future
    end

    %% Connections
    Browser -->|"loads HTML/CSS"| Style
    Browser -->|"loads HTML/JS"| Script
    Script -->|"GET /search?term=xxx"| Express
    Express -->|"reads API key"| Env
    Express -->|"reads deps/scripts"| Package
    Express -->|"YouTube API: search.list"| YouTube
    YouTube -->|"video metadata JSON"| Express
    Express -->|"JSON response"| Script

    %% Future scope connections (dashed)
    Express -.->|"cache results"| Redis
    Script -.->|"assets via CDN"| CDN
    Express -.->|"deploy to"| Cloud

    %% Click Events
    click Browser "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/public/index.html"
    click Script "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/public/script.js"
    click Style "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/public/style.css"
    click Express "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/index.js"
    click Env "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/.env"
    click Package "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/package.json"
    click Doc "https://github.com/thejohnpg/inspiration-viral-youtube-videos/blob/master/Readme.md"

    %% Styles
    classDef frontend fill:#D6EFFF,stroke:#0077B6,color:#000;
    classDef backend fill:#E0FFD6,stroke:#2D6A4F,color:#000;
    classDef external fill:#F0F0F0,stroke:#6C757D,color:#000;
    classDef future fill:#FFF0D6,stroke:#FF9408,stroke-dasharray: 5 5,color:#000;
```
