# neolaner/scoap-next architecture

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

- Interactive diagram: https://gitdiagram.com/neolaner/scoap-next
- Repository: https://github.com/neolaner/scoap-next

## Overview

##### Main Components
- Frontend (Client-Side UI)
- Located primarily under the “src/app” directory.
- Contains numerous pages (e.g., home, login, user, collections, search, stream, help, settings) and a rich set of UI components and layouts.
- Includes several provider components (under “src/app/_providers”) that establish global state management (e.g., for chat data, current media, subtitles, etc.).
- Uses modern React hooks (under “src/app/_hooks”) to manage component-level logic and interactions.
- Backend API and Server Logic
- API endpoints are organized under “src/app/api” (for authentication and tRPC routes) and further elaborated in the “src/server/api/routers” directory (routers for addons, collections, media sources, room, source, subtitle, and user).
- tRPC integration is used for strongly typed API communication between the client and server.
- The “src/server” directory contains additional server files, including authentication (NextAuth integration) and database connection/configuration.
- Database
- The “prisma” directory includes both the Prisma schema and migration files. This establishes the connection and data modeling used by the app.
- Shared Libraries/Utilities and Third-Party Services
- The “src/lib” folder holds shared types, utilities, event emitters, socket configuration, collections handling, and stream functions.
- Under “src/app/_services”, you see further abstractions for sockets, streaming (stremIo), and addons which abstract external service communications.
- Static Assets & Configurations
- The “public” folder holds static assets.
- Config files (Tailwind config, ESLint, Prettier, Next config) support project configuration and styling.

##### Interactions and Data Flow
- Frontend components (pages and UI) interact with provider components which encapsulate global state.
- These UI components call API endpoints via tRPC (or traditional routes under “src/app/api”) to perform operations such as authentication or interacting with media, sources, and rooms.
- Server-side endpoints (in “src/server/api/routers” and “src/server/api/trpc”) handle these requests, enforce business logic, and interact with the database (using Prisma).
- Communication with external services (via socket connections and streaming services) is managed by dedicated services in the “src/app/_services” and “src/lib/socket” folders.
- Data flows from the client through API gateways to the database and external integrations, with feedback and state propagation managed via React providers and event emitters.

##### Architectural Patterns & Design Principles
- The application adheres to a separation of concerns:
- UI Layer/Presentation: All components in “src/app/_ui”, “src/components”, and corresponding providers.
- API/Business Logic Layer: Managed by Next.js API routes and tRPC routers.
- Data Access Layer: Encapsulated with Prisma (migrations, schema) in the “prisma” directory.
- Emphasis on modularity and reusability is apparent by splitting utilities (src/lib) and hooks (src/app/_hooks) for common functionality.
- Real-time or reactive elements are supported via socket services and event emitters.
- File-based routing, a Next.js staple, is used to structure the UI and API endpoints, fostering clarity and ease of navigation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client (Next.js Frontend)
    subgraph "Client (Next.js Frontend)"
        C1("UI Pages & Components"):::frontend
        C2("Providers"):::frontend
        C3("Hooks"):::frontend
    end

    %% API/Gateway Layer
    subgraph "API/Gateway"
        A1("API Endpoints (NextAuth & tRPC)"):::api
        A2("tRPC Routes"):::api
    end

    %% Server Logic Layer
    subgraph "Server Logic"
        S1("Business Logic Routers"):::backend
        S2("Server Files"):::backend
    end

    %% Database Layer
    DB("Prisma Database"):::db

    %% External Services
    subgraph "External Services"
        E1("Socket Service"):::external
        E2("Streaming Service"):::external
    end

    %% Shared Libraries & Static Assets
    SL("Shared Libraries & Utilities"):::shared
    SA("Static Assets & Configurations"):::config

    %% Data Flow
    C1 -->|"API_call"| A1
    A1 -->|"Process_request"| S1
    S1 -->|"DB_query"| DB
    C1 -->|"RealTime_comms"| E1
    C1 -->|"RealTime_stream"| E2
    C1 -->|"Get_assets"| SA
    C1 -->|"Use_shared_libs"| SL
    S2 -->|"Use_shared_libs"| SL

    %% Click Events
    click C1 "https://github.com/neolaner/scoap-next/tree/main/src/app"
    click C2 "https://github.com/neolaner/scoap-next/tree/main/src/app/_providers"
    click C3 "https://github.com/neolaner/scoap-next/tree/main/src/app/_hooks"
    click A1 "https://github.com/neolaner/scoap-next/tree/main/src/app/api"
    click A2 "https://github.com/neolaner/scoap-next/tree/main/src/app/api/trpc"
    click S1 "https://github.com/neolaner/scoap-next/tree/main/src/server/api/routers"
    click S2 "https://github.com/neolaner/scoap-next/tree/main/src/server"
    click DB "https://github.com/neolaner/scoap-next/tree/main/prisma"
    click SL "https://github.com/neolaner/scoap-next/tree/main/src/lib"
    click E1 "https://github.com/neolaner/scoap-next/tree/main/src/app/_services/socket"
    click E2 "https://github.com/neolaner/scoap-next/tree/main/src/app/_services/stremIo"
    click SA "https://github.com/neolaner/scoap-next/tree/main/public"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef api fill:#F7D6AE,stroke:#333,stroke-width:2px;
    classDef backend fill:#D6F7AE,stroke:#333,stroke-width:2px;
    classDef db fill:#F7AEA0,stroke:#333,stroke-width:2px;
    classDef external fill:#E3E3E3,stroke:#333,stroke-width:2px;
    classDef shared fill:#FFF0B3,stroke:#333,stroke-width:2px;
    classDef config fill:#D0B3FF,stroke:#333,stroke-width:2px;
```
