# prabincankod/sunal-rahal architecture

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

- Interactive diagram: https://gitdiagram.com/prabincankod/sunal-rahal
- Repository: https://github.com/prabincankod/sunal-rahal

## Overview

##### Project Type and Main Purpose
- The project is a full-stack Next.js application with both client-side and server-side components.
- Its primary function is to allow users to connect their Spotify account, fetch the currently playing track, and display that information in a visually engaging format.

##### Key Components
a. Frontend (User Interface):
- Next.js pages (found in src/pages) that render the UI, including pages like index.tsx and profile.tsx.
- Reusable UI components (src/components and src/components/ui) such as Navbar, Footer, Layout, Avatar, Button, Card, etc.
- Client-side state management and styling (Tailwind CSS configurations in tailwind.config.js/ts and src/styles).

b. API Layer / Server-side Logic:
- Server directories such as src/pages/api and src/server that house the API endpoints.
- Business Logic & Routers: Represent the TRPC routers (e.g., src/server/api/routers/example.ts) and core “root” API endpoint (src/server/api/root.ts).

c. Database and Persistence:
- Prisma integration using the prisma/schema.prisma file.
- Connection from server-side code (src/server/db.ts) to the database, and mention any ORM-related components.

d. Authentication and External Integration:
- Authentication handler (e.g., src/pages/api/auth/[...nextauth].ts and src/server/auth.ts).

e. Utility and Helper Services:
- Utility modules (src/lib/utils.ts, src/server/utils/*, and src/utils/api.ts) that perform reusable tasks such as generating access tokens or handling data URIs.
- These can be boxed as helper functions that support major flows like API calls or processing third-party responses.

##### Relationships and Data Flow
- From the Browser/User interface to the Next.js pages and UI components.
- From UI components to backend API endpoints (for login, fetch track info, etc.).
- From API endpoints to the database (via Prisma) and to external services (Spotify API).
- Data exchanges among TRPC endpoints and the custom routers.
- Flow of authentication data from the UI to the authentication endpoints and then onto Spotify, ensuring users’ session data is managed appropriately.

##### Architectural Patterns and Technologies
- That the application leverages Next.js for server-side rendering and API routes.
- Use of TRPC for type-safe API procedures, ensuring consistent data contracts between client and server.
- Usage of Prisma as the ORM for database interactions.
- Mention the integration with Spotify’s API, which is central to the project’s music experience feature.
- That UI styling and theming is done with Tailwind CSS.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UserBrowser("User Browser"):::frontend

    subgraph "Frontend"
        subgraph "Next.js Pages"
            PageIndex("Index Page"):::frontend
            PageProfile("Profile Page"):::frontend
            PageApp("App Shell"):::frontend
        end
        subgraph "UI Components"
            Navbar("Navbar"):::frontend
            Footer("Footer"):::frontend
            Layout("Layout"):::frontend
            Avatar("Avatar"):::frontend
            Button("Button"):::frontend
            Card("Card"):::frontend
            Dropdown("Dropdown Menu"):::frontend
            Input("Input"):::frontend
        end
        subgraph "Styling & Configuration"
            TailwindConfig("Tailwind Configuration"):::styling
            GlobalStyles("Global Styles"):::styling
        end
        ClientAPI("Client-side API Helpers"):::frontend
    end

    subgraph "Backend"
        subgraph "API Endpoints"
            AuthAPI("Auth Endpoint"):::api
            SpotifyAPI("Spotify Endpoint"):::api
            TRPCAPI("TRPC API Endpoint"):::api
        end
        subgraph "TRPC & Routers"
            TRPCServer("TRPC Server Setup"):::api
            TRPCRouter("TRPC Routers"):::api
            RootAPI("Root API Endpoint"):::api
        end
        subgraph "Authentication & External Integration"
            AuthIntegration("Spotify Auth Integration"):::external
        end
    end

    subgraph "Database"
        PrismaSchema("Prisma Schema"):::database
        DBConnection("DB Connection"):::database
    end

    subgraph "Utilities & Helpers"
        GeneralUtil("General Utilities"):::utility
        ServerUtil_AT("Generate Access Token"):::utility
        ServerUtil_DataUri("Get Data URI"):::utility
    end

    %% Connections from User Browser to Frontend Pages
    UserBrowser --> PageIndex
    UserBrowser --> PageProfile
    UserBrowser --> PageApp

    %% Connections within Frontend: Pages to UI Components
    PageIndex --> Navbar
    PageIndex --> Footer
    PageIndex --> Layout
    PageProfile --> Navbar
    PageProfile --> Footer
    PageProfile --> Layout
    Layout --> Avatar
    Layout --> Button
    Layout --> Card
    Layout --> Dropdown
    Layout --> Input

    %% Frontend interacts with Client-side API Helpers and Styling
    Navbar --> ClientAPI
    Footer --> ClientAPI
    Layout --> ClientAPI
    Layout --> TailwindConfig
    Layout --> GlobalStyles

    %% Pages calling API Endpoints
    PageIndex -->|"calls"| AuthAPI
    PageProfile -->|"calls"| SpotifyAPI
    PageApp -->|"calls"| TRPCAPI

    %% API Endpoints interacting with Backend & External Services
    AuthAPI -->|"utilizes"| GeneralUtil
    AuthAPI -->|"authWith"| AuthIntegration
    TRPCAPI -->|"utilizes"| GeneralUtil
    TRPCAPI --> TRPCServer

    %% TRPC Server interactions
    TRPCServer --> TRPCRouter
    TRPCServer -->|"generates"| ServerUtil_AT
    TRPCServer -->|"handles"| ServerUtil_DataUri

    %% TRPC Routers interactions with Database and Core Endpoint
    TRPCRouter --> RootAPI
    TRPCRouter --> DBConnection

    %% Database connection
    DBConnection --> PrismaSchema

    %% Class definitions with colours
    classDef frontend fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef api fill:#f9d7a1,stroke:#333,stroke-width:2px;
    classDef database fill:#d1f7c4,stroke:#333,stroke-width:2px;
    classDef external fill:#fad4d4,stroke:#333,stroke-width:2px;
    classDef utility fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef styling fill:#e6ccff,stroke:#333,stroke-width:2px;

    %% Click Events
    click PageIndex "https://github.com/prabincankod/sunal-rahal/blob/main/src/pages/index.tsx"
    click PageProfile "https://github.com/prabincankod/sunal-rahal/blob/main/src/pages/profile.tsx"
    click PageApp "https://github.com/prabincankod/sunal-rahal/blob/main/src/pages/_app.tsx"
    click Navbar "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/Navbar.tsx"
    click Footer "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/Footer.tsx"
    click Layout "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/Layout.tsx"
    click Avatar "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/ui/avatar.tsx"
    click Button "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/ui/button.tsx"
    click Card "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/ui/card.tsx"
    click Dropdown "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/ui/dropdown-menu.tsx"
    click Input "https://github.com/prabincankod/sunal-rahal/blob/main/src/components/ui/input.tsx"
    click AuthAPI "https://github.com/prabincankod/sunal-rahal/blob/main/src/pages/api/auth/[...nextauth].ts"
    click SpotifyAPI "https://github.com/prabincankod/sunal-rahal/blob/main/src/pages/api/getWhatsPlaying/[userSlug].ts"
    click TRPCAPI "https://github.com/prabincankod/sunal-rahal/blob/main/src/pages/api/trpc/[trpc].ts"
    click TRPCRouter "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/api/routers/example.ts"
    click RootAPI "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/api/root.ts"
    click TRPCServer "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/api/trpc.ts"
    click DBConnection "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/db.ts"
    click PrismaSchema "https://github.com/prabincankod/sunal-rahal/blob/main/prisma/schema.prisma"
    click AuthIntegration "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/auth.ts"
    click GeneralUtil "https://github.com/prabincankod/sunal-rahal/blob/main/src/lib/utils.ts"
    click ServerUtil_AT "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/utils/generateAccessToken.ts"
    click ServerUtil_DataUri "https://github.com/prabincankod/sunal-rahal/blob/main/src/server/utils/getDataUri.ts"
    click ClientAPI "https://github.com/prabincankod/sunal-rahal/blob/main/src/utils/api.ts"
    click TailwindConfig "https://github.com/prabincankod/sunal-rahal/blob/main/tailwind.config.js"
    click GlobalStyles "https://github.com/prabincankod/sunal-rahal/blob/main/src/styles/globals.css"
```
