# morizerodev/milestro architecture

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

- Interactive diagram: https://gitdiagram.com/morizerodev/milestro
- Repository: https://github.com/morizerodev/milestro

## Overview

##### Project Type and Purpose
- Milestro is an integration library for Unity that ties into Skia rendering.
- It supports multiple platforms (Windows, Android) and includes provisions for cross-compilation (evident from the cmake configurations and Android-specific instructions).
- Its primary purpose is to provide a Unity plugin that enhances game rendering capabilities using Skia.

##### Analyzing the File Structure
- Top-Level Directories:
- apps: Contains command-line applications (like the CLI tool in apps/cmd) useful for interfacing or testing.
- ext: Includes external dependencies and plugins, notably the PluginAPI with various headers exposing Unity event and graphics interfaces.
- Contains the Milestro headers that define its public API for common functions, game interfaces, ICU (for international text processing), IO, logging, and Skia integration.
- src: Implements the actual logic corresponding to the headers including game-specific implementations (e.g., skia rendering for canvas, fonts, SVG, text layout, ICU, I/O, and logging).
- tests: Contains unit/integration tests organized by module (ICU, image, readfont), which is critical to validate module components.
- cmake & gradle files: Indicate use of CMake for building the C++ backend parts, and Gradle for some parts of the build (or wrapping native libraries).

##### Key Components and Their Roles
- Frontend/CLI App (apps): A command-line interface that might be used for maintenance, testing or configuring the engine.
- Plugin API (ext/PluginAPI): A set of interfaces (for rendering, logging, etc.) that Unity interacts with, providing the hook between Unity and Milestro.
- Core Library:
- Common utilities, platform abstraction, encoding, and time functions (in include/Milestro/common and src).
- Game specific logic (in include/Milestro/game and src/game) that likely includes high-level interface functions for interacting with the Unity game loop.
- Skia integration: Provided extensively in include/Milestro/skia and src/skia. This covers Canvas, Fonts, Images, Vector graphics, SVG rendering, and text layout. These are core to the project’s mission of integrating modern rendering features into a game environment.
- ICU integration for international text (found in include/Milestro/icu and src/icu).
- IO and Logging components (organized respectively in include/Milestro/io, include/Milestro/log and their src implementations) maintain runtime diagnostics and file operations.
- Testing Suite:
- Organized tests for each main component confirming that each part behaves as expected.

##### Relationships and Interactions
- Unity Game (external consumer) ←→ PluginAPI in ext/PluginAPI:
- Unity communicates with Milestro through well-defined interfaces like IUnityGraphics and IUnityLog.
- The Command-line tool (in apps/cmd) leverages the core library to perform certain actions or tests.
- The core engine (compiled from src) ties together functionalities from:
- Skia: Rendering graphics, managing fonts, images, SVG, and text layout.
- ICU: Handling language and cultural text specifics.
- IO and Logging: Managing file I/O and diagnostics.
- Testing modules simulate or invoke various aspects of the Milestro functionalities ensuring robust integrations.

##### Architectural Patterns and Design Principles
- Modularization: The project is separated into multiple modules (game, skia, icu, io, log). This customer separation supports maintainability, testing, and potential reusability outside of Unity.
- Interface-driven design: The ext/PluginAPI exposes necessary interfaces for Unity, which decouples the implementation in the core from the way Unity interacts with it.
- Cross-platform compilation: The project employs CMake and Gradle, with specific build configurations for Windows and Android, ensuring that multiple build environments are supported.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Consumers
    UNITY["Unity Game Engine"]:::external
    CLI["CLI Tool"]:::external

    %% Milestro Core Architecture
    subgraph "Milestro Core"
        direction TB
        PLUGIN["Plugin API (Unity Interface)"]:::interface
        GAME["Game Interface Module"]:::module
        SKIA["Skia Rendering Module"]:::module
        ICU["ICU Integration Module"]:::module
        IO["IO Module"]:::module
        LOG["Logging Module"]:::module
        COMMON["Common Utilities Module"]:::module
    end

    %% Testing Suite Module
    TEST["Testing Suite"]:::module

    %% Relationships
    UNITY -->|"calls"| PLUGIN
    PLUGIN -->|"routes"| GAME
    PLUGIN -->|"routes"| SKIA
    PLUGIN -->|"routes"| ICU
    PLUGIN -->|"routes"| IO
    PLUGIN -->|"routes"| LOG
    COMMON -->|"supports"| GAME
    COMMON -->|"supports"| SKIA
    COMMON -->|"supports"| ICU
    COMMON -->|"supports"| IO
    COMMON -->|"supports"| LOG
    CLI -->|"invokes"| GAME
    TEST -->|"validates"| GAME
    TEST -->|"validates"| SKIA
    TEST -->|"validates"| ICU
    TEST -->|"validates"| IO
    TEST -->|"validates"| LOG

    %% Click Events
    click CLI "https://github.com/morizerodev/milestro/blob/master/apps/cmd/cli.cpp"
    click PLUGIN "https://github.com/morizerodev/milestro/tree/master/ext/PluginAPI"
    click GAME "https://github.com/morizerodev/milestro/tree/master/include/Milestro/game"
    click SKIA "https://github.com/morizerodev/milestro/tree/master/include/Milestro/skia"
    click ICU "https://github.com/morizerodev/milestro/tree/master/include/Milestro/icu"
    click IO "https://github.com/morizerodev/milestro/blob/master/include/Milestro/io/milestro_io.cpp"
    click LOG "https://github.com/morizerodev/milestro/tree/master/include/Milestro/log"
    click COMMON "https://github.com/morizerodev/milestro/tree/master/include/Milestro/common"
    click TEST "https://github.com/morizerodev/milestro/tree/master/tests"

    %% Styles
    classDef external fill:#FFDDCC,stroke:#333,stroke-width:2px;
    classDef interface fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef module fill:#CCCCFF,stroke:#333,stroke-width:2px;
```
