# dev-sire/nodestream architecture

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

- Interactive diagram: https://gitdiagram.com/dev-sire/nodestream
- Repository: https://github.com/dev-sire/nodestream

## Overview

##### Main Components
- Frontend/UI Layer: Represented by the Next.js app. Key directories include:
– src/app: Contains the route-level files and layouts for different sections ((auth), (home), (studio)).
– src/components and src/modules/*/ui: These hold reusable UI components and feature-specific components.
– Public assets and global styles (public, src/app/globals.css).
- API/Backend Layer:
– src/app/api: Contains RESTful API endpoints (uploadthing, trpc, users, videos webhooks).
– src/trpc: Manages tRPC configuration and routers for server-side procedures and queries.
- Business Logic/Modules:
– src/modules: Divided by domain areas (auth, categories, home, studio, videos), each containing its own server-side (procedures) and UI parts.
- Data & External Integrations:
– Database: src/db (schema definitions and initialization) plus drizzle.config.ts, which indicate a connection configuration.
– External Services: Integration components in src/lib (e.g., mux.ts for video streaming, ratelimit.ts for rate limiting, redis.ts for caching/session management, and uploadthing.ts for file uploads).

##### Relationships and Data Flows
- The client (browser) interacts with Next.js page routes defined in src/app (e.g., authentication pages, home view, studio).
- These pages load reusable UI components from src/components and feature-specific modules.
- When dynamic data or state changes are necessary, the components invoke APIs:
– tRPC endpoints (via src/app/api/trpc and src/trpc/routers) handle business logic on the server.
– Other API endpoints (uploadthing, webhook routes) interact with external systems.
- The backend communicates with the database (src/db) and leverages utilities in src/lib for integrations with external systems like Mux and Redis.
- The modular directory structure (src/modules) shows a clean separation of concerns, with each domain having both a UI and server logic layer, which simplifies scaling and maintenance.

##### Important Architectural Patterns
- Next.js App Structure: Emphasizes file-based routing and layout composition.
- Modular Architecture: Domain-specific modules (auth, home, studio, videos) separating concerns across UI, server procedures, and integrations.
- API Layer with tRPC: Provides typesafe communication between client and server.
- Integration with External Services: Use of dedicated libraries (for uploads, rate limiting, video streaming) isolates external dependencies.

##### Technologies, Frameworks, and Libraries
- Next.js: For both rendering pages and handling API routes.
- tRPC: For typesafe API calls and server procedures.
- Tailwind CSS: Configured through tailwind.config.ts for UI styling.
- Uploadthing: For file uploads within the API.
- Additional libraries/utilities in src/lib (mux, redis, etc.) that interact with external systems.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entity
    Browser("Browser"):::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        A1("Next.js Frontend (src/app)"):::frontend
        A2("Home Page (src/app/(home))"):::frontend
        A3("Studio Page (src/app/(studio))"):::frontend
        A4("Global Layout (src/app/layout.tsx)"):::frontend
        A5("Global Styles (src/app/globals.css)"):::frontend
        A6("Reusable UI Components (src/components)"):::frontend
        A7("Auth UI (src/modules/auth/ui)"):::frontend
        A8("Home UI (src/modules/home/ui)"):::frontend
        A9("Studio UI (src/modules/studio/ui)"):::frontend
        A10("Videos UI (src/modules/videos/ui)"):::frontend
    end

    %% API/Backend Layer
    subgraph "API Layer"
        B1("tRPC API Endpoints (src/app/api/trpc)"):::api
        B2("tRPC Route (src/app/api/trpc/[trpc]/route.ts)"):::api
        B3("Uploadthing Endpoints (src/app/api/uploadthing)"):::api
        B4("Users Webhook Endpoint (src/app/api/users/webhook/route.ts)"):::api
        B5("Videos Webhook Endpoint (src/app/api/videos/webhook/route.ts)"):::api
    end

    %% Business Logic Modules
    subgraph "Business Modules"
        C1("Auth Module (src/modules/auth)"):::business
        C2("Categories Procedures (src/modules/categories/server/procedures.ts)"):::business
        C3("Studio Procedures (src/modules/studio/server/procedures.ts)"):::business
        C4("Videos Procedures (src/modules/videos/server/procedures.ts)"):::business
    end

    %% Database & External Integrations
    subgraph "Data & External Services"
        D1("Database (src/db)"):::database
        D2("DB Config (drizzle.config.ts)"):::database
        D3("External Integration Libraries (src/lib)"):::external
        D4("tRPC Config & Routers (src/trpc)"):::external
    end

    %% Connections for Frontend
    Browser --> A1
    A1 --> A2
    A1 --> A3
    A1 --> A4
    A1 --> A5
    A1 --> A6
    A6 --> A7
    A6 --> A8
    A6 --> A9
    A6 --> A10

    %% Frontend to API interactions
    A2 -->|"calls"| B1
    A3 -->|"calls"| B3
    A7 -->|"calls"| B1
    A8 -->|"calls"| B1
    A9 -->|"calls"| B1
    A10 -->|"calls"| B1

    %% API Endpoint details and integrations
    B1 -->|"routes"| B2
    B1 -->|"configures"| D4
    B3 -->|"integrates"| D3
    B4 -->|"integrates"| D3
    B5 -->|"integrates"| D3

    %% API to Business Logic Flow
    B1 -->|"triggers"| C1
    B1 -->|"triggers"| C2
    B1 -->|"triggers"| C3
    B1 -->|"triggers"| C4

    %% Business Logic to Database & External
    C1 -->|"accesses"| D1
    C2 -->|"accesses"| D1
    C3 -->|"accesses"| D1
    C4 -->|"accesses"| D1
    C1 -->|"uses"| D3
    C2 -->|"uses"| D3
    C3 -->|"uses"| D3
    C4 -->|"uses"| D3

    %% Database Config Connection
    D2 -->|"configures"| D1

    %% tRPC Config integration loop
    D4 -->|"feeds"| B1

    %% Click Events
    click A1 "https://github.com/dev-sire/nodestream/tree/main/src/app"
    click A2 "https://github.com/dev-sire/nodestream/tree/main/src/app/(home)"
    click A3 "https://github.com/dev-sire/nodestream/tree/main/src/app/(studio)"
    click A4 "https://github.com/dev-sire/nodestream/blob/main/src/app/layout.tsx"
    click A5 "https://github.com/dev-sire/nodestream/blob/main/src/app/globals.css"
    click A6 "https://github.com/dev-sire/nodestream/tree/main/src/components"
    click A7 "https://github.com/dev-sire/nodestream/tree/main/src/modules/auth/ui"
    click A8 "https://github.com/dev-sire/nodestream/tree/main/src/modules/home/ui"
    click A9 "https://github.com/dev-sire/nodestream/tree/main/src/modules/studio/ui"
    click A10 "https://github.com/dev-sire/nodestream/tree/main/src/modules/videos/ui"
    click B1 "https://github.com/dev-sire/nodestream/tree/main/src/app/api/trpc"
    click B2 "https://github.com/dev-sire/nodestream/blob/main/src/app/api/trpc/[trpc]/route.ts"
    click B3 "https://github.com/dev-sire/nodestream/tree/main/src/app/api/uploadthing"
    click B4 "https://github.com/dev-sire/nodestream/blob/main/src/app/api/users/webhook/route.ts"
    click B5 "https://github.com/dev-sire/nodestream/blob/main/src/app/api/videos/webhook/route.ts"
    click C1 "https://github.com/dev-sire/nodestream/tree/main/src/modules/auth"
    click C2 "https://github.com/dev-sire/nodestream/blob/main/src/modules/categories/server/procedures.ts"
    click C3 "https://github.com/dev-sire/nodestream/blob/main/src/modules/studio/server/procedures.ts"
    click C4 "https://github.com/dev-sire/nodestream/blob/main/src/modules/videos/server/procedures.ts"
    click D1 "https://github.com/dev-sire/nodestream/tree/main/src/db"
    click D2 "https://github.com/dev-sire/nodestream/blob/main/drizzle.config.ts"
    click D3 "https://github.com/dev-sire/nodestream/tree/main/src/lib"
    click D4 "https://github.com/dev-sire/nodestream/tree/main/src/trpc"

    %% Styles
    classDef frontend fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef api fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px;
    classDef business fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef database fill:#f8bbd0,stroke:#880e4f,stroke-width:2px;
    classDef external fill:#d1c4e9,stroke:#4a148c,stroke-width:2px;
```
