# aswinpc143/netflixclone architecture

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

- Interactive diagram: https://gitdiagram.com/aswinpc143/netflixclone
- Repository: https://github.com/aswinpc143/netflixclone

## Overview

##### Project Type and Purpose
- This is a full-stack, Netflix-style streaming clone. The frontend is a React single-page application (SPA) that handles routing, UI, and state. The backend is entirely managed by Supabase (Auth, PostgreSQL database with RLS, and real-time subscriptions). External APIs (TMDB for movie data, YouTube for trailers) supply content. The app is deployed to Netlify.

##### High-Level File Structure & Architectural Patterns
- Top-level directories:
- public/ – static assets and index.html
- src/ – all client code
· App.js + index.js – entry point, router and context provider setup
· Components/ – reusable UI pieces (NavBar, Banner, RowPost, MovieCard, etc.)
· pages/ – route-level views (HomePage, BrowsePage, GenrePage, MyListPage, etc.)
· context/ – React Context providers for Auth, MyList, ViewingHistory
· lib/supabase.js – Supabase client initialization
· Axios.js & Urls.js – HTTP client and endpoint constants
· Constants/ – magic strings and API keys
- supabase/migrations/ – SQL schema definitions
- Architectural patterns: SPA with Context‐based state management, 3-tier separation (UI, client business logic, data), and micro-interactions via real-time subscriptions.

##### Main Components
A. User & Browser
- Represents end user accessing the React SPA served from Netlify.
B. Netlify CDN/Hosting
- Hosts built static assets (HTML, JS, CSS).
C. React Application (Client Layer)
- Router (React Router)
- Context Providers (AuthContext, MyListContext, ViewingHistoryContext)
- UI Components and Pages
- Axios HTTP client for REST calls
D. Supabase Services (Backend Layer)
1. Supabase Auth
- Handles user signup/login/logout
- Issues JWTs used in subsequent requests
2. PostgreSQL Database
- Tables: profiles, my_list, viewing_history, user_preferences
- Enforced Row Level Security (RLS)
3. Realtime Subscriptions
- Pushes live updates to the client (e.g., list changes) via websockets
E. External APIs
- TMDB REST API (movie/genre/search data)
- YouTube Embedded Player API (trailers)

##### Relationships & Data Flows
- User → Browser → Netlify → React App
- React App ⇄ Supabase Auth (REST over HTTPS for login/signup)
- React App ⇄ Supabase Realtime (websocket for live updates on lists/history)
- React App ⇄ Supabase PostgreSQL (REST/GraphQL‐style queries via Supabase client)
- React App → TMDB API (to fetch movie metadata and search results)
- React App → YouTube API (to embed trailers)

##### Architectural Patterns & Design Principles
- Single Page Application (SPA) with client-side routing
- Context API for cross-cutting concerns (authentication state, lists, history)
- Separation of concerns:
- Presentation (Components, Pages)
- State & Business Logic (Context + custom hooks)
- Data Access (Axios + Supabase client)
- Real-time updates via pub/sub model (Supabase Realtime)
- Secure by design: environment variables for API keys, RLS on database

##### Essential Elements to Capture
- Authentication lifecycle (signup→login→token propagation)
- Database schema components (profiles, my_list, viewing_history, preferences)
- Real-time subscription channels (e.g., when MyList changes)
- External API integration points (TMDB, YouTube)
- Hosting/CDN layer (Netlify) and build/deploy pipeline (GitHub Actions → npm-publish.yml → Netlify)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        User["User & Browser"]:::frontend
        Netlify["Netlify CDN/Hosting"]:::frontend
    end

    %% Client Layer
    subgraph "Client Layer (React App)"
        Router["React Router"]:::frontend

        subgraph "Context Providers"
            AuthCtx["AuthContext"]:::frontend
            MyListCtx["MyListContext"]:::frontend
            ViewHistCtx["ViewingHistoryContext"]:::frontend
        end

        subgraph "UI Components"
            NavBar["NavBar"]:::frontend
            Banner["Banner"]:::frontend
            RowPost["RowPost"]:::frontend
            MovieCard["MovieCard"]:::frontend
            MyListComp["MyList"]:::frontend
            AuthPage["AuthPage"]:::frontend
            LoginForm["LoginForm"]:::frontend
            SignupForm["SignupForm"]:::frontend
            Layout["Layout"]:::frontend
        end

        subgraph "Pages"
            HomePage["HomePage"]:::frontend
            BrowsePage["BrowsePage"]:::frontend
            GenrePage["GenrePage"]:::frontend
            MyListPage["MyListPage"]:::frontend
            ProfilePage["ProfilePage"]:::frontend
            SearchPage["SearchPage"]:::frontend
            ViewingHistoryPage["ViewingHistoryPage"]:::frontend
            AccountPage["AccountPage"]:::frontend
            HelpPage["HelpPage"]:::frontend
        end

        HttpClient["Axios HTTP Client"]:::frontend
        Urls["Endpoint Constants"]:::frontend
        SupabaseClient["Supabase Client Init"]:::frontend
        Constants["Magic Strings & API Keys"]:::frontend
    end

    %% Backend & Data Services
    subgraph "Backend & Data Services"
        Auth["Supabase Auth"]:::backend
        DB["PostgreSQL Database"]:::backend
        Realtime["Realtime Subscriptions"]:::backend
        Migration["DB Migrations & RLS"]:::backend
    end

    %% External APIs
    subgraph "External APIs"
        TMDB["TMDB API"]:::external
        YouTube["YouTube API"]:::external
    end

    %% Connections
    User -->|loads app| Netlify
    Netlify -->|serves SPA| Router
    Router -->|routes to| HomePage
    Router -->|routes to| BrowsePage
    Router -->|routes to| GenrePage
    Router -->|routes to| MyListPage
    Router -->|routes to| ProfilePage
    Router -->|routes to| SearchPage
    Router -->|routes to| ViewingHistoryPage
    Router -->|routes to| AccountPage
    Router -->|routes to| HelpPage

    HomePage -->|renders| NavBar
    HomePage -->|renders| Banner
    BrowsePage -->|renders| RowPost
    GenrePage -->|renders| RowPost
    MyListPage -->|renders| MyListComp
    ViewingHistoryPage -->|renders| RowPost
    ProfilePage -->|renders| MovieCard
    AuthPage -->|uses| LoginForm
    AuthPage -->|uses| SignupForm
    PagesAll["Pages"] -.->|layout| Layout

    AuthCtx -->|provides state to| HomePage
    AuthCtx -->|provides state to| MyListPage
    MyListCtx -->|provides state to| MyListPage
    ViewHistCtx -->|provides state to| ViewingHistoryPage

    HomePage -->|fetch data via| HttpClient
    BrowsePage -->|fetch data via| HttpClient
    GenrePage -->|fetch data via| HttpClient
    SearchPage -->|fetch data via| HttpClient

    HttpClient -->|REST HTTPS| TMDB
    HttpClient -->|REST HTTPS| YouTube

    HomePage -->|auth & data| SupabaseClient
    MyListPage -->|auth & data| SupabaseClient
    ViewingHistoryPage -->|auth & data| SupabaseClient

    SupabaseClient -->|auth calls| Auth
    SupabaseClient -->|db queries| DB
    SupabaseClient -->|subscribe| Realtime
    Realtime -->|updates| MyListPage
    Realtime -->|updates| ViewingHistoryPage

    Migration -->|defines schema| DB

    %% Click Events
    click User "https://github.com/aswinpc143/netflixclone/blob/master/public/index.html"
    click Netlify "https://github.com/aswinpc143/netflixclone/blob/master/.github/workflows/npm-publish.yml"
    click Router "https://github.com/aswinpc143/netflixclone/blob/master/src/index.js"
    click Router "https://github.com/aswinpc143/netflixclone/blob/master/src/App.js"
    click AuthCtx "https://github.com/aswinpc143/netflixclone/blob/master/src/context/AuthContext.js"
    click MyListCtx "https://github.com/aswinpc143/netflixclone/blob/master/src/context/MyListContext.js"
    click ViewHistCtx "https://github.com/aswinpc143/netflixclone/blob/master/src/context/ViewingHistoryContext.js"
    click NavBar "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/NavBar/NavBar.js"
    click Banner "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/Banner/Banner.js"
    click RowPost "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/RowPost/RowPost.js"
    click MovieCard "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/MovieCard/MovieCard.js"
    click MyListComp "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/MyList/MyList.js"
    click AuthPage "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/Auth/AuthPage.js"
    click LoginForm "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/Auth/LoginForm.js"
    click SignupForm "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/Auth/SignupForm.js"
    click Layout "https://github.com/aswinpc143/netflixclone/blob/master/src/Components/Layout/Layout.js"
    click HomePage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/HomePage/HomePage.js"
    click BrowsePage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/BrowsePage/BrowsePage.js"
    click GenrePage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/GenrePage/GenrePage.js"
    click MyListPage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/MyListPage/MyListPage.js"
    click ProfilePage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/ProfilePage/ProfilePage.js"
    click SearchPage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/SearchPage/SearchPage.js"
    click ViewingHistoryPage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/ViewingHistoryPage/ViewingHistoryPage.js"
    click AccountPage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/AccountPage/AccountPage.js"
    click HelpPage "https://github.com/aswinpc143/netflixclone/blob/master/src/pages/HelpPage/HelpPage.js"
    click HttpClient "https://github.com/aswinpc143/netflixclone/blob/master/src/Axios.js"
    click Urls "https://github.com/aswinpc143/netflixclone/blob/master/src/Urls.js"
    click SupabaseClient "https://github.com/aswinpc143/netflixclone/blob/master/src/lib/supabase.js"
    click Constants "https://github.com/aswinpc143/netflixclone/blob/master/src/Constants/Constants.js"
    click Migration "https://github.com/aswinpc143/netflixclone/blob/master/supabase/migrations/20250703115411_green_meadow.sql"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px;
    classDef backend fill:#DFF6DD,stroke:#28a745,stroke-width:1px;
    classDef external fill:#FFE4B5,stroke:#ff8c00,stroke-width:1px;
```
