# syntrait/splinux architecture

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

- Interactive diagram: https://gitdiagram.com/syntrait/splinux
- Repository: https://github.com/syntrait/splinux

## Overview

##### Project Type and Purpose
**Splinux** is a utility tool designed for Linux systems that allows users to split their screen and manage multiple instances of applications or games. It leverages technologies like **gamescope**, **Xwayland**, and **bubblewrap** to create isolated environments for each application instance, enabling features such as dual-screen setups and independent input handling.

##### Analysis of File Structure

- **Top-Level Files:**
- `.gitignore`, `Cargo.lock`, `Cargo.toml`: Indicate a Rust-based project with dependency management.
- `LICENSE`, `README.md`: Standard documentation and licensing.

- **`src/` Directory:**
- `main.rs`: Entry point of the application.
- `client.rs`, `gui.rs`, `types.rs`: Suggest modular components handling client interactions, graphical user interface, and type definitions respectively.

**Architectural Patterns:**
- **Modular Architecture:** Separation of concerns through distinct modules (`client`, `gui`, `types`).
- **CLI and GUI Integration:** Implies both command-line and graphical interfaces.

**Configuration and Build:**
- **Cargo:** Utilized for building and managing Rust dependencies.
- **Potential Configuration Files:** Although not explicitly listed, Rust projects may use `config` directories or environment variables for configuration.

##### Insights from README

- **Key Functionalities:**
- Screen splitting and input management using **gamescope**.
- Compatibility with both native and Proton (Steam) games.
- Use of **Xwayland** for X11 compatibility on Wayland systems.
- **bubblewrap** for sandboxing and managing save data locations.

- **Dependencies and Tools:**
- **gamescope**: For managing virtual screens with 3D acceleration.
- **Xwayland**: Compatibility layer for running X11 applications on Wayland.
- **bubblewrap (bwrap)**: Containerization tool for sandboxing applications.
- **Goldberg Emulator**: For patching Steam's DRM components.

- **Architectural Components Mentioned:**
- Interaction with the filesystem (`/tmp/.X11-unix/`, `/dev/input/`).
- Handling of input devices and display identifiers.
- Integration with Steam and Proton for game compatibility.

**a. Main Components:**
- **Backend:**
- **Screen Manager:** Utilizes **gamescope** to create and manage virtual screens.
- **Input Manager:** Interfaces with input devices using **evtest**, manages device IDs, and assigns inputs to specific displays.
- **Sandboxing Module:** Uses **bubblewrap** to isolate application instances and manage save data locations.
- **Steam Integration:** Handles launching and patching of Steam/Proton games, including DRM bypass with **Goldberg**.
- **Configuration Files:** Manages settings, display IDs, device mappings.
- **Logging and Troubleshooting Module:** Captures logs and provides troubleshooting steps.

**b. Relationships and Interactions:**
- **GUI ↔ Backend Modules:**
- User inputs in the GUI are sent to the respective backend modules (e.g., entering display IDs updates the Screen Manager).
- **Backend Modules Interaction:**
- **Screen Manager** communicates with **Input Manager** to assign inputs to specific screens.
- **Sandboxing Module** interacts with both **Screen Manager** and **Steam Integration** to ensure isolated environments for each game instance.
- **External Tools Integration:**
- Backend modules invoke **gamescope**, **bubblewrap**, and **Goldberg Emulator** through system calls or APIs to perform their functions.

**c. Architectural Patterns and Design Principles:**
- **Modularity:** Clear separation between GUI, input management, screen management, and sandboxing.
- **Isolation:** Use of containerization (**bubblewrap**) to ensure that each application instance operates independently.
- **Scalability:** Ability to handle multiple applications/games simultaneously without interference.
- **Security:** Sandboxing ensures limited access to system resources for each application instance.

**d. Technologies, Frameworks, and Libraries:**
- **Rust:** Primary programming language for Splinux.
- **gamescope:** Tool for managing virtual screens with performance optimizations.
- **Xwayland:** Ensures compatibility with X11 applications on Wayland.
- **bubblewrap:** Provides sandboxing capabilities.
- **Goldberg Emulator:** Facilitates DRM bypass for Steam games.
- **evtest:** Utilized for input device enumeration and management.

##### User Interface Layer
- **GUI Module**
- User Inputs (Display IDs, Device IDs)
- Control Buttons (`+` Button)

##### Application Logic Layer
- **Screen Manager**
- Integrates with gamescope
- **Input Manager**
- Interfaces with evtest
- **Sandboxing Module**
- Utilizes bubblewrap
- **Steam Integration**
- Handles game launching
- Integrates Goldberg Emulator

##### External Tools and Services
- **gamescope**
- **Xwayland**
- **bubblewrap**
- **Goldberg Emulator**

##### Data Management
- Configuration Files
- Save Data Locations

- From GUI to Application Logic modules
- Between Application Logic modules to external tools
- Data flow between modules and configuration/data storage

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes

    %% User Interface Layer
    GUI["Frontend (GUI)"]:::frontend

    %% Application Logic Layer
    ScreenManager["Screen Manager"]:::backend
    InputManager["Input Manager"]:::backend
    SandboxingModule["Sandboxing Module"]:::backend
    SteamIntegration["Steam Integration"]:::backend

    %% External Tools and Services
    gamescope["gamescope"]:::external
    Xwayland["Xwayland"]:::external
    bubblewrap["bubblewrap"]:::external
    GoldbergEmulator["Goldberg Emulator"]:::external
    evtest["evtest"]:::external

    %% Data Management
    ConfigFiles["Configuration Files"]:::data
    SaveData["Save Data Locations"]:::data

    %% Logging and Troubleshooting
    Logging["Logging and Troubleshooting Module"]:::logging

    %% Subgraphs
    subgraph "User Interface Layer"
        GUI
    end

    subgraph "Application Logic Layer"
        ScreenManager
        InputManager
        SandboxingModule
        SteamIntegration
    end

    subgraph "External Tools and Services"
        gamescope
        Xwayland
        bubblewrap
        GoldbergEmulator
        evtest
    end

    subgraph "Data Management"
        ConfigFiles
        SaveData
    end

    subgraph "Logging and Troubleshooting"
        Logging
    end

    %% Connections
    GUI -->|User Input| ScreenManager
    GUI -->|User Input| InputManager
    GUI -->|User Input| SandboxingModule
    GUI -->|User Input| SteamIntegration

    ScreenManager -->|Uses| gamescope
    ScreenManager -->|Configuration| ConfigFiles

    InputManager -->|Uses| evtest
    InputManager -->|Configuration| ConfigFiles

    SandboxingModule -->|Uses| bubblewrap
    SandboxingModule -->|Data| SaveData
    SandboxingModule -->|Configuration| ConfigFiles

    SteamIntegration -->|Uses| GoldbergEmulator
    SteamIntegration -->|Uses| Xwayland
    SteamIntegration -->|Configuration| ConfigFiles

    ScreenManager -->|Logs| Logging
    InputManager -->|Logs| Logging
    SandboxingModule -->|Logs| Logging
    SteamIntegration -->|Logs| Logging

    %% Click Events
    click GUI "https://github.com/syntrait/splinux/blob/master/src/gui.rs"
    click ScreenManager "https://github.com/syntrait/splinux/blob/master/src/client.rs"
    click InputManager "https://github.com/syntrait/splinux/blob/master/src/client.rs"
    click SandboxingModule "https://github.com/syntrait/splinux/blob/master/src/client.rs"
    click SteamIntegration "https://github.com/syntrait/splinux/blob/master/src/client.rs"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000
    classDef backend fill:#90ee90,stroke:#000
    classDef external fill:#ffa500,stroke:#000
    classDef data fill:#ffb6c1,stroke:#000
    classDef logging fill:#d3d3d3,stroke:#000
```
