# qkeluna/screen_recording_sharing_app architecture

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

- Interactive diagram: https://gitdiagram.com/qkeluna/screen_recording_sharing_app
- Repository: https://github.com/qkeluna/screen_recording_sharing_app

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js application that lets users record their screen, upload videos, view AI transcripts, and share videos via unique links.
- Key characteristics: React UI (App Router), server-side logic (API routes), database integration (Xata + Drizzle ORM), video storage & streaming (Bunny.net), authentication (Better Auth + Google), and security middleware (Arcjet).

##### File Structure
- **app/** – Next.js App Router structure with UI pages and server components:
- (auth) sign-in pages
- (root) main pages: profile, upload, video
- **app/api/auth/** – API routes for authentication
- **components/** – reusable UI pieces (Navbar, VideoPlayer, etc.)
- **lib/** – client-side utilities and actions (file input, screen recording, video API calls)
- **drizzle/** – migrations and schema using Drizzle ORM
- **.xata**, **src/xata.ts** – Xata DB configuration for storing video metadata
- **middleware.ts** and **lib/arcjet.ts** – Arcjet security layer for rate-limiting & bot protection
- **next.config.ts**, **tailwind** & **postcss** configs – build/deploy settings

##### README for Architectural Insights
- Tech stack calls out: Next.js (UI & server), Tailwind CSS (styling), Better Auth + Google (auth), Arcjet (security), Bunny.net (video CDN), Xata (database), Drizzle ORM (type-safe SQL).

##### Main Components
a. Frontend (Browser)
- Next.js React pages & components under **app/** & **components/**
- Tailwind-styled UI, client-side hooks (useFileInput, useScreenRecording)
b. Backend / BFF Layer (Next.js Server)
- App Router server components (data fetching)
- API Routes: **/api/auth/** for login, custom video upload endpoint (lib/actions/video.ts)
- Middleware (middleware.ts) invoking Arcjet for request filtering
c. Database
- Xata (serverless PostgreSQL) for storing users & video metadata (configured in **xata.ts**)
- Drizzle ORM used for migrations and type-safe queries against Postgres (drizzle folder)
d. Video Storage & Delivery
- Bunny.net edge storage & CDN for raw video files and adaptive streaming
- Bunny.net API called by server endpoints to upload and retrieve video URLs
e. Authentication & Security
- Better Auth (external auth service) + Google OAuth
- Arcjet for bot protection, rate limiting, and attack mitigation
f. External Services
- Google OAuth endpoints
- AI transcript service (if present)
- Discord link & other ancillary services (optional)

##### Relationships and Data Flow
1. User → Browser UI → Next.js Server (SSR or API call)
2. Next.js Server → Arcjet middleware → API route logic
3. Authentication flow:
- Browser calls `/api/auth/[...all]/route.ts` → Better Auth / Google → session cookie
4. Screen Recording & Upload:
- Client hook captures video → lib/actions/video.ts → POST to Next.js upload endpoint → Bunny.net storage → Next.js writes metadata to Xata DB via Xata SDK (or Drizzle)
5. Video Retrieval:
- Client navigates to `/video/[videoId]` → Next.js server component fetches metadata from Xata → retrieves streaming URL from Bunny.net → renders VideoPlayer
6. Search & Profile:
- Client calls server components or API to query Xata DB for search results or user’s video list

##### Architectural Patterns and Design Principles
- BFF (Backend-for-Frontend): Next.js API routes act as a tailored backend layer
- Server Components vs. Client Components (Next.js App Router)
- Type-safe database interactions (Drizzle ORM + Xata SDK)
- Separation of concerns: UI, business logic (lib/actions), data layer, external services
- Incremental Static Regeneration / SSR for video pages (leveraging Next.js performance)

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Layers
  subgraph "User & Browser"
    User["User"]:::external
    Browser["Browser (React UI)"]:::internal
  end

  subgraph "Next.js Layer"
    subgraph "UI Rendering"
      AppRouter["Next.js App Router\n(app/)"]:::internal
      LayoutFile["Main Layout\n(app/layout.tsx)"]:::internal
      Globals["Global Styles\n(app/globals.css)"]:::internal
      SignIn["Sign-In Page\n(app/(auth)/sign-in/page.tsx)"]:::internal
    end
    subgraph "API / BFF"
      ArcjetMW["Arcjet Middleware\n(middleware.ts)"]:::external
      AuthAPI["Auth API\n(app/api/auth/[...all]/route.ts)"]:::internal
      VideoAPI["Video Upload Endpoint\n(lib/actions/video.ts)"]:::internal
      ServerComp["Server Components\n(data fetching)"]:::internal
    end
  end

  subgraph "Client Hooks & Components"
    FileInput["useFileInput Hook\n(lib/hooks/useFileInput.ts)"]:::internal
    ScreenRec["useScreenRecording Hook\n(lib/hooks/useScreenRecording.ts)"]:::internal
    Utils["Utilities\n(lib/utils.ts)"]:::internal
    Components["UI Components\n(components/)"]:::internal
  end

  subgraph "Database & ORM"
    Xata["Xata DB\n(.xata, src/xata.ts)"]:::db
    Drizzle["Drizzle ORM\n(drizzle/)"]:::db
  end

  subgraph "Video Storage & CDN"
    Bunny["Bunny.net CDN"]:::external
  end

  subgraph "Authentication Services"
    BetterAuth["Better Auth"]:::external
    GoogleOAuth["Google OAuth"]:::external
  end

  subgraph "Security Services"
    ArcjetService["Arcjet Service\n(lib/arcjet.ts)"]:::external
  end

  subgraph "Static & Config"
    Assets["Static Assets\n(public/assets/)"]:::internal
    Configs["Build & Deploy Configs\n(next.config.ts,\npostcss.config.mjs,\ntailwind.config.ts)"]:::internal
  end

  %% Relationships
  User --> Browser
  Browser --> AppRouter
  AppRouter --> LayoutFile
  AppRouter --> Globals
  AppRouter --> SignIn
  Browser --> FileInput
  Browser --> ScreenRec
  Browser --> Utils
  Browser --> Components
  Browser -->|API call| ArcjetMW
  ArcjetMW --> AuthAPI
  ArcjetMW --> VideoAPI
  ArcjetMW --> ServerComp
  AuthAPI --> BetterAuth
  BetterAuth --> GoogleOAuth
  VideoAPI --> Bunny
  VideoAPI --> Xata
  ServerComp --> Xata
  ServerComp --> Bunny
  Drizzle --> Xata
  ArcjetMW --> ArcjetService
  AppRouter --> ServerComp
  Browser --> Assets
  Configs -- configuration --> AppRouter

  %% Click Events
  click AppRouter "https://github.com/qkeluna/screen_recording_sharing_app/tree/main/app/"
  click LayoutFile "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/app/layout.tsx"
  click Globals "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/app/globals.css"
  click SignIn "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/app/(auth)/sign-in/page.tsx"
  click AuthAPI "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/app/api/auth/[...all]/route.ts"
  click VideoAPI "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/lib/actions/video.ts"
  click FileInput "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/lib/hooks/useFileInput.ts"
  click ScreenRec "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/lib/hooks/useScreenRecording.ts"
  click Utils "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/lib/utils.ts"
  click Components "https://github.com/qkeluna/screen_recording_sharing_app/tree/main/components/"
  click Xata "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/src/xata.ts"
  click Drizzle "https://github.com/qkeluna/screen_recording_sharing_app/tree/main/drizzle/"
  click Assets "https://github.com/qkeluna/screen_recording_sharing_app/tree/main/public/assets/"
  click Configs "https://github.com/qkeluna/screen_recording_sharing_app/blob/main/next.config.ts"

  %% Styles
  classDef internal fill:#daf1fc,stroke:#2b6cb0,stroke-width:1px;
  classDef db fill:#d4f4dd,stroke:#2f855a,stroke-width:1px;
  classDef external fill:#feeedd,stroke:#dd6b20,stroke-width:1px;
```
