# existc/edutube architecture

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

- Interactive diagram: https://gitdiagram.com/existc/edutube
- Repository: https://github.com/existc/edutube

## Overview

##### Main Components
- Frontend:
- Pages & Views: Represented by directories like app/(browse), app/home, and their corresponding pages (e.g., page.tsx).
- Components: Organized in app/components (such as Button, topbar components, Inputs, and PagesComponents like videolist and videoplayer). These constitute the UI composition.
- Context Providers & Hooks: Found in app/context and app/hooks. These provide global state (e.g., AuthContext, ToasterContext) and route handling.
- Global Styles & Layouts: app/globals.css, app/layout.tsx, and home/layout.tsx indicate styling and layout management.

- Backend/API:
- API Routes: Located under app/api, handling endpoints for authentication (app/api/auth with NextAuth routes), registration (app/api/register), and video operation (app/api/video).
- Server-side Integrations: The project’s integration with Prisma is indicated by app/libs/prismadb.ts and prisma/schema.prisma, representing the database connection and schema.

##### Relationships & Interactions
- The Frontend communicates with the Backend/API endpoints for user authentication, registration, and video services via HTTP calls.
- Global Context and Hooks serve as a bridge to manage state within the client-side application and ensure that data flows correctly between view components and API calls.
- Layout components wrap page components and include top-level styling, routing through Next.js dynamic folders, and platform-wide components like HomeTopbar.
- Prisma is used for persistent storage (likely a database) and is referenced within the application’s libraries, showing a direct dependency in data management.

##### Architectural Patterns & Design Principles
- Component-Based Architecture: Separation into reusable UI components (e.g., Buttons, Topbar) and specific pages (modularized under /app slot groups).
- API as a Layer: The Next.js API routes encapsulate server-side logic, following an MVC-like separation where the view (pages) is distinct from business logic (API handlers).
- Context & Hooks: Usage for global state management and routing underline the adherence to React hooks and modern state management practices.
- Next.js Convention: Leveraging reserved keywords like “page” and “layout” for file naming, ensuring that the file structure translates directly to route handling and component hierarchy.

##### Key Technologies and Frameworks
- Next.js with the new App Router
- TypeScript for static type checking
- Prisma for ORM and database management
- Tailwind CSS (as indicated by tailwind.config.ts) for styling
- NextAuth for handling authentication in the API routes

- Main pages (categorized under “app/(browse)”, “app/home”)
- Common UI components (Buttons, Topbar, Input fields)
- Global state management (AuthContext, ToasterContext, hooks such as useRoutes)
- API functionality (auth with NextAuth, video processing, registration)
- The database connection via Prisma
- Frontend components with their corresponding API endpoints showing the request-response data flow.
- Integration with Next.js features (e.g., implementation of layout and reserved file structures).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend"
        %% Pages & Views
        subgraph "Pages & Views"
            Wel["Page: Welcome"]:::frontend
            HomePage["Page: Home"]:::frontend
            HomeLayout["Layout: Home Layout"]:::frontend
            AppLayout["Layout: App Layout"]:::frontend
            Globals["Global Styles"]:::frontend
        end
        %% UI Components
        subgraph "UI Components"
            AuthForm["Auth Form"]:::frontend
            Button["Button"]:::frontend
            VideoList["Video List"]:::frontend
            VideoPlayer["Video Player"]:::frontend
            Searchbar["Searchbar"]:::frontend
            Input["Input Field"]:::frontend
            HomeTopbar["Home Topbar"]:::frontend
            HomeItem["Home Item"]:::frontend
            Topbar["Topbar"]:::frontend
        end
        %% Context Providers & Hooks
        subgraph "Context & Hooks"
            AuthCtx["Auth Context"]:::utility
            ToasterCtx["Toaster Context"]:::utility
            UseRoutes["useRoutes Hook"]:::utility
        end
    end

    %% Backend/API Section
    subgraph "Backend/API"
        %% API Endpoints
        subgraph "API Endpoints"
            AuthAPI["Auth API (NextAuth)"]:::backend
            RegisterAPI["Register API"]:::backend
            VideoAPI["Video API"]:::backend
        end
        %% Database Integration
        subgraph "Database/Prisma"
            PrismaClient["Prisma Client"]:::database
            PrismaSchema["Prisma Schema"]:::database
        end
    end

    %% Connections from Frontend to Backend
    AuthForm -->|"login"| AuthAPI
    AuthForm -->|"register"| RegisterAPI
    VideoPlayer -->|"fetchVideo"| VideoAPI
    VideoList -->|"fetchVideos"| VideoAPI
    Searchbar -->|"search"| VideoAPI

    %% Connection from API Endpoints to Database Integration
    AuthAPI -->|"db_query"| PrismaClient
    RegisterAPI -->|"db_query"| PrismaClient
    VideoAPI -->|"db_query"| PrismaClient
    PrismaClient -->|"schema"| PrismaSchema

    %% Internal Frontend Connections
    AuthForm -->|"consumes"| AuthCtx
    HomePage -->|"routing"| UseRoutes
    HomeTopbar -->|"displays"| AuthCtx

    %% Styles
    classDef frontend fill:#a2d5f2,stroke:#333,stroke-width:2px;
    classDef backend fill:#f2a2a2,stroke:#333,stroke-width:2px;
    classDef utility fill:#d4f2a2,stroke:#333,stroke-width:2px;
    classDef database fill:#f2e2a2,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend - Pages & Views
    click Wel "https://github.com/existc/edutube/blob/main/app/(browse)/(welcome)/page.tsx"
    click HomePage "https://github.com/existc/edutube/blob/main/app/home/page.tsx"
    click HomeLayout "https://github.com/existc/edutube/blob/main/app/home/layout.tsx"
    click AppLayout "https://github.com/existc/edutube/blob/main/app/layout.tsx"
    click Globals "https://github.com/existc/edutube/blob/main/app/globals.css"

    %% Click Events for Frontend - UI Components
    click AuthForm "https://github.com/existc/edutube/blob/main/app/(browse)/components.tsx"
    click Button "https://github.com/existc/edutube/blob/main/app/components/Button.tsx"
    click VideoList "https://github.com/existc/edutube/blob/main/app/components/PagesComponents/videolist.tsx"
    click VideoPlayer "https://github.com/existc/edutube/blob/main/app/components/PagesComponents/videoplayer.tsx"
    click Searchbar "https://github.com/existc/edutube/blob/main/app/components/PagesComponents/searchbar.tsx"
    click Input "https://github.com/existc/edutube/blob/main/app/components/inputs/Input.tsx"
    click HomeTopbar "https://github.com/existc/edutube/blob/main/app/components/topbar/HomeTopbar.tsx"
    click HomeItem "https://github.com/existc/edutube/blob/main/app/components/topbar/HomeItem.tsx"
    click Topbar "https://github.com/existc/edutube/blob/main/app/components/topbar/Topbar.tsx"

    %% Click Events for Frontend - Context Providers & Hooks
    click AuthCtx "https://github.com/existc/edutube/blob/main/app/context/AuthContext.tsx"
    click ToasterCtx "https://github.com/existc/edutube/blob/main/app/context/ToasterContext.tsx"
    click UseRoutes "https://github.com/existc/edutube/blob/main/app/hooks/useRoutes.ts"

    %% Click Events for Backend/API - API Endpoints
    click AuthAPI "https://github.com/existc/edutube/blob/main/app/api/auth/[...nextauth]/route.ts"
    click RegisterAPI "https://github.com/existc/edutube/blob/main/app/api/register/route.ts"
    click VideoAPI "https://github.com/existc/edutube/blob/main/app/api/video/route.ts"

    %% Click Events for Backend/API - Database Integration
    click PrismaClient "https://github.com/existc/edutube/blob/main/app/libs/prismadb.ts"
    click PrismaSchema "https://github.com/existc/edutube/blob/main/prisma/schema.prisma"
```
