# yudswin/nettubebe architecture

> Architecture diagram of the GitHub repository yudswin/nettubebe, 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/nettubebe
- Repository: https://github.com/yudswin/nettubebe

## Overview

##### Project type and purpose
- This is a standalone backend API server (no frontend code) written in TypeScript using Express.
- It serves as a media content management and streaming platform (“Nettube Backend”): handles user auth, content CRUD, streaming, favorites, history, reviews, genres, countries, collections.
- It targets two database environments (MySQL in development, Neon PostgreSQL in production) via Drizzle ORM.
- It integrates with external media and image-storage services (Cloudinary for video, Imgur for images).

##### File structure
- Top-level files: configuration (drizzle-dev, drizzle-production), build scripts, CLI helper (register-paths.js), seed script.
- src/index.ts: application entrypoint.
- src/routes → src/controllers → src/services → src/models: a classic layered architecture.
- src/db: database client initialization and external-service config (Cloudinary, Imgur).
- src/middleware: JWT auth, error handlers.
- src/libs, src/types: shared utilities (bcrypt, JWT, CORS, logging) and type definitions.
- src/data + seed.ts: static CSV/JSON used for bootstrapping.
- Config files: tsconfig.json, vercel.json (deployment), .env for secrets.

##### README for additional insights
- The README confirms Express + TypeScript + Drizzle ORM.
- It lists all feature endpoints (authentication, user avatar, watch history, favorites, media management, streaming proxy, content, genres, countries, cast, directors, persons, departments, reviews, collections).
- It details the migration workflow for dev vs prod and seeding.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Client["Clients (Web/Mobile)"]:::external

    %% Express API Server
    subgraph "Express API Server"
        direction TB
        Entry["src/index.ts"]:::entry
        Auth["JWT Auth"]:::middleware
        ErrorH["Error Handling"]:::middleware
        HTTP["HTTP Layer (Routes)"]:::http
        Ctrl["Controllers"]:::controller
        Svc["Services"]:::service
        DAL["Data-access Layer"]:::db
    end

    %% Databases
    subgraph "Databases" 
        direction TB
        MySQL["MySQL (dev)"]:::db
        Postgres["PostgreSQL/Neon (prod)"]:::db
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Cloudinary["Cloudinary"]:::externalSvc
        Imgur["Imgur"]:::externalSvc
    end

    %% Auxiliary Processes
    subgraph "Auxiliary"
        direction TB
        Seed["Seed Process"]:::util
        DataFiles["Seed Data (src/data)"]:::util
        MigReg["register-paths.js"]:::util
        MigDev["drizzle-dev.config.ts"]:::util
        MigProd["drizzle-production.config.ts"]:::util
    end

    %% Flow
    Client -->|HTTP request| Auth
    Auth --> HTTP
    HTTP --> Ctrl
    Ctrl --> Svc
    Svc --> DAL
    DAL -->|SQL queries| MySQL
    DAL -->|SQL queries| Postgres
    Svc -->|SDK calls| Cloudinary
    Svc -->|API calls| Imgur
    HTTP -.->|error| ErrorH
    Entry -->|init| Auth
    Entry -->|init| HTTP
    Seed -->|reads| DataFiles
    Seed -->|uses| Svc
    MigReg --> MigDev
    MigReg --> MigProd

    %% Click Events
    click Entry "https://github.com/yudswin/nettubebe/blob/main/src/index.ts"
    click HTTP "https://github.com/yudswin/nettubebe/tree/main/src/routes"
    click Ctrl "https://github.com/yudswin/nettubebe/tree/main/src/controllers"
    click Svc "https://github.com/yudswin/nettubebe/tree/main/src/services"
    click DAL "https://github.com/yudswin/nettubebe/tree/main/src/models/mysql"
    click DAL "https://github.com/yudswin/nettubebe/tree/main/src/models/pg"
    click Cloudinary "https://github.com/yudswin/nettubebe/blob/main/src/db/cloudinaryConfig.ts"
    click Cloudinary "https://github.com/yudswin/nettubebe/blob/main/src/services/cloudinary.service.ts"
    click Imgur "https://github.com/yudswin/nettubebe/blob/main/src/db/imgurClient.ts"
    click Imgur "https://github.com/yudswin/nettubebe/blob/main/src/controllers/imgur.controller.ts"
    click Auth "https://github.com/yudswin/nettubebe/blob/main/src/middleware/auth.ts"
    click ErrorH "https://github.com/yudswin/nettubebe/blob/main/src/middleware/handler/tokenStatus.ts"
    click Seed "https://github.com/yudswin/nettubebe/blob/main/src/seed.ts"
    click DataFiles "https://github.com/yudswin/nettubebe/tree/main/src/data"
    click MigReg "https://github.com/yudswin/nettubebe/blob/main/register-paths.js"
    click MigDev "https://github.com/yudswin/nettubebe/blob/main/drizzle-dev.config.ts"
    click MigProd "https://github.com/yudswin/nettubebe/blob/main/drizzle-production.config.ts"

    %% Styles
    classDef external fill:#f9f,stroke:#333,stroke-width:1px
    classDef entry fill:#CCF,stroke:#333,stroke-width:1px
    classDef http fill:#CFF,stroke:#333,stroke-width:1px
    classDef controller fill:#CFF,stroke:#333,stroke-width:1px
    classDef service fill:#CFF,stroke:#333,stroke-width:1px
    classDef db fill:#CFC,stroke:#333,stroke-width:1px
    classDef externalSvc fill:#FC9,stroke:#333,stroke-width:1px
    classDef middleware fill:#DDD,stroke:#333,stroke-width:1px
    classDef util fill:#EEE,stroke:#333,stroke-width:1px
```
