# hadryan/splayer architecture

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

- Interactive diagram: https://gitdiagram.com/hadryan/splayer
- Repository: https://github.com/hadryan/splayer

## Overview

##### Major Components
- Electron Main Process & Preload Scripts:
- In the “electron/main” directory you have files such as createGlobalShortcut.js, startMainServer.js, and mainIpcMain.js that constitute the Electron main process. This handles system-level operations (shortcuts, server startup, IPC coordination).
- The “electron/preload” folder holds the preload script(s) that form the bridge between the main process and the renderer (UI) process.
- Renderer / Frontend (Vue Application):
- The “src” folder comprises components, views, routing (in src/router), state management (src/stores), APIs (src/api), and utilities. This area is responsible for the UI, user interactions, and business logic.
- Public Assets:
- The “public” directory includes static assets (images, fonts) used by the UI.
- External API Service:
- Although not part of this repository, the README makes clear that the application depends on an external NeteaseCloudMusicApi server and also supports services like UnblockNeteaseMusic.
- Build and Configuration:
- Documents like electron-builder.yml and electron.vite.config.js, along with other config files at the root, facilitate bundling and deployment for various platforms (Windows, Linux, macOS).

##### Relationships and Data Flow
- The Electron Main process starts the native application shell and spawns the renderer process.
- The Preload script exposes selective APIs to the Vue frontend (renderer), allowing safe interaction with Node/Electron resources (for example, global shortcuts and filesystem access).
- Within the Vue application, components communicate via the Vue Router and Vuex-like state management (or similar store in “src/stores”) to handle UI state, user actions, and routing.
- The Vue frontend makes RESTful API calls (visible in “src/api”) to the external music API. This layer also handles local song management and other client-specific tasks.
- There is also an interaction flow between local file operations (for local song management) and core Electron functions.
- Requests from UI components → API utility functions → External Music API.
- User interaction events → local state store updates → UI updates across components.
- Electron IPC communication between main and renderer processes.

##### Architectural Patterns & Design Principles
- Separation of Concerns:
- Clear split between Electron’s main process (system-level functionality) and the Vue renderer (UI logic).
- Modular Design:
- The “src” folder is organized by features (api, views, components, stores, and utils) to ensure each functional piece is encapsulated.
- Client-Server Communication:
- The project uses RESTful API calls to fetch music data and perform actions (login, playlist management).
- Multi-Platform Considerations:
- Distinct build pipelines for web and desktop (with scripts for win/linux/mac) indicate platform-specific concerns managed through build scripts and configuration.

##### Relevant Technologies, Frameworks, and Libraries
- Vue 3 and its ecosystem (router, state management).
- Naïve UI for the component library.
- Electron for packaging the desktop application.
- Vite as a bundler (see electron.vite.config.js, along with development build commands in the README).
- External dependencies like NeteaseCloudMusicApi and UnblockNeteaseMusic which are essential for service integration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Electron Shell Subgraph
    subgraph "Electron Shell"
        EM["Electron Main Process"]:::electron
        EP["Electron Preload Script"]:::electron
    end

    %% Vue Renderer Subgraph
    subgraph "Vue Renderer (Frontend)"
        VFE["Vue Renderer (Frontend)"]:::renderer
        UI["UI Components"]:::renderer
        VR["Vue Router"]:::renderer
        SM["State Management"]:::renderer
        API["API Layer"]:::renderer
        VFE -->|"contains"| UI
        VFE -->|"contains"| VR
        VFE -->|"contains"| SM
        VFE -->|"contains"| API
    end

    %% Other Components
    PA["Public Assets"]:::public
    EXT["External Music API/Services"]:::external
    BC["Build & Configuration"]:::config

    %% Electron and Vue Interactions
    EM -->|"initializes"| EP
    EP -->|"bridges to"| VFE
    EM -->|"spawns renderer"| VFE

    %% Vue Internal Data Flow
    UI -->|"triggers"| SM
    SM -->|"updates"| UI
    UI -->|"calls"| API
    API -->|"REST_API"| EXT
    UI -->|"navigates"| VR

    %% Public Assets and Build Flow
    VFE -->|"loads"| PA
    BC -->|"builds"| EM
    BC -->|"builds"| VFE

    %% Click Events
    click EM "https://github.com/hadryan/splayer/tree/master/electron/main"
    click EP "https://github.com/hadryan/splayer/blob/master/electron/preload/index.js"
    click VFE "https://github.com/hadryan/splayer/tree/master/src"
    click PA "https://github.com/hadryan/splayer/tree/master/public"
    click BC "https://github.com/hadryan/splayer/blob/master/electron-builder.yml"

    %% Class Definitions for Colors
    classDef electron fill:#B3D7FF,stroke:#1E90FF,stroke-width:2px;
    classDef renderer fill:#C2FFC2,stroke:#32CD32,stroke-width:2px;
    classDef public fill:#FFCCE5,stroke:#FF69B4,stroke-width:2px;
    classDef external fill:#FFF5BA,stroke:#FFD700,stroke-width:2px;
    classDef config fill:#E6E6FA,stroke:#9370DB,stroke-width:2px;
```
