# wolefabikun/lujay architecture

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

- Interactive diagram: https://gitdiagram.com/wolefabikun/lujay
- Repository: https://github.com/wolefabikun/lujay

## Overview

##### Project Type and Purpose
- Full-stack web application built with Next.js (app router + API routes)
- Allows users to search Spotify, get recommendations, preview tracks, and download audio previews

##### Main Components
a. Frontend (Next.js app)
- Server-Rendered React pages (app/layout.tsx, page.tsx, recommendations/page.tsx)
- UI components (components/, ShadCN UI library)
- Static assets (public/, fonts, globals.css)
b. Backend (Next.js API routes)
- Authentication endpoints (spotify/auth/route.ts, callback)
- Data endpoints (search, recommendation, track-data, user-info, refresh_token, download)
- Utility modules (src/lib/getToken.ts, src/lib/utils.ts)
c. External Services
- Spotify Web API (authentication, search, recommendations, user data)
d. Deployment / Hosting
- Vercel (build & deploy)

##### Relationships and Data Flows
- User’s browser → HTTP request → Next.js frontend page
- Frontend → calls Next.js API routes (using Axios or fetch)
- API routes → request to Spotify Web API (OAuth token exchange, search, recommendations)
- Spotify API → returns JSON payloads → API route processes via utils → returns to frontend
- Frontend → renders UI, plays audio previews, triggers “Download Previews” route
- Download route → gathers preview URLs → streams files back to user as ZIP or folder

##### Architectural Patterns & Key Technologies
- App Router pattern (Next.js 13) separating UI layers (app/) from API layers (app/api/)
- Server Functions for all backend logic—no separate microservice needed
- ShadCN UI for design system components, Tailwind for styling
- Axios or native fetch in API and UI (lib/utils.ts)
- Token management via getToken.ts, refresh_token endpoint for long-running sessions

##### Essential Elements
- Clear component names (e.g., “Search Page”, “Recommendations API Route”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser
    Browser["User Browser"]:::external

    %% Infra
    subgraph "Infrastructure"
        Vercel["Vercel"]:::infra
    end

    %% External Services
    subgraph "External Service"
        SpotifyAPI["Spotify Web API"]:::external
    end

    %% Frontend Layer
    subgraph "Frontend (Next.js App)" 
        direction TB

        subgraph "Pages"
            Layout["Layout (app/layout.tsx)"]:::frontend
            SearchPage["Home / Search Page (app/page.tsx)"]:::frontend
            RecPage["Recommendations Page (recommendations/page.tsx)"]:::frontend
        end

        subgraph "UI Components"
            Header["Header"]:::component
            Logo["Logo"]:::component
            Nav["Navigation"]:::component
            MobileNav["Mobile Nav"]:::component
            ParticleBG["Particle Background"]:::component
            ResultsList["Search Results List"]:::component

            subgraph "ShadCN UI Library"
                Badge["Badge"]:::ui
                Button["Button"]:::ui
                Card["Card"]:::ui
                Input["Input"]:::ui
                ScrollArea["Scroll Area"]:::ui
                Sheet["Sheet"]:::ui
            end
        end

        subgraph "Static Assets & Styling"
            Public["Public Assets"]:::asset
            Fonts["Custom Fonts"]:::asset
            GlobalsCSS["Global CSS"]:::asset
            TailwindConfig["Tailwind Config"]:::asset
        end
    end

    %% Backend Layer
    subgraph "Backend (Next.js API Routes)"
        direction TB

        subgraph "Authentication & OAuth"
            AuthInit["Initiate Auth (auth/route.ts)"]:::server
            AuthCallback["Callback Handler (callback/route.ts)"]:::server
        end

        subgraph "Data Endpoints"
            SearchRoute["Search Tracks (search/route.ts)"]:::server
            RecRoute["Get Recommendations (recommendation/route.ts)"]:::server
            TrackData["Track Metadata (track-data/route.ts)"]:::server
            UserInfo["User Profile Info (user-info/route.ts)"]:::server
            RefreshToken["Refresh OAuth Token (refresh_token/route.ts)"]:::server
            Download["Download Previews (download/route.ts)"]:::server
        end

        subgraph "Utility Modules"
            GetToken["getToken.ts"]:::utils
            Utils["utils.ts"]:::utils
        end
    end

    %% Connections
    Browser -->|Visits Home| SearchPage
    Browser -->|Visits Recommendations| RecPage
    Browser -->|Loads Layout| Layout

    %% Page uses components
    Layout --> Header
    Layout --> Logo
    Layout --> Nav
    Layout --> MobileNav
    Layout --> ParticleBG

    SearchPage --> Input
    SearchPage --> Button
    SearchPage --> ResultsList

    RecPage --> Card
    RecPage --> Button
    RecPage --> ScrollArea

    %% API calls from frontend
    SearchPage -->|GET /api/spotify/search| SearchRoute
    RecPage -->|GET /api/spotify/recommendation| RecRoute
    SearchPage -->|POST /api/spotify/auth| AuthInit
    AuthInit -->|redirect| AuthCallback
    Download -->|GET Previews| Download
    SearchPage -->|GET /api/spotify/user-info| UserInfo
    SearchPage -->|POST /api/spotify/refresh_token| RefreshToken
    SearchPage -->|GET /api/spotify/track-data| TrackData

    %% API to Utils & Token
    AuthCallback --> GetToken
    SearchRoute --> Utils
    RecRoute --> Utils
    TrackData --> Utils
    Download --> Utils
    RefreshToken --> GetToken

    %% API <-> Spotify
    SearchRoute -->|requests| SpotifyAPI
    RecRoute -->|requests| SpotifyAPI
    TrackData -->|requests| SpotifyAPI
    UserInfo -->|requests| SpotifyAPI
    RefreshToken -->|requests| SpotifyAPI
    Download -->|uses| SpotifyAPI
    AuthInit -->|requests| SpotifyAPI
    AuthCallback -->|exchanges token| SpotifyAPI

    %% Deployment
    Vercel -->|deploys| Frontend
    Vercel -->|deploys| Backend

    %% Click Events
    click Layout "https://github.com/wolefabikun/lujay/blob/main/src/app/layout.tsx"
    click SearchPage "https://github.com/wolefabikun/lujay/blob/main/src/app/page.tsx"
    click RecPage "https://github.com/wolefabikun/lujay/blob/main/src/app/recommendations/page.tsx"
    click Header "https://github.com/wolefabikun/lujay/blob/main/src/components/header.tsx"
    click Logo "https://github.com/wolefabikun/lujay/blob/main/src/components/logo.tsx"
    click Nav "https://github.com/wolefabikun/lujay/blob/main/src/components/nav.tsx"
    click MobileNav "https://github.com/wolefabikun/lujay/blob/main/src/components/mobile-nav.tsx"
    click ParticleBG "https://github.com/wolefabikun/lujay/blob/main/src/components/particle-bg.tsx"
    click ResultsList "https://github.com/wolefabikun/lujay/blob/main/src/components/results.tsx"
    click Badge "https://github.com/wolefabikun/lujay/blob/main/src/components/ui/badge.tsx"
    click Button "https://github.com/wolefabikun/lujay/blob/main/src/components/ui/button.tsx"
    click Card "https://github.com/wolefabikun/lujay/blob/main/src/components/ui/card.tsx"
    click Input "https://github.com/wolefabikun/lujay/blob/main/src/components/ui/input.tsx"
    click ScrollArea "https://github.com/wolefabikun/lujay/blob/main/src/components/ui/scroll-area.tsx"
    click Sheet "https://github.com/wolefabikun/lujay/blob/main/src/components/ui/sheet.tsx"
    click Public "https://github.com/wolefabikun/lujay/tree/main/public/"
    click Fonts "https://github.com/wolefabikun/lujay/tree/main/src/app/fonts/"
    click GlobalsCSS "https://github.com/wolefabikun/lujay/blob/main/src/app/globals.css"
    click TailwindConfig "https://github.com/wolefabikun/lujay/blob/main/tailwind.config.ts"
    click AuthInit "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/auth/route.ts"
    click AuthCallback "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/callback/route.ts"
    click SearchRoute "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/search/route.ts"
    click RecRoute "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/recommendation/route.ts"
    click TrackData "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/track-data/route.ts"
    click UserInfo "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/user-info/route.ts"
    click RefreshToken "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/refresh_token/route.ts"
    click Download "https://github.com/wolefabikun/lujay/blob/main/src/app/api/spotify/download/route.ts"
    click GetToken "https://github.com/wolefabikun/lujay/blob/main/src/lib/getToken.ts"
    click Utils "https://github.com/wolefabikun/lujay/blob/main/src/lib/utils.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0288D1,color:#000
    classDef component fill:#E0F7FA,stroke:#00796B,color:#000
    classDef ui fill:#F3E5F5,stroke:#6A1B9A,color:#000
    classDef asset fill:#FFF3E0,stroke:#F57C00,color:#000
    classDef server fill:#E8F5E9,stroke:#388E3C,color:#000
    classDef utils fill:#FFFDE7,stroke:#FBC02D,color:#000
    classDef external fill:#ECEFF1,stroke:#607D8B,color:#000
    classDef infra fill:#FFF8E1,stroke:#FFA000,color:#000
```
