# davide-perli/nysodi architecture

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

- Interactive diagram: https://gitdiagram.com/davide-perli/nysodi
- Repository: https://github.com/davide-perli/nysodi

## Overview

##### Project Type and Purpose
-  Type: Multi-crate Rust workspace for a single-player 2D game.
-  Purpose:
- Editor (scene creation & live preview)
- Executors (runtimes for desktop, WebAssembly, Android)
- Game logic as a dynamically loaded plugin
- Shared asset pipeline

##### Break Down the File Structure into Architectural Components
Top-level crates under `nysodi/`:
- editor – Binary GUI app for building and previewing levels
- executor – Desktop runtime binary
- executor-wasm – WebAssembly runtime (browser)
- executor-android – Android runtime library
- game-dylib – cdylib plugin crate that exports game logic hooks
- game – Core game logic (entities, systems) as an ordinary Rust library
- data – Asset folder (scenes, sprites, tilesets, configs)

##### Main Components
A. Fyrox Engine (shared across editor & executors)
B. Editor App
– Loads assets (scene RGS, sprites, tiles)
– Loads the game logic plugin (game-dylib) for live preview
C. Executors (3 variants)
– Desktop executor binary
– WebAssembly executor (main.js + WASM)
– Android executor library (APK integration)
All three load assets + game logic plugin
D. Game Logic Plugin
– game-dylib (compiled as cdylib)
– Depends on `game` crate for bot/player logic, health, items
E. Asset Pipeline
– `nysodi/data/` folder containing all imagery, RGS scenes, configs

##### Relationships & Data Flow
1. Editor/Executor → Fyrox Engine
- Calls core rendering, input, scripting APIs
2. Editor/Executor → Asset Loader
- Loads `.rgs` scene files, sprite PNGs, tilesets, fonts
3. Editor/Executor → Game Logic Plugin
- Loads cdylib at runtime
- Invokes plugin’s lifecycle hooks (`on_init`, `on_update`)
4. Game Logic Plugin → `game` crate
- Executes entity logic (spawn bots, handle health, power-ups)
5. Executors (WASM / Android) → Platform Host
- WASM: Browser WebGL context + JS glue (`main.js`)
- Android: JNI bridge + keystore integration

##### Key Architectural Patterns & Principles
- Plugin Architecture: game logic lives in a dynamically loaded cdylib
- Multi-target Builds: single code-base with platform-specific executors
- Separation of Concerns:
- Editor vs. Runtime vs. Game Logic vs. Assets
- Data-driven Scenes: RGS scene files drive level structure

##### Technologies, Frameworks & Formats
- Language: Rust (stable)
- Engine: Fyrox (2D game engine)
- Build System: Cargo workspace with multiple Cargo.toml files
- Plugin Format: cdylib for desktop, wasm32-unknown-unknown, JNI for Android
- Asset Formats: `.rgs` (scenes), PNG (sprites), `.tileset`, `.ron` (settings)

- Fyrox Engine
- Editor App
- Executor-Desktop, Executor-WASM, Executor-Android
- Game Logic Plugin (game-dylib)
- Core Game Logic (game crate)
- Asset Store (data/)
- Platform Hosts (Browser, Android OS)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Development & Editor"
        EditorApp["Editor App"]:::engine
    end

    subgraph "Runtimes"
        ExecutorDesktop["Executor-Desktop"]:::engine
        ExecutorWASM["Executor-WASM"]:::engine
        ExecutorAndroid["Executor-Android"]:::engine
    end

    FyroxEngine["Fyrox Engine"]:::engine
    AssetStore["Asset Store (nysodi/data/)"]:::assets
    GameLogicPlugin["Game Logic Plugin (cdylib)"]:::game
    CoreGame["Core Game Logic (game crate)"]:::game

    subgraph "Platform Hosts"
        Browser["Browser Host"]:::platform
        AndroidOS["Android OS Host"]:::platform
    end

    EditorApp -->|"calls rendering/input"| FyroxEngine
    ExecutorDesktop -->|"calls rendering/input"| FyroxEngine
    ExecutorWASM -->|"calls rendering/input"| FyroxEngine
    ExecutorAndroid -->|"calls rendering/input"| FyroxEngine

    EditorApp -->|"load_scene(), load_assets"| AssetStore
    ExecutorDesktop -->|"load_scene(), load_assets"| AssetStore
    ExecutorWASM -->|"load_scene(), load_assets"| AssetStore
    ExecutorAndroid -->|"load_scene(), load_assets"| AssetStore

    EditorApp -->|"load_plugin()"| GameLogicPlugin
    ExecutorDesktop -->|"load_plugin()"| GameLogicPlugin
    ExecutorWASM -->|"load_plugin()"| GameLogicPlugin
    ExecutorAndroid -->|"load_plugin()"| GameLogicPlugin

    GameLogicPlugin -->|"invoke_on_init(), on_update()"| CoreGame

    ExecutorWASM -->|"WebGL, JS glue (main.js)"| Browser
    ExecutorAndroid -->|"JNI bridge"| AndroidOS

    click EditorApp "https://github.com/davide-perli/nysodi/tree/main/nysodi/editor/"
    click ExecutorDesktop "https://github.com/davide-perli/nysodi/tree/main/nysodi/executor/"
    click ExecutorWASM "https://github.com/davide-perli/nysodi/tree/main/nysodi/executor-wasm/"
    click ExecutorAndroid "https://github.com/davide-perli/nysodi/tree/main/nysodi/executor-android/"
    click GameLogicPlugin "https://github.com/davide-perli/nysodi/tree/main/nysodi/game-dylib/"
    click CoreGame "https://github.com/davide-perli/nysodi/tree/main/nysodi/game/"
    click AssetStore "https://github.com/davide-perli/nysodi/tree/main/nysodi/data/"

    classDef engine fill:#cce5ff,stroke:#004085
    classDef game fill:#d4edda,stroke:#155724
    classDef assets fill:#fff3cd,stroke:#856404
    classDef platform fill:#e2dfff,stroke:#4b0082
```
