# spruceui/spruceos architecture

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

- Interactive diagram: https://gitdiagram.com/spruceui/spruceos
- Repository: https://github.com/spruceui/spruceos

## Overview

##### Main Components

a. Core System Layer:
- Miyoo OS Base (underlying system)
- Spruce Customization Layer
- System Services & Daemons

b. Application Layer:
- Main UI Interface
- Game Emulators
- Utility Applications
- Network Services

c. Storage & Configuration:
- ROM Management
- Save States
- BIOS Files
- Configuration Files
- Themes System

d. Network Stack:
- WiFi Management
- Network Services (SSH, SFTP, Samba, Syncthing)
- OTA Updates

##### Component Relationships

**[Hardware Layer]**
- ↕
**[Miyoo OS Base] ← → [Spruce System Layer]**
- ↕
**[Core Services] → [System Management]**
- ↕
**┌────────────┴───────────┐**

**[Games] [Apps] [Network] [UI]**

##### Detailed Component Breakdown

a. System Core:
- Runtime Management (/spruce/scripts/runtime.sh)
- Power Management
- CPU Performance Profiles
- Button/Input Handling

b. Applications:
- Game Emulators (RetroArch + specific emulators)
- Utility Apps (BoxartScraper, GameSwitcher, etc.)
- System Tools (Advanced Settings, Firmware Update)

c. Network Stack:
- WiFi Management
- File Transfer Services
- Sync Services
- Update System

d. Storage Management:
- ROM Organization
- Save State Handling
- Theme Management
- Configuration Storage

##### Data Flow Indicators

- Game loading path
- Save state management
- Network data flow
- Configuration changes
- Update process

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef core fill:#b3d9ff,stroke:#333
    classDef app fill:#90EE90,stroke:#333
    classDef network fill:#FFB366,stroke:#333
    classDef storage fill:#DDA0DD,stroke:#333
    classDef config fill:#FFFF99,stroke:#333

    %% Hardware and Base Layer
    subgraph Hardware
        HW[Miyoo A30 Hardware]
    end

    subgraph BaseSystem
        MiyooOS[Miyoo OS Base]:::core
        SpruceLayer[Spruce System Layer]:::core
        SystemServices[System Services & Daemons]:::core
    end

    %% Core Services Layer
    subgraph CoreServices
        Runtime[Runtime Management]:::core
        PowerMgmt[Power Management]:::core
        InputHandler[Input Handling]:::core
    end

    %% Application Layer
    subgraph Apps
        MainUI[Main UI Interface]:::app
        Emulators[Game Emulators]:::app
        RetroArch[RetroArch]:::app
        UtilityApps[Utility Applications]:::app
    end

    %% Storage Layer
    subgraph Storage
        ROMs[ROM Management]:::storage
        SaveStates[Save States]:::storage
        BIOS[BIOS Files]:::storage
        Themes[Themes System]:::storage
    end

    %% Network Services
    subgraph NetworkServices
        WiFi[WiFi Management]:::network
        SSH[SSH Service]:::network
        SFTP[SFTP Service]:::network
        Samba[Samba Service]:::network
        Syncthing[Syncthing Service]:::network
        OTA[OTA Updates]:::network
        BoxArt[BoxArt Scraper]:::network
    end

    %% Configuration
    subgraph Config
        SysConfig[System Configuration]:::config
        EmulatorConfig[Emulator Configuration]:::config
        NetworkConfig[Network Configuration]:::config
    end

    %% Relationships
    HW --> MiyooOS
    MiyooOS --> SpruceLayer
    SpruceLayer --> SystemServices
    SystemServices --> Runtime
    SystemServices --> PowerMgmt
    SystemServices --> InputHandler
    
    Runtime --> MainUI
    Runtime --> Emulators
    Runtime --> UtilityApps
    
    Emulators --> RetroArch
    Emulators --> ROMs
    RetroArch --> SaveStates
    RetroArch --> BIOS
    
    MainUI --> Themes
    
    WiFi --> SSH
    WiFi --> SFTP
    WiFi --> Samba
    WiFi --> Syncthing
    WiFi --> OTA
    WiFi --> BoxArt
    
    SysConfig --> EmulatorConfig
    SysConfig --> NetworkConfig

    %% Click events for component mapping
    click MiyooOS "https://github.com/spruceUI/spruceOS/tree/main//miyoo/"
    click SpruceLayer "https://github.com/spruceUI/spruceOS/tree/main//spruce/"
    click SystemServices "https://github.com/spruceUI/spruceOS/blob/main//spruce/scripts/runtime.sh"
    click MainUI "https://github.com/spruceUI/spruceOS/tree/main//miyoo/app/MainUI"
    click Emulators "https://github.com/spruceUI/spruceOS/tree/main//Emu/"
    click UtilityApps "https://github.com/spruceUI/spruceOS/tree/main//App/"
    click ROMs "https://github.com/spruceUI/spruceOS/tree/main//Roms/"
    click SaveStates "https://github.com/spruceUI/spruceOS/tree/main//Saves/states/"
    click BIOS "https://github.com/spruceUI/spruceOS/tree/main//BIOS/"
    click Themes "https://github.com/spruceUI/spruceOS/tree/main//Themes/"
    click WiFi "https://github.com/spruceUI/spruceOS/blob/main//spruce/scripts/wifi_watchdog.sh"
    click SSH "https://github.com/spruceUI/spruceOS/tree/main//spruce/bin/SSH/"
    click SFTP "https://github.com/spruceUI/spruceOS/tree/main//spruce/bin/SFTPGo/"
    click Samba "https://github.com/spruceUI/spruceOS/tree/main//spruce/bin/Samba/"
    click Syncthing "https://github.com/spruceUI/spruceOS/tree/main//spruce/bin/Syncthing/"
    click RetroArch "https://github.com/spruceUI/spruceOS/tree/main//RetroArch/"
    click BoxArt "https://github.com/spruceUI/spruceOS/tree/main//App/BoxartScraper/"
    click OTA "https://github.com/spruceUI/spruceOS/tree/main//App/-OTA/"

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Applications]:::app
        L3[Network Services]:::network
        L4[Storage]:::storage
        L5[Configuration]:::config
    end
```
