# totuus1157/apple-music-hi-res-albums-database architecture

> Architecture diagram of the GitHub repository totuus1157/apple-music-hi-res-albums-database, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/totuus1157/apple-music-hi-res-albums-database
- Repository: https://github.com/totuus1157/apple-music-hi-res-albums-database

## Overview

##### Project type and purpose
- This is a full-stack, server-rendered React application built on Next.js (using both App Router and legacy Pages Router in parallel).
- Its purpose is to let “Apple and Music Lovers” browse, store, and manage a database of hi-res lossless albums. It also handles authentication, sharing via Twitter, and Open Graph image generation.

##### File structure
- Top level: Configuration files (next.config.ts, tailwind.config.ts, tsconfig.json), package.json, public assets.
- src/app: Primary UI (App Router). Contains page layouts, datatable components, custom scripts (cookie consent, Google Ads), and App-Router API routes under src/app/api.
- api/apple-music: Proxy endpoints to Apple Music (album data, storefronts)
- api/og: Serverless route to generate Open Graph images
- src/pages/api: Legacy Next.js API routes for authentication (Auth0), database CRUD (add/get/delete albums), and Twitter sharing.
- src/app/datatable: Reusable UI & business logic for displaying and editing the album table.
- public: Static assets (images, robots.txt, ads.txt).

##### README
- Confirms the purpose (list of hi-res lossless albums)
- Mentions ongoing work (migrating datatable pages from Pages Router to App Router; allowing users to self-manage auth credentials).

## Diagram (Mermaid)

```mermaid
graph TB
    %% Layers
    subgraph "Client"
        direction TB
        Browser["Browser / React UI"]:::frontend
    end

    subgraph "Frontend Layer"
        direction TB
        subgraph "App Router UI"
            direction TB
            AppRouter["src/app"]:::frontend
            Layout["layout.tsx"]:::frontend
            Page["page.tsx"]:::frontend
            Providers["providers.tsx"]:::frontend
            CookieConsent["cookie-consent-widget-script.tsx"]:::frontend
            GoogleAdSlot["googlead-slot-id.ts"]:::frontend
            GoogleAdsScript["googleads-script.tsx"]:::frontend
            GoogleAdComp["googlead.tsx"]:::frontend
            subgraph "Datatable Module"
                direction TB
                DatatableComp["datatable.tsx"]:::logic
                AlbumFormatter["album-formatter.ts"]:::logic
                APIRequest["api-request.ts"]:::logic
                EditTable["edit-table.tsx"]:::logic
                Modal["modal.tsx"]:::logic
                DatatablePage["page.tsx"]:::logic
                DatatableLayout["layout.tsx"]:::logic
                ExtractInfo["extract-album-info.ts"]:::logic
                ErrorMessage["get-error-message.ts"]:::logic
                Types["types.ts"]:::logic
            end
        end
        subgraph "Public Assets"
            direction TB
            Images["public/images"]:::frontend
            Robots["public/robots.txt"]:::frontend
            AdsTxt["public/ads.txt"]:::frontend
        end
    end

    subgraph "Backend Layer"
        direction TB
        NextServer["Next.js Server"]:::backend
        subgraph "App-Router API Routes"
            direction TB
            AppleMusicAPI["src/app/api/apple-music"]:::api
            Storefronts["get-storefronts/route.ts"]:::api
            AlbumData["[...storefrontAndAlbum]/route.ts"]:::api
            OGImage["src/app/api/og/route.js"]:::api
        end
        subgraph "Pages-Router API Routes"
            direction TB
            Auth0API["src/pages/api/auth/[auth0].js"]:::api
            subgraph "Database CRUD"
                direction TB
                AddAlbum["add-album.ts"]:::api
                GetAlbums["get-albums.ts"]:::api
                DeleteAlbum["delete-album.ts"]:::api
            end
            TweetAPI["src/pages/api/twitter/tweet.ts"]:::api
        end
        Database["Database"]:::db
    end

    subgraph "External Services"
        direction TB
        AppleMusicExt["Apple Music API"]:::external
        Auth0Ext["Auth0"]:::external
        TwitterExt["Twitter API"]:::external
        GoogleAdsExt["Google Ads"]:::external
    end

    %% Connections
    Browser -->|"renders UI"| AppRouter
    Browser -->|"loads assets"| Images
    Browser -->|"fetch /api/apple-music"| AlbumData
    Browser -->|"fetch /api/apple-music"| Storefronts
    Browser -->|"fetch /api/database"| GetAlbums
    Browser -->|"fetch /api/database"| AddAlbum
    Browser -->|"fetch /api/database"| DeleteAlbum
    Browser -->|"fetch /api/twitter/tweet"| TweetAPI

    AppRouter -->|SSR/SSG| NextServer
    NextServer -->|uses| AppleMusicAPI
    NextServer -->|uses| OGImage
    NextServer -->|handles| Auth0API
    NextServer -->|handles| AddAlbum
    NextServer -->|handles| GetAlbums
    NextServer -->|handles| DeleteAlbum
    NextServer -->|handles| TweetAPI
    NextServer -->|calls| Database

    NextServer -->|Auth handshake| Auth0Ext
    NextServer -->|requests metadata| AppleMusicExt
    NextServer -->|posts tweets| TwitterExt
    NextServer -->|inject scripts| GoogleAdsExt

    DatatableComp -->|UI logic| NextServer
    APIRequest -->|calls API routes| NextServer

    %% Click events
    click AppRouter "https://github.com/totuus1157/apple-music-hi-res-albums-database/tree/main/src/app"
    click Layout "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/layout.tsx"
    click Page "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/page.tsx"
    click AppleMusicAPI "https://github.com/totuus1157/apple-music-hi-res-albums-database/tree/main/src/app/api/apple-music"
    click Storefronts "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/api/apple-music/get-storefronts/route.ts"
    click AlbumData "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/api/apple-music/[...storefrontAndAlbum]/route.ts"
    click OGImage "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/api/og/route.js"
    click Auth0API "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/pages/api/auth/[auth0].js"
    click AddAlbum "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/pages/api/database/add-album.ts"
    click GetAlbums "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/pages/api/database/get-albums.ts"
    click DeleteAlbum "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/pages/api/database/delete-album.ts"
    click TweetAPI "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/pages/api/twitter/tweet.ts"
    click DatatableComp "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/datatable.tsx"
    click AlbumFormatter "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/album-formatter.ts"
    click APIRequest "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/api-request.ts"
    click EditTable "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/edit-table.tsx"
    click Modal "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/modal.tsx"
    click DatatablePage "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/page.tsx"
    click DatatableLayout "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/layout.tsx"
    click ExtractInfo "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/extract-album-info.ts"
    click ErrorMessage "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/get-error-message.ts"
    click Types "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/datatable/types.ts"
    click CookieConsent "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/cookie-consent-widget-script.tsx"
    click GoogleAdSlot "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/googlead-slot-id.ts"
    click GoogleAdsScript "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/googleads-script.tsx"
    click GoogleAdComp "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/googlead.tsx"
    click Providers "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/src/app/providers.tsx"
    click Images "https://github.com/totuus1157/apple-music-hi-res-albums-database/tree/main/public/images"
    click Robots "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/public/robots.txt"
    click AdsTxt "https://github.com/totuus1157/apple-music-hi-res-albums-database/blob/main/public/ads.txt"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#E8F5D0,stroke:#2a7f2a,color:#2a7f2a
    classDef api fill:#DFF0D8,stroke:#3c763d,color:#3c763d
    classDef db fill:#FFF5CC,stroke:#b78900,color:#b78900
    classDef external fill:#F0F0F0,stroke:#6c6c6c,color:#6c6c6c
    classDef logic fill:#F5D0E8,stroke:#9f005f,color:#9f005f
```
