# betterthanhajin/my-melody architecture

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

- Interactive diagram: https://gitdiagram.com/betterthanhajin/my-melody
- Repository: https://github.com/betterthanhajin/my-melody

## Overview

##### Main Components

A. Frontend Layer
- Next.js Application (React + TypeScript)
- UI Components Structure
- CD Player Interface
- YouTube Music Components
- Material-UI Components
- State Management (lib/state)

B. API Layer (Next.js API Routes)
- Speech-to-Text Endpoint
- Image Generation Endpoint

C. External Services Integration
- OpenAI Integration
- R2 Storage Service
- Voice Activity Detection (VAD)

**[Client Layer]**
- ↕️
**[API Layer]**
- ↕️
**[External Services]**

##### Detailed Component Breakdown

Client Layer (Top):

- UI Components     |

- CD Player     |  |
- Music Player  |  |
- Controls      |  |

- ↕️            |

- State Manager  |  |

API Layer (Middle):

- Next.js API Routes  |

- Speech-to-Text   |  |
- Image Generation |  |

External Services (Bottom):

- External Services    |

- OpenAI API   |  |
- R2 Storage   |  |
- VAD Service  |  |

##### Key Interactions to Highlight

A. Voice Processing Flow:
**User Input → VAD → Speech-to-Text API → OpenAI → Image Generation**

B. Music Playback Flow:
**Music Selection → State Manager → CD Player → Audio Output**

##### Important Details

- Clear labeling of all components
- API endpoint specifications
- State management flow
- Storage interactions
- External service dependencies

##### Technical Stack Callouts

- Next.js/React/TypeScript
- Material-UI components
- OpenAI integration
- R2 storage system
- VAD library

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        UI[UI Components]
        CD["CD Player Interface"]
        YT["YouTube Music Components"]
        Controls["UI Controls"]
        State["State Management"]
        
        subgraph YTComponents["YouTube Components"]
            MC["Music Container"]
            MF["Music Footer"]
            MH["Music Header"]
            MP["Music Playlist"]
        end
        
        subgraph UIControls["UI Controls"]
            Slider["Continuous Slider"]
            History["History Component"]
            MCard["Media Card"]
            MHistory["Music History"]
            Buttons["Outlined Buttons"]
        end
    end

    subgraph APILayer["API Layer"]
        STT["Speech-to-Text API"]
        IMG["Image Generation API"]
    end

    subgraph External["External Services"]
        OpenAI["OpenAI Service"]
        R2["R2 Storage"]
        VAD["Voice Activity Detection"]
    end

    UI --> CD
    UI --> YT
    UI --> Controls
    YT --> State
    CD --> State
    Controls --> State

    State --> APILayer
    APILayer --> External

    %% Component relationships within YouTube
    YT --> MC
    YT --> MF
    YT --> MH
    YT --> MP

    %% Component relationships within Controls
    Controls --> Slider
    Controls --> History
    Controls --> MCard
    Controls --> MHistory
    Controls --> Buttons

    %% Data flow
    STT --> OpenAI
    IMG --> R2
    VAD --> STT

    %% Click events
    click CD "https://github.com/betterthanhajin/my-melody/blob/master/components/cd-player.tsx"
    click MC "https://github.com/betterthanhajin/my-melody/blob/master/components/youtube-music/music-container.tsx"
    click MF "https://github.com/betterthanhajin/my-melody/blob/master/components/youtube-music/music-footer.tsx"
    click MH "https://github.com/betterthanhajin/my-melody/blob/master/components/youtube-music/music-header.tsx"
    click MP "https://github.com/betterthanhajin/my-melody/blob/master/components/youtube-music/music-play-list.tsx"
    click Slider "https://github.com/betterthanhajin/my-melody/blob/master/components/ui/ContinuousSlider.tsx"
    click History "https://github.com/betterthanhajin/my-melody/blob/master/components/ui/History.tsx"
    click MCard "https://github.com/betterthanhajin/my-melody/blob/master/components/ui/MediaCard.tsx"
    click MHistory "https://github.com/betterthanhajin/my-melody/blob/master/components/ui/MusicHistory.tsx"
    click Buttons "https://github.com/betterthanhajin/my-melody/blob/master/components/ui/OutlinedButtons.tsx"
    click State "https://github.com/betterthanhajin/my-melody/blob/master/lib/state/music-state.ts"
    click STT "https://github.com/betterthanhajin/my-melody/blob/master/app/api/speech-to-text/route.ts"
    click IMG "https://github.com/betterthanhajin/my-melody/blob/master/app/api/create-image/route.ts"
    click OpenAI "https://github.com/betterthanhajin/my-melody/blob/master/lib/openai/speech-to-text.ts"
    click R2 "https://github.com/betterthanhajin/my-melody/blob/master/lib/storage/r2Client.ts"
    click YT "https://github.com/betterthanhajin/my-melody/tree/master/components/youtube-music"
    click Controls "https://github.com/betterthanhajin/my-melody/tree/master/components/ui"

    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef api fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#9b59b6,stroke:#8e44ad,color:white
    classDef component fill:#e74c3c,stroke:#c0392b,color:white

    class UI,CD,YT,Controls,State,MC,MF,MH,MP,Slider,History,MCard,MHistory,Buttons frontend
    class STT,IMG api
    class OpenAI,R2,VAD external
    class YTComponents,UIControls component
```
