# kidagine/darklings-fightinggame architecture

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

- Interactive diagram: https://gitdiagram.com/kidagine/darklings-fightinggame
- Repository: https://github.com/kidagine/darklings-fightinggame

## Overview

##### Project type and purpose
- This is a Unity 2D fighting game (“Darklings”) built with Unity 2021.3.24.
- It uses deterministic physics/animations, a rollback netcode (GGPO), replay/video streaming, UI/dialogue systems, AI opponents, and local/online multiplayer.

##### Top-level structure overview
- Root:
– Assets/ (game assets, code, plugins)
– Packages/ (manifest.json)
– ProjectSettings/ (Unity project config)
- Major subfolders under Assets/:
– _Project/… → all game-specific Scenes, Scripts, Prefabs, ScriptableObjects, Materials, Shaders, Sounds, UI, Simulation and Network code
– Plugins/ → third-party tools (ParrelSync for local testing, Sirenix Odin Inspector, Sprite Shaders Ultimate, jsLibrary)
– PlayFabEditorExtensions/ & PlayFabSDK/ → PlayFab integration for cloud data
– Pixel Arsenal/ → visual effect asset pack
– TextMesh Pro/, UIElementsSchema/, WebGLTemplates/ → UI and WebGL support

##### Key technology & patterns
- Unity Engine (URP) drives rendering, audio, input
- Deterministic simulation tick at 60 FPS (SimulationScripts)
- State machine pattern for character/game states (SimulationScripts/StateScripts)
- Rollback netcode using GGPO integration under NetworkScripts + STUN for NAT traversal
- ScriptableObject-based data (SciptableObjects) for easy tuning
- Editor-only tools: ParrelSync for multi-instance testing, Odin Inspector for better editor UI, PlayFabEditorExtensions

##### Components
A. Unity Editor & Build Pipeline
– Assets import & Asset Bundle builder
– Code compilation via asmdef files
– Continuous Integration (GitHub Actions activation.yml)
B. Runtime Game Client (Unity Player)
1. Input Layer
- Unity Input System → InputManager, NetworkInput
- ParrelSync (editor only) for multi-instance
2. Simulation & Physics
- Deterministic Physics (Physics2DSettings)
- SimulationScripts (GameSimulation, StateSimulation)
- Frame-locked tick at 60 FPS
3. State Machine & Rollback
- StateScripts for gameplay states
- GGPO netcode (GGPORunner, GGPOSession) + STUN client for NAT traversal
- Rollback buffer & InputBufferNetwork
4. Rendering & Audio
- URP rendering pipeline (URPProjectSettings)
- Sprite/Shaders (Sprite Shaders Ultimate, Pixel Arsenal)
- Audio mixer (AudioManager.asset) → SoundManager
5. UI & Video
- TextMeshPro UI, Canvas prefabs, DialogueSystem
- Streaming Video subsystem for command videos & replays
6. Game Services
- PlayFab SDK (Client, Data, Authentication) for analytics/leaderboards
C. External Services & Tools
– PlayFab cloud services
– Clumsy (optional network lag simulation)
– ParrelSync (local testing)
– GitHub (source, CI/CD)

##### Relationships & data flows
- Input → Simulation core → State changes → Renderer/Audio/UI
- Input & simulation states → Network layer (GGPO) ↔ peer client
- Simulation states → Replay recording & Video streaming
- ScriptableObjects → Simulation & UI for configuration
- PlayFab SDK ↔ PlayFab cloud for persistent data

##### Architectural patterns & principles
- Deterministic lockstep simulation + rollback => resilient netcode
- Separation of concerns: Input, Simulation, State Machine, Rendering, Audio, UI
- Data-driven design via ScriptableObjects & asmdef modularity
- Plugin-based extensibility (Odin Inspector, Sprite Shaders)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Unity Editor & Build Pipeline"
        CI["GitHub Actions CI"]:::external
        Manifest["manifest.json"]:::data
        Asmdef["Assembly Definitions"]:::data
    end

    subgraph "Runtime Game Client"
        subgraph "Input Layer"
            DemonInput["DemonInput.inputactions & DemonInput.cs"]:::core
            InputMgr["InputManager"]:::core
            NetworkInput["NetworkInput"]:::core
        end

        subgraph "Simulation & Physics"
            PhysSettings["Physics2DSettings.asset"]:::data
            GameSim["GameSimulation"]:::core
            SimMgr["SimulationManager"]:::core
        end

        subgraph "State Machine & Rollback"
            StateScripts["StateScripts"]:::core
            InputBufferNet["InputBufferNetwork"]:::core
            GGPORunner["GGPORunner"]:::core
            GGPOSession["GGPOSession"]:::core
            STUNClient["STUNClient"]:::core
        end

        subgraph "Rendering & Audio"
            URPSettings["URPProjectSettings.asset"]:::data
            SpriteShaders["Sprite Shaders & VFX"]:::external
            PixelArsenal["Pixel Arsenal"]:::external
            AudioMixer["MainAudioMixer_SND.mixer"]:::data
            SoundMgr["SoundManager"]:::core
        end

        subgraph "UI & Video"
            TextMesh["TextMeshPro"]:::external
            DialogueSO["DialogueScriptableObjects"]:::data
            UIScripts["UI Scripts & Prefabs"]:::core
            ReplayMgr["ReplayManager"]:::core
            Videos["Video Assets"]:::external
        end

        subgraph "Game Services"
            PlayFabClient["PlayFabClientAPI"]:::external
            PlayFabEditor["PlayFabEditor"]:::editor
            PlayFabCloud["PlayFab Cloud Services"]:::external
        end
    end

    subgraph "External Tools & Services"
        Clumsy["Clumsy"]:::external
        ParrelSync["ParrelSync"]:::editor
        Odin["Odin Inspector"]:::editor
        jsLibrary["jsLibrary"]:::editor
        GitHub["GitHub"]:::external
    end

    %% Connections
    DemonInput -->|"input"| SimMgr
    InputMgr -->|"input"| SimMgr
    NetworkInput -->|"network input"| StateScripts

    SimMgr -->|"updates at 60 FPS"| GameSim
    SimMgr -->|"manages simulation"| StateScripts
    SimMgr -->|"sends state"| ReplayMgr
    SimMgr -->|"renders via"| SpriteShaders
    SimMgr -->|"renders via"| PixelArsenal
    SimMgr -->|"audio events to"| SoundMgr

    StateScripts -->|"state data"| GGPORunner
    GGPORunner -->|"rollback sync"| StateScripts
    GGPORunner -->|"session run"| GGPOSession
    GGPOSession -->|"peer session"| GGPORunner
    StateScripts -->|"network buffer"| InputBufferNet
    StateScripts -->|"STUN queries"| STUNClient

    StateScripts -->|"state for UI"| UIScripts
    ReplayMgr -->|"video frames"| Videos

    UIScripts -->|"API calls"| PlayFabClient
    PlayFabClient -->|"cloud data"| PlayFabCloud
    PlayFabCloud -->|"responses"| PlayFabClient

    CI --> Manifest
    CI --> Asmdef
    GitHub --> CI

    ParrelSync -.-> DemonInput
    Odin -.-> InputMgr
    jsLibrary -.-> TextMesh
    Clumsy -.-> NetworkInput

    %% Click Events
    click CI "https://github.com/kidagine/darklings-fightinggame/blob/development/.github/workflows/activation.yml"
    click Manifest "https://github.com/kidagine/darklings-fightinggame/blob/development/Packages/manifest.json"
    click Asmdef "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/Scripts.asmdef"

    click DemonInput "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Inputs/DemonInput.inputactions"
    click InputMgr "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/ManagerScripts/InputManager.cs"
    click NetworkInput "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/NetworkScripts/NetworkInput.cs"

    click PhysSettings "https://github.com/kidagine/darklings-fightinggame/blob/development/ProjectSettings/Physics2DSettings.asset"
    click GameSim "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/SimulationScripts/GameSimulation.cs"
    click SimMgr "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/SimulationScripts/SimulationManager.cs"

    click InputBufferNet "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/SimulationScripts/StateScripts/NetworksScripts/InputBufferNetwork.cs"
    click GGPORunner "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/NetworkScripts/GGPORunner.cs"
    click GGPOSession "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/NetworkScripts/GGPOSession.cs"
    click STUNClient "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/NetworkScripts/Stun/STUNClient.cs"

    click URPSettings "https://github.com/kidagine/darklings-fightinggame/blob/development/ProjectSettings/URPProjectSettings.asset"
    click SoundMgr "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/ManagerScripts/SoundManager.cs"

    click DialogueSO "https://github.com/kidagine/darklings-fightinggame/tree/development/Assets/_Project/SciptableObjects/CharacterScriptableObjects/DialogueScriptableObjects/"
    click UIScripts "https://github.com/kidagine/darklings-fightinggame/tree/development/Assets/_Project/Scripts/UIScripts/"
    click ReplayMgr "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/_Project/Scripts/ManagerScripts/ReplayManager.cs"
    click Videos "https://github.com/kidagine/darklings-fightinggame/tree/development/Assets/_Project/Videos/"

    click PlayFabClient "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/PlayFabSDK/Client/PlayFabClientAPI.cs"
    click PlayFabEditor "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/PlayFabEditorExtensions/Editor/PlayFabEditor.cs"

    click ParrelSync "https://github.com/kidagine/darklings-fightinggame/tree/development/Assets/Plugins/ParrelSync/ParrelSync/"
    click Odin "https://github.com/kidagine/darklings-fightinggame/tree/development/Assets/Plugins/Sirenix/Odin Inspector/"
    click jsLibrary "https://github.com/kidagine/darklings-fightinggame/blob/development/Assets/Plugins/jsLibrary.jslib"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000
    classDef external fill:#90EE90,stroke:#000
    classDef data fill:#FFA500,stroke:#000
    classDef editor stroke-dasharray: 5 5,stroke:#000
```
