# lunatic2good/netflix architecture

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

- Interactive diagram: https://gitdiagram.com/lunatic2good/netflix
- Repository: https://github.com/lunatic2good/netflix

## Overview

##### Project type and purpose
- This is a full-stack “Netflix clone” application.
- The client folder is a React/TypeScript single-page app (built with Vite and Tailwind) that handles UI, state (Redux Toolkit), routing (React Router), and media playback.
- The server folder is an Express/Node.js API that exposes authentication, movie metadata, and subscription endpoints, persists data via Prisma/SQL, and integrates with Stripe for payments.

##### File structure
- Top-level: “client” and “server” directories.
- client/
- src/pages → high-level routes (HomePage, BrowsePage, etc.)
- src/components → reusable UI (MovieCard, Navbar, etc.)
- src/hooks & src/features → data-fetching and Redux slices (userSlice)
- public/assets → static media (southpark.mp4)
- config files: vite.config.ts, tailwind.config.js, tsconfig.json
- server/
- routes/ → Express endpoints (auth.js, movies.js, sub.js)
- middleware/ → request-level logic (e.g. auth checks)
- services/ & utils/ → business logic (fetchSubscription, Stripe helper)
- prisma/ → schema.prisma, migrations
- db/ & scripts/ → local JSON data and seedMovies.js
- index.js → app entry, connects middleware, routes, Prisma client

##### Extract insights from README
- README.md only contains “# netflix” but file names and folder structure confirm: a streaming-style frontend with a RESTful backend and subscription billing.

a. Main components:
- Client SPA (React + Redux + Router + Vite)
- API Server (Express + Prisma + Node.js)
- Database (PostgreSQL / MySQL via Prisma ORM)
- External Payment Service (Stripe)
- Static Assets Storage (local public folder or CDN)
b. Relationships & interactions:
- User in browser ↔ Client SPA
- SPA → REST calls to API (auth, fetch movies, manage subscriptions)
- API ↔ Database (CRUD for users, subscriptions, movies)
- API ↔ Stripe (create charges, manage subscriptions)
- Server ↔ Seed script for initial data
c. Architectural patterns & principles:
- Client is decoupled: UI, state, and routing separated into pages, components, hooks.
- Server follows MVC-style organization: routes → controllers/services → data layer (Prisma).
- Use of middleware for cross-cutting concerns (authentication).
- Infrastructure as code: Prisma schema, seed scripts.
d. Key technologies:
- Frontend: React, TypeScript, Redux Toolkit, React Router, Vite, Tailwind CSS
- Backend: Node.js, Express, Prisma ORM, Stripe SDK
- Database: relational (configured via Prisma)
- Build & dev tools: ESLint, PostCSS, Vite, npm scripts

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Browser["User Browser"]:::external
        ReactApp["React App"]:::frontend
        ReduxStore["Redux Store"]:::frontend
        RouterPages["Routing & Pages"]:::frontend
        UIComps["UI Components"]:::frontend
        Hooks["Data-fetching Hooks"]:::frontend
        PrivateRoutes["Private Route Utility"]:::frontend
        StaticAssets["Static Assets"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        direction TB
        ExpressAPI["Express API"]:::backend
        IndexJS["index.js"]:::backend
        AuthRoutes["Auth Endpoints"]:::backend
        MoviesRoutes["Movie Metadata Endpoints"]:::backend
        SubRoutes["Subscription Endpoints"]:::backend
        Middleware["Auth Middleware"]:::backend
        Services["Business Logic Services"]:::backend
        StripeHelper["Stripe Integration Helper"]:::backend
        PrismaClient["Prisma ORM"]:::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["Database (Postgres/MySQL)"]:::database
        SchemaPrisma["Prisma Schema"]:::backend
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Stripe["Stripe Service"]:::external
        CDN["Asset CDN"]:::external
    end

    %% Scripts & Seed
    subgraph "Seed & Data Init"
        direction TB
        SeedScript["Seed Script"]:::backend
        JSONLoader["Local JSON Data"]:::backend
    end

    %% Connections
    Browser -->|"loads"| ReactApp
    ReactApp -->|"hydrates state"| ReduxStore
    ReactApp -->|"renders routes"| RouterPages
    ReactApp -->|"renders UI"| UIComps
    ReactApp -->|"calls hooks"| Hooks
    ReactApp -->|"uses"| PrivateRoutes
    ReactApp -->|"serves media"| StaticAssets

    ReactApp -->|"GET /auth, /movies, /sub"| ExpressAPI
    ExpressAPI -->|"uses"| Middleware
    ExpressAPI -->|"routes to"| AuthRoutes
    ExpressAPI -->|"routes to"| MoviesRoutes
    ExpressAPI -->|"routes to"| SubRoutes
    AuthRoutes -->|"calls"| Services
    MoviesRoutes -->|"calls"| Services
    SubRoutes -->|"calls"| Services
    Services -->|"uses"| StripeHelper
    Services -->|"calls ORM"| PrismaClient
    PrismaClient -->|"executes schema"| SchemaPrisma
    PrismaClient -->|"CRUD"| DB

    ExpressAPI -->|"webhooks"| Stripe
    StaticAssets -->|"cdn upload"| CDN

    SeedScript -.->|"seeds data"| DB
    JSONLoader -->|"provides data"| SeedScript

    %% Click Events
    click ReactApp "https://github.com/lunatic2good/netflix/blob/main/client/src/main.tsx"
    click ReactApp "https://github.com/lunatic2good/netflix/blob/main/client/src/App.tsx"
    click ReduxStore "https://github.com/lunatic2good/netflix/blob/main/client/src/app/store.ts"
    click RouterPages "https://github.com/lunatic2good/netflix/blob/main/client/src/pages/HomePage.tsx"
    click RouterPages "https://github.com/lunatic2good/netflix/blob/main/client/src/pages/BrowsePage.tsx"
    click RouterPages "https://github.com/lunatic2good/netflix/blob/main/client/src/pages/LoginPage.tsx"
    click RouterPages "https://github.com/lunatic2good/netflix/blob/main/client/src/pages/PlansPage.tsx"
    click RouterPages "https://github.com/lunatic2good/netflix/blob/main/client/src/pages/PlansManage.tsx"
    click RouterPages "https://github.com/lunatic2good/netflix/blob/main/client/src/pages/WatchPage.tsx"
    click UIComps "https://github.com/lunatic2good/netflix/blob/main/client/src/components/MovieCard.tsx"
    click UIComps "https://github.com/lunatic2good/netflix/blob/main/client/src/components/Navbar.tsx"
    click UIComps "https://github.com/lunatic2good/netflix/blob/main/client/src/components/Billboard.tsx"
    click Hooks "https://github.com/lunatic2good/netflix/blob/main/client/src/hooks/useAuth.ts"
    click Hooks "https://github.com/lunatic2good/netflix/blob/main/client/src/hooks/useMovie.ts"
    click Hooks "https://github.com/lunatic2good/netflix/blob/main/client/src/hooks/useMoviesList.ts"
    click Hooks "https://github.com/lunatic2good/netflix/blob/main/client/src/hooks/usePlans.ts"
    click Hooks "https://github.com/lunatic2good/netflix/blob/main/client/src/hooks/useSubscription.ts"
    click PrivateRoutes "https://github.com/lunatic2good/netflix/blob/main/client/src/utils/PrivateRoutes.tsx"
    click StaticAssets "https://github.com/lunatic2good/netflix/tree/main/client/public"
    click StaticAssets "https://github.com/lunatic2good/netflix/blob/main/client/src/assets/southpark.mp4"
    click IndexJS "https://github.com/lunatic2good/netflix/blob/main/server/index.js"
    click AuthRoutes "https://github.com/lunatic2good/netflix/blob/main/server/routes/auth.js"
    click MoviesRoutes "https://github.com/lunatic2good/netflix/blob/main/server/routes/movies.js"
    click SubRoutes "https://github.com/lunatic2good/netflix/blob/main/server/routes/sub.js"
    click Middleware "https://github.com/lunatic2good/netflix/blob/main/server/middleware/index.js"
    click Services "https://github.com/lunatic2good/netflix/blob/main/server/services/fetchSubscription.js"
    click StripeHelper "https://github.com/lunatic2good/netflix/blob/main/server/utils/stripe.js"
    click SchemaPrisma "https://github.com/lunatic2good/netflix/blob/main/server/prisma/schema.prisma"
    click SeedScript "https://github.com/lunatic2good/netflix/blob/main/server/scripts/seedMovies.js"
    click JSONLoader "https://github.com/lunatic2good/netflix/blob/main/server/movies.json"
    click JSONLoader "https://github.com/lunatic2good/netflix/blob/main/server/db/index.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#0366d6,stroke-width:2px
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px
    classDef database fill:#fff3cd,stroke:#ffc107,stroke-width:2px
    classDef external fill:#f8d7da,stroke:#dc3545,stroke-width:2px
```
