# zaneh/piano-trainer architecture

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

- Interactive diagram: https://gitdiagram.com/zaneh/piano-trainer
- Repository: https://github.com/zaneh/piano-trainer

## Overview

##### Main Components

a. Frontend Layer (React):
- User Interface Components (ScreenManager, Quiz, Trainer, Keyboard)
- Provider Components (KV, Soundfont, Trainer, Sidebar)
- Internationalization (i18n)
- Utils (scales, modes, MIDI handling)

b. Backend Layer (Tauri/Rust):
- MIDI Device Integration
- Native System Integration
- Cross-platform Features

c. External Dependencies:
- MIDI Devices
- Soundfont System
- File System (for settings/configuration)

##### Component Relationships

- Data flow between Providers and UI Components
- User input flow from Keyboard/MIDI to Trainer/Quiz components
- Sound output flow from Soundfont Provider to system audio

##### Specific Implementation Details

a. State Management:
- Provider components (KV, Sidebar, Trainer, Soundfont)
- Their relationships with UI components

b. User Interface Flow:
- ScreenManager coordination with other components
- Quiz and Trainer interaction patterns
- Settings management through SettingsSidebar

##### Technical Stack Indicators

Technology labels:
- React/TypeScript (Frontend)
- Tauri/Rust (Backend)
- MIDI Protocol
- Soundfont Technology
- i18n (Multiple language support)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef provider fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white
    classDef utils fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        UI[User Interface Layer]
        SM[ScreenManager]
        QZ[Quiz Component]
        TR[Trainer Component]
        KB[Keyboard Component]
        ST[Settings UI]
    end

    %% Provider Layer
    subgraph Providers
        KVP[KV Provider]
        SFP[Soundfont Provider]
        TRP[Trainer Provider]
        SBP[Sidebar Provider]
    end

    %% Backend Layer
    subgraph Backend
        TB[Tauri Backend]
        MIDI[MIDI Integration]
        NSI[Native System Integration]
    end

    %% Utils Layer
    subgraph Utils
        I18N[Internationalization]
        MUTIL[MIDI Utils]
        SUTIL[Scales Utils]
        PUTIL[Practice Modes]
        SOUND[Sound Utils]
    end

    %% External Systems
    MDEV[MIDI Devices]:::external
    SFS[Soundfont System]:::external
    FSY[File System]:::external

    %% Relationships
    TB --> MIDI
    MIDI <--> MDEV
    TB <--> FSY
    SFP <--> SFS
    
    KVP --> UI
    SFP --> UI
    TRP --> UI
    SBP --> UI
    
    SM --> QZ
    SM --> TR
    SM --> KB
    SM --> ST
    
    TR --> KB
    QZ --> KB
    
    MUTIL --> MIDI
    SUTIL --> TR
    PUTIL --> TR
    SOUND --> SFP
    I18N --> UI

    %% Style Applications
    class UI,SM,QZ,TR,KB,ST frontend
    class TB,MIDI,NSI backend
    class KVP,SFP,TRP,SBP provider
    class I18N,MUTIL,SUTIL,PUTIL,SOUND utils
    
    %% Click Events
    click SM "https://github.com/ZaneH/piano-trainer/blob/main/src/components/ScreenManager/ScreenManager.tsx"
    click QZ "https://github.com/ZaneH/piano-trainer/blob/main/src/components/Quiz/Quiz.tsx"
    click TR "https://github.com/ZaneH/piano-trainer/blob/main/src/components/Trainer/TrainerPiano.tsx"
    click KB "https://github.com/ZaneH/piano-trainer/blob/main/src/components/Keyboard/Keyboard.tsx"
    click KVP "https://github.com/ZaneH/piano-trainer/blob/main/src/components/KVProvider/KVProvider.tsx"
    click SFP "https://github.com/ZaneH/piano-trainer/blob/main/src/components/SoundfontProvider/SoundfontProvider.tsx"
    click TRP "https://github.com/ZaneH/piano-trainer/blob/main/src/components/TrainerProvider/TrainerProvider.tsx"
    click SBP "https://github.com/ZaneH/piano-trainer/blob/main/src/components/SidebarProvider/SidebarProvider.tsx"
    click I18N "https://github.com/ZaneH/piano-trainer/tree/main/src/i18n/"
    click MUTIL "https://github.com/ZaneH/piano-trainer/blob/main/src/utils/midi.ts"
    click SUTIL "https://github.com/ZaneH/piano-trainer/tree/main/src/utils/scales/"
    click PUTIL "https://github.com/ZaneH/piano-trainer/blob/main/src/utils/modes/practice.ts"
    click SOUND "https://github.com/ZaneH/piano-trainer/blob/main/src/utils/sounds.ts"
    click TB "https://github.com/ZaneH/piano-trainer/blob/main/src-tauri/src/main.rs"
    click ST "https://github.com/ZaneH/piano-trainer/blob/main/src/components/SettingsSidebar/SettingsSidebar.tsx"
```
