# yashu1113/bingwatch architecture

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

- Interactive diagram: https://gitdiagram.com/yashu1113/bingwatch
- Repository: https://github.com/yashu1113/bingwatch

## Overview

##### Project type and purpose
- This is a single-page web application (SPA) built with React + TypeScript, Vite, and Tailwind CSS.
- It provides a movie/TV show discovery UI: genres, trending, search, details, and a locally stored watchlist.
- It integrates with the external TMDB REST API.

##### File structure
- src/pages: top-level “views” served by your router (Index, GenrePage, MovieDetails, TVShowDetails, etc.).
- src/components: reusable UI and layout pieces (HeroSlider, MediaCard, Carousels, UI primitives).
- src/contexts & src/hooks: global state via React Context (WatchlistContext) and custom hooks for debounce, local-storage, network quality, etc.
- src/services/tmdb.ts: network layer encapsulating calls to the TMDB API.
- static config & build files: Vite, Tailwind, PostCSS, Vercel redirects.

##### README (empty here)
- No explicit architectural notes; we derive architecture from code structure.

##### Main components & interactions
a. Browser (User Agent)
b. React SPA
- Router → pages (src/pages)
- Components → presentational & layout (src/components)
- UI primitives (src/components/ui)
c. State Management
- WatchlistContext (persisted via use-local-storage hook)
- Other hooks (use-network-quality, use-debounce)
d. Network Layer
- tmdb service (src/services/tmdb.ts)
e. Data Persistence
- localStorage (via use-local-storage hook)
f. External Service
- TMDB REST API
g. Build & Deployment
- Vite (vite.config.ts)
- Tailwind (tailwind.config.ts)
- Vercel (vercel.json, public/_redirects)

Relationships:
- Pages and components call custom hooks or directly invoke tmdb service.
- tmdb service does HTTP requests, returns JSON to components.
- WatchlistContext wraps application, exposing get/set in localStorage.
- State flows downward via props/context; user actions trigger hooks and service calls.

##### Architectural patterns & principles
- Component-based UI
- Container (page) vs. Presentational (component) separation
- Single Context for global state (watchlist)
- Custom hooks for cross-cutting concerns
- Service layer isolating network calls

##### Detailing labels & flows
- UI Components: src/components, src/pages
- Service: src/services/tmdb.ts
- Context: src/contexts/WatchlistContext.tsx
- Hooks: src/hooks/use-*.ts(x)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers and Components
    subgraph "Browser & Entry Point"
        direction TB
        Browser["Browser (User Agent)"]:::external
        AppEntry["main.tsx (Entry Point)"]:::infra
        Browser -->|"loads"| AppEntry
        click AppEntry "https://github.com/yashu1113/bingwatch/blob/main/src/main.tsx"
    end

    subgraph "UI Layer" 
        direction TB
        Router["App.tsx (Router Setup)"]:::ui
        Pages["Pages (Container Components)"]:::ui
        Components["Presentational & Layout Components"]:::ui
        UIPrims["UI Primitives"]:::ui
        AppEntry -->|"renders"| Router
        Router -->|"routes to"| Pages
        Pages -->|"uses"| Components
        Components -->|"uses"| UIPrims
        click Router "https://github.com/yashu1113/bingwatch/blob/main/src/App.tsx"
        click Pages "https://github.com/yashu1113/bingwatch/tree/main/src/pages"
        click Components "https://github.com/yashu1113/bingwatch/tree/main/src/components"
        click UIPrims "https://github.com/yashu1113/bingwatch/tree/main/src/components/ui"
    end

    subgraph "State Management"
        direction TB
        WatchContext["WatchlistContext"]:::state
        Hooks["Custom Hooks"]:::state
        LocalStorageHook["use-local-storage.ts"]:::state
        NetQualityHook["use-network-quality.ts"]:::state
        DebounceHook["use-debounce.ts"]:::state
        Pages <-->|"wraps with / reads & writes"| WatchContext
        Components <-->|"reads & writes"| WatchContext
        WatchContext -->|"persists to"| LocalStorageSt
        Hooks -->|"includes"| LocalStorageHook
        Hooks -->|"includes"| NetQualityHook
        Hooks -->|"includes"| DebounceHook
        click WatchContext "https://github.com/yashu1113/bingwatch/blob/main/src/contexts/WatchlistContext.tsx"
        click Hooks "https://github.com/yashu1113/bingwatch/tree/main/src/hooks"
        click LocalStorageHook "https://github.com/yashu1113/bingwatch/blob/main/src/hooks/use-local-storage.ts"
        click NetQualityHook "https://github.com/yashu1113/bingwatch/blob/main/src/hooks/use-network-quality.ts"
        click DebounceHook "https://github.com/yashu1113/bingwatch/blob/main/src/hooks/use-debounce.ts"
    end

    LocalStorageSt(["localStorage"]):::state

    subgraph "Network Layer"
        direction TB
        Service["tmdb.ts (TMDB Service Layer)"]:::network
        Utils["utils.ts (Utility Functions)"]:::network
        Service -->|"HTTP GET/POST"| TMDBAPI
        Components -->|"calls"| Service
        Hooks -->|"calls"| Service
        Utils -->|"used by"| Service
        Utils -->|"used by"| Hooks
        click Service "https://github.com/yashu1113/bingwatch/blob/main/src/services/tmdb.ts"
        click Utils "https://github.com/yashu1113/bingwatch/blob/main/src/lib/utils.ts"
    end

    TMDBAPI["TMDB REST API"]:::external

    subgraph "Build & Deployment"
        direction TB
        ViteCfg["vite.config.ts"]:::infra
        TailwindCfg["tailwind.config.ts"]:::infra
        PostCSS["postcss.config.js"]:::infra
        VercelCfg["vercel.json"]:::infra
        Redirects["public/_redirects"]:::infra
        ViteCfg -->|"build static assets"| StaticSite
        TailwindCfg --> StaticSite
        PostCSS --> StaticSite
        StaticSite["Static Assets"]:::infra
        StaticSite -->|"deployed to CDN"| VercelCfg
        click ViteCfg "https://github.com/yashu1113/bingwatch/blob/main/vite.config.ts"
        click TailwindCfg "https://github.com/yashu1113/bingwatch/blob/main/tailwind.config.ts"
        click PostCSS "https://github.com/yashu1113/bingwatch/blob/main/postcss.config.js"
        click VercelCfg "https://github.com/yashu1113/bingwatch/blob/main/vercel.json"
        click Redirects "https://github.com/yashu1113/bingwatch/tree/main/public/_redirects"
    end

    %% Styling
    classDef ui fill:#e0f7ff,stroke:#008bba;
    classDef state fill:#e0ffe0,stroke:#28a745;
    classDef network fill:#fff0e0,stroke:#ff8c00;
    classDef infra fill:#f0f0f0,stroke:#666;
    classDef external fill:#ffe0e0,stroke:#d9534f;
```
