# alez-dev/babylonia-terminal architecture

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

- Interactive diagram: https://gitdiagram.com/alez-dev/babylonia-terminal
- Repository: https://github.com/alez-dev/babylonia-terminal

## Overview

##### Project Type and Purpose
- This project is a launcher for anime games. It handles the downloading and installation of the game and its dependencies.
- There are two main variants:
– A CLI version (contained in the “babylonia-terminal-cli” directory) which manages game launching and patching.
– A GUI version (located under “babylonia_terminal_launcher”), which, in this GTK branch update, should now use GTK for its interface rather than its previous Flutter or other UI paradigms.
- The “babylonia-terminal-sdk” directory holds the core library functions (components, downloaders, patchers, configuration managers, etc.) and ties the CLI and GUI together.

##### Parts of the File Structure
- Top-level Structure:
– “babylonia-terminal-cli”: Handles command-line interactions, argument parsing (“arguments.rs”), game logic (“game.rs”), reporting states (“reporter.rs”) and utility functions.
– “babylonia-terminal-sdk”: A modular SDK with a components folder (holding individual component downloaders for DXVK, Proton, game-specific patches) and utility modules (like GitHub requests and third-party APIs).
– “babylonia_terminal_launcher”: This directory is dedicated to the graphical launcher, containing a rich set of UI elements (screens, widgets, models, and provider modules). Note the native integration layer under “native/hub” and Linux-specific code under “linux”.
- Notice the “.github/workflows” directory for CI/CD, and build scripts like “build.sh” that indicate deployment/build integration.
- Protocol buffer (proto) files under “messages” indicate a well-structured messaging system for game state and configuration, which is an important aspect in understanding data flows.

##### Using the README for Additional Context
- The README emphasizes the launcher’s purpose: to download and install anime games with a clear separation between the CLI and GUI versions.

a. Main Components:
- CLI Frontend: The Babylonia Terminal CLI (in “babylonia-terminal-cli”) is responsible for command parsing and initiating game operations.
- Core SDK: The Babylonia Terminal SDK (in “babylonia-terminal-sdk”) provides shared logic, including component management for downloads, patching, game management, state handling, and utility functions interfacing with external APIs (e.g., GitHub, Kuro Prod API).
- Graphical Launcher (GTK Version): Within “babylonia_terminal_launcher”, include both the UI business logic (previously using Flutter/Dart, now aimed for a GTK interface in this branch) and the native hub integration from “native/hub”. Also factor in Linux-specific bindings under the “linux” directory.
- Native Integration Layer: The “native/hub” module and related Linux code compose the low-level integration between the graphical frontend and system-level operations.
- Messaging & Protocol: Represent the messaging layer (protos under “messages”) that standardizes communication among various components (CLI, SDK, Launcher, and Native integrations).

b. Relationships and Interactions:
- The CLI and GUI interact with the same backend functionality provided by the SDK.
- The launcher (now GTK based) communicates with the SDK for core operational tasks (like game downloading, patching, and dependency management).
- The native integration layer acts as a bridge for platform-specific operations (file system updates, executing native code, etc.), and it interfaces with both the launcher and the SDK.
- Protocol messages are exchanged between these layers for consistent state reporting and handling errors.

c. Architectural Patterns and Design Principles:
- Separation of Concerns: The application clearly separates CLI logic, SDK functionality, and GUI components.
- Modular Design: The SDK is organized into self-contained components which can be individually updated or replaced.
- Data Flow via Messaging: The use of proto files illustrates a message-based architecture which is ideal for decoupling systems.
- Cross-Platform Considerations: Given the presence of both CLI and GUI versions, the architecture supports adaptability for different user interfaces, which is crucial for the GTK branch update.

d. Relevant Technologies and Frameworks:
- Rust: Used for the CLI and SDK (Cargo files indicate Rust libraries).
- GTK: For this branch, the graphical launcher will now rely on GTK for building the UI.
- (Previously) Flutter/Dart code was present in “babylonia_terminal_launcher/lib”, but for the GTK branch – you may need to migrate or adapt the UI components to GTK, so highlight this change.
- External libraries like “wincompatlib” are also integrated for compatibility.

##### Additional Note for the GTK Branch
- Mention any necessary migration or integration steps needed to replace previously used Flutter components with GTK elements if the graphical launcher is in transition.

## Diagram (Mermaid)

```mermaid
graph TD
    Build["CI/CD & Build Scripts"]:::build

    subgraph "User Interfaces"
        CLI["CLI Frontend"]:::cli
        subgraph "Graphical Launcher (GTK)"
            GUI["Main Launcher"]:::gui
            UIAssets["UI Assets"]:::gui
        end
    end

    subgraph "Core Services"
        SDK["Core SDK"]:::sdk
        subgraph "Native Integration Layer"
            NI_Hub["Hub Integration"]:::native
            NI_Linux["Linux Specific Integration"]:::native
        end
        Msg["Messaging/Protocol System"]:::msg
    end

    Build -->|"builds"| CLI
    Build -->|"builds"| GUI
    Build -->|"builds"| SDK

    CLI -->|"sends_commands"| SDK
    GUI -->|"sends_UI_commands"| SDK

    SDK -->|"invokes_native"| NI_Hub
    SDK -->|"sends_protocol_messages"| Msg
    NI_Hub -->|"reports_state"| Msg
    GUI -->|"direct_native_call"| NI_Hub

    Msg -->|"feedback_to_CLI"| CLI
    Msg -->|"feedback_to_GUI"| GUI

    UIAssets --- GUI

    click CLI "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia-terminal-cli/src"
    click SDK "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia-terminal-sdk/src"
    click GUI "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia_terminal_launcher/lib"
    click UIAssets "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia_terminal_launcher/assets"
    click NI_Hub "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia_terminal_launcher/native/hub"
    click NI_Linux "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia_terminal_launcher/linux"
    click Msg "https://github.com/alez-dev/babylonia-terminal/tree/master/babylonia_terminal_launcher/messages"

    classDef cli fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef sdk fill:#99ff99,stroke:#333,stroke-width:2px;
    classDef gui fill:#99ccff,stroke:#333,stroke-width:2px;
    classDef native fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef msg fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef build fill:#cce5ff,stroke:#333,stroke-width:2px;
```
