# styly-dev/styly-netsync architecture

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

- Interactive diagram: https://gitdiagram.com/styly-dev/styly-netsync
- Repository: https://github.com/styly-dev/styly-netsync

## Overview

##### Project type and purpose
- This is a full-stack network synchronization solution for Unity (STYLY) clients.
- It delivers:
- A Python-based NetSync server (handling binary-protocol events, serialization, REST bridge, CLI)
- A Unity package (C# runtime + editor scripts) that connects in-game avatars to the server over the network
- A benchmark suite (Locust load tests, Prometheus metrics, Grafana dashboards)
- Dev container and CI/CD workflows for development, testing, and release

##### File structure
- Top level:
- .devcontainer (VS Code remote dev)
- .github/workflows (CI: tests, performance, PyPI publish)
- STYLY-NetSync-Server (Python package + CLI + adapters + tests + benchmark folder)
- STYLY-NetSync-Unity (Unity project + sample scenes + “com.styly.styly-netsync” package)
- README.md, LICENSE, AGENTS.md, CLAUDE.md
- Server folder: “src/styly_netsync” modules: server.py, rest_bridge.py, nv_sync, binary_serializer, adapters, client, events
- Benchmark: locustfile.py, docker-compose.yml, client factory, metrics collector, Grafana and Prometheus config
- Unity folder:
- Assets/Samples_Dev (sample scenes, prefabs, scripts)
- Packages/com.styly.styly-netsync (Editor scripts to launch server, runtime scripts: ConnectionManager, AvatarManager, RPCManager, NetworkVariableManager, BinarySerializer wrapper, Prefabs, Utilities)

##### README
- Under construction; no explicit architecture section → rely on file layout to infer data flows

## Diagram (Mermaid)

```mermaid
graph TB

    %% Unity Client Application
    subgraph "Unity Client Application" 
        direction TB
        subgraph "Editor Extension" 
            direction TB
            StartServer["StartPythonServer.cs"]:::unity
            AddManager["AddNetSyncManager.cs"]:::unity
            NetSyncManagerEditor["NetSyncManagerEditor.cs"]:::unity
            NetSyncAvatarEditor["NetSyncAvatarEditor.cs"]:::unity
        end
        subgraph "Runtime Package"
            direction TB
            ConnectionManager["ConnectionManager.cs"]:::unity
            MessageProcessor["MessageProcessor.cs"]:::unity
            TransformSyncManager["TransformSyncManager.cs"]:::unity
            RPCManager["RPCManager.cs"]:::unity
            NetworkVariableManager["NetworkVariableManager.cs"]:::unity
            AvatarManager["AvatarManager.cs"]:::unity
            NetSyncManagerCore["NetSyncManager.cs"]:::unity
            NetSyncAvatarCore["NetSyncAvatar.cs"]:::unity
        end
        subgraph "Sample Scenes"
            direction TB
            DebugScene["Debug/"]:::unity
            Demo01Scene["Demo-01/"]:::unity
        end
    end

    %% NetSync Server
    subgraph "NetSync Server (Python)" 
        direction TB
        subgraph "CLI / Driver"
            direction TB
            MainPy["__main__.py"]:::python
            CLIpy["cli.py"]:::python
        end
        subgraph "Protocol Layer"
            direction TB
            BinarySerializer["binary_serializer.py"]:::python
            NetworkUtils["network_utils.py"]:::python
            NvSync["nv_sync.py"]:::python
        end
        RESTBridge["rest_bridge.py"]:::python
        Adapters["adapters.py"]:::python
        EventsDef["events.py"]:::python
        ServerCore["server.py"]:::python
        TestSuite["tests/"]:::python
    end

    %% Benchmark & Monitoring
    subgraph "Benchmark Suite" 
        direction TB
        LoadGen["locustfile.py"]:::benchmark
        subgraph "Client Factory"
            direction TB
            NetsyncClient["netsync_manager_client.py"]:::benchmark
            StylyClient["styly_client.py"]:::benchmark
        end
        MetricsCollector["metrics_collector.py"]:::benchmark
    end

    subgraph "Monitoring"
        direction TB
        Prometheus["prometheus.yml"]:::benchmark
        Grafana["grafana/"]:::benchmark
    end

    %% Dev & CI/CD
    subgraph "Development & CI/CD" 
        direction TB
        DevContainer[".devcontainer/"]:::dev
        CIWorkflow[".github/workflows/"]:::dev
    end

    %% Connections
    DebugScene -->|uses| ConnectionManager
    Demo01Scene -->|uses| ConnectionManager
    ConnectionManager -->|sends/receives| BinarySerializer
    MessageProcessor -->|processes| BinarySerializer
    TransformSyncManager -->|syncs transforms| BinarySerializer
    RPCManager -->|invokes| BinarySerializer
    NetworkVariableManager -->|syncs vars| NvSync
    AvatarManager -->|manages avatars| BinarySerializer

    ConnectionManager -->|connects to| ServerCore
    ServerCore -->|serializes| BinarySerializer
    ServerCore -->|uses| NetworkUtils
    ServerCore -->|handles NV sync| NvSync
    ServerCore -->|routes events| Adapters
    Adapters -->|defines events| EventsDef
    RESTBridge -->|exposes REST| ServerCore
    MainPy -->|launches| ServerCore
    CLIpy -->|provides CLI| ServerCore
    TestSuite -->|tests| ServerCore

    LoadGen -->|load tests| ServerCore
    NetsyncClient -->|factory| LoadGen
    StylyClient -->|factory| LoadGen
    MetricsCollector -->|collects| ServerCore
    ServerCore -->|exposes metrics| Prometheus
    Prometheus -->|visualizes| Grafana

    StartServer -->|spawns| MainPy
    CIWorkflow -->|runs tests| TestSuite
    CIWorkflow -->|builds| NetSyncManagerCore
    CIWorkflow -->|publishes| CLIpy
    DevContainer -->|provides env| StartServer
    DevContainer -->|provides env| MainPy

    %% Click Events
    click DevContainer "https://github.com/styly-dev/styly-netsync/tree/develop/.devcontainer/"
    click CIWorkflow "https://github.com/styly-dev/styly-netsync/tree/develop/.github/workflows/"
    click MainPy "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/__main__.py"
    click CLIpy "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/cli.py"
    click ServerCore "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/server.py"
    click BinarySerializer "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/binary_serializer.py"
    click NetworkUtils "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/network_utils.py"
    click NvSync "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/nv_sync.py"
    click RESTBridge "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/rest_bridge.py"
    click Adapters "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/adapters.py"
    click EventsDef "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/src/styly_netsync/events.py"
    click TestSuite "https://github.com/styly-dev/styly-netsync/tree/develop/STYLY-NetSync-Server/tests/"
    click LoadGen "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/benchmark/locustfile.py"
    click NetsyncClient "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/benchmark/src/clients/netsync_manager_client.py"
    click StylyClient "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/benchmark/src/clients/styly_client.py"
    click MetricsCollector "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/benchmark/src/metrics_collector.py"
    click Prometheus "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Server/benchmark/visualizer/prometheus.yml"
    click Grafana "https://github.com/styly-dev/styly-netsync/tree/develop/STYLY-NetSync-Server/benchmark/visualizer/grafana/"
    click StartServer "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Editor/StartPythonServer.cs"
    click AddManager "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Editor/AddNetSyncManager.cs"
    click NetSyncManagerEditor "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Editor/NetSyncManagerEditor.cs"
    click NetSyncAvatarEditor "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Editor/NetSyncAvatarEditor.cs"
    click ConnectionManager "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/Internal Scripts/ConnectionManager.cs"
    click MessageProcessor "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/Internal Scripts/MessageProcessor.cs"
    click TransformSyncManager "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/Internal Scripts/TransformSyncManager.cs"
    click RPCManager "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/Internal Scripts/RPCManager.cs"
    click NetworkVariableManager "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/Internal Scripts/NetworkVariableManager.cs"
    click AvatarManager "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/Internal Scripts/AvatarManager.cs"
    click NetSyncManagerCore "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/NetSyncManager.cs"
    click NetSyncAvatarCore "https://github.com/styly-dev/styly-netsync/blob/develop/STYLY-NetSync-Unity/Packages/com.styly.styly-netsync/Runtime/NetSyncAvatar.cs"

    %% Styles
    classDef unity fill:#D0E8FF,stroke:#004080,color:#004080
    classDef python fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32
    classDef benchmark fill:#FFF3E0,stroke:#EF6C00,color:#EF6C00
    classDef dev fill:#F5F5F5,stroke:#616161,color:#616161
```
