# polymeilex/neothesia architecture

> Architecture diagram of the GitHub repository polymeilex/neothesia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/polymeilex/neothesia
- Repository: https://github.com/polymeilex/neothesia

## Overview

##### Main System Components

a. Core Application Layer:
- neothesia (main application)
- neothesia-core (core rendering and functionality)
- neothesia-cli (command-line interface)
- neothesia-ai (AI-related functionality)

b. Input/Output Layer:
- midi-file (MIDI file parsing and playback)
- midi-io (MIDI I/O operations)
- mpeg_encoder (video encoding capabilities)

c. UI/Rendering Layer:
- neothesia-iced-widgets (custom UI widgets)
- wgpu-jumpstart (GPU rendering utilities)
- nuon (UI widget system)
- piano-layout (piano visualization)

##### Component Relationships

a. Data Flow:
- MIDI File → midi-file → neothesia-core → Rendering Pipeline
- User Input → neothesia → neothesia-core → Output Manager
- Video Export → neothesia-cli → mpeg_encoder

b. Dependencies:
- How neothesia-core is the central component that other modules depend on
- Relationship between UI components and the core rendering system

##### Architectural Patterns

a. Scene Management:
- Menu Scene
- Playing Scene
- Settings Management

b. Rendering Pipeline:
- Background Animation
- Waterfall Effect
- Keyboard Visualization
- Glow Effects

##### Technical Implementation

- Blue rectangles: Core components
- Green rectangles: I/O handling
- Purple rectangles: UI components
- Orange rectangles: Rendering components

**┌─────────────────────────────────────────────┐**
- User Interface               │
- (neothesia-iced-widgets, nuon)             │
- ┤
- Core Application              │
- (neothesia-core, scene management)         │
- ┤
- Rendering Engine              │
- (wgpu-jumpstart, waterfall, keyboard)      │
- ┤
- I/O Handling                 │
- (midi-file, midi-io, mpeg_encoder)         │
- ┘

##### Important Details

- Configuration management (settings.ron)
- Platform-specific implementations (Flatpak, Windows, macOS)
- Audio output options (MIDI backend, synth backend)
- Resource management (SF2 files, assets)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph UI_Layer["User Interface Layer"]
        IcedWidgets["Custom UI Widgets"]:::ui
        Nuon["Widget System"]:::ui
        MenuScene["Menu Scene"]:::ui
        PlayingScene["Playing Scene"]:::ui
        Settings["Settings Management"]:::ui
    end

    subgraph Core_Layer["Core Application Layer"]
        Neothesia["Main Application"]:::core
        NeothesiaCore["Core Engine"]:::core
        NeothesiaCLI["CLI Interface"]:::core
        NeothesiaAI["AI Functionality"]:::core
        Config["Configuration"]:::core
        Resources["Resource Management"]:::core
    end

    subgraph Render_Layer["Rendering Layer"]
        WGPUJumpstart["GPU Rendering Utilities"]:::render
        Background["Background Animation"]:::render
        Waterfall["Waterfall Effect"]:::render
        Keyboard["Keyboard Visualization"]:::render
        Glow["Glow Effects"]:::render
        PianoLayout["Piano Visualization"]:::render
    end

    subgraph IO_Layer["I/O Layer"]
        MIDIFile["MIDI File Handler"]:::io
        MIDIIO["MIDI I/O Operations"]:::io
        MPEGEncoder["Video Encoder"]:::io
        OutputManager["Output Management"]:::io
    end

    subgraph Platform_Layer["Platform Support"]
        Flatpak["Flatpak Build"]:::platform
        MacOS["macOS Build"]:::platform
    end

    %% Relationships
    MIDIFile --> NeothesiaCore
    MIDIIO --> NeothesiaCore
    MPEGEncoder --> NeothesiaCLI
    
    NeothesiaCore --> WGPUJumpstart
    NeothesiaCore --> Background
    NeothesiaCore --> Waterfall
    NeothesiaCore --> Keyboard
    NeothesiaCore --> Glow
    
    IcedWidgets --> Neothesia
    Nuon --> Neothesia
    MenuScene --> Neothesia
    PlayingScene --> Neothesia
    
    Neothesia --> NeothesiaCore
    NeothesiaCLI --> NeothesiaCore
    NeothesiaAI --> NeothesiaCore
    
    Config --> NeothesiaCore
    Resources --> NeothesiaCore
    
    PianoLayout --> Keyboard

    %% Click Events
    click Neothesia "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia"
    click NeothesiaCore "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-core"
    click NeothesiaCLI "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-cli"
    click NeothesiaAI "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-ai"
    click MIDIFile "https://github.com/PolyMeilex/Neothesia/tree/master/midi-file"
    click MIDIIO "https://github.com/PolyMeilex/Neothesia/tree/master/midi-io"
    click MPEGEncoder "https://github.com/PolyMeilex/Neothesia/tree/master/mpeg_encoder"
    click OutputManager "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia/src/output_manager"
    click IcedWidgets "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-iced-widgets"
    click WGPUJumpstart "https://github.com/PolyMeilex/Neothesia/tree/master/wgpu-jumpstart"
    click Nuon "https://github.com/PolyMeilex/Neothesia/tree/master/nuon"
    click PianoLayout "https://github.com/PolyMeilex/Neothesia/tree/master/piano-layout"
    click MenuScene "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia/src/scene/menu_scene"
    click PlayingScene "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia/src/scene/playing_scene"
    click Settings "https://github.com/PolyMeilex/Neothesia/blob/master/neothesia/src/scene/menu_scene/iced_menu/settings.rs"
    click Background "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-core/src/render/background_animation"
    click Waterfall "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-core/src/render/waterfall"
    click Keyboard "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-core/src/render/keyboard"
    click Glow "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-core/src/render/glow"
    click Config "https://github.com/PolyMeilex/Neothesia/tree/master/neothesia-core/src/config"
    click Resources "https://github.com/PolyMeilex/Neothesia/blob/master/neothesia-core/src/utils/resources.rs"
    click Flatpak "https://github.com/PolyMeilex/Neothesia/tree/master/flatpak"
    click MacOS "https://github.com/PolyMeilex/Neothesia/blob/master/.github/app/Neothesia.app"

    %% Styling
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef io fill:#4CAF50,stroke:#2E7D32,color:white
    classDef ui fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef render fill:#FF9800,stroke:#EF6C00,color:white
    classDef platform fill:#795548,stroke:#4E342E,color:white
```
