# burnemdown/unitycorekit architecture

> Architecture diagram of the GitHub repository burnemdown/unitycorekit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/burnemdown/unitycorekit
- Repository: https://github.com/burnemdown/unitycorekit

## Overview

1. **Repository role and boundary**
   UnityCoreKit is not an application; it is a reusable Unity library meant to be embedded as a Git submodule inside a host game project. The architecture is therefore a set of runtime services, utilities, and editor helpers that the consuming game wires together.

2. **Top-level split: runtime vs editor**
   The codebase is cleanly separated into `Runtime/` and `Editor/` assemblies. Runtime contains all game-facing systems; Editor contains Unity editor tooling such as custom inspectors and helpers. This split is enforced with `.asmdef` files so runtime code does not depend on `UnityEditor`.

3. **Bootstrap and composition root**
   `Runtime/Bootstrap/Loader.cs` is the expected entry point in the host project. It acts as the composition root: it creates the persistent bootstrap object, registers concrete service implementations, and wires the subsystem graph together. Most systems are consumed through interfaces, so the loader decides which implementations are active.

4. **Central service registry**
   `Core.Services.CoreServices` is the main service locator/registry. It provides lazy registration and resolution of interfaces such as audio, analytics, save, scene loading, networking, remote config, time, events, factories, pooling, and localization. This is the central architectural boundary: gameplay code depends on interfaces, while the loader injects implementations.

5. **Interfaces-first core contract**
   The `Runtime/Core/Interfaces/` folder defines the stable API surface for the whole package. These interfaces are what the host game should target. The concrete services live elsewhere, making it easy to swap stubs for production systems without changing consuming code.

6. **Default, stub, and optional production services**
   There are three main service families:
   - `DefaultServices/` for functional Unity-backed implementations like time, scene loading, JSON save, and basic network support.
   - `StubServices/` for no-op or logging implementations of audio, localization, analytics, crash reporting, and remote config.
   - `DefaultServices/Firebase/` for optional Firebase-backed analytics, crash reporting, and remote config.
   This indicates a “safe-by-default” design: the library works without external backend SDKs, but can override stubs when Firebase is available.

7. **Object creation and pooling pipeline**
   Object creation is abstracted through `IObjectFactory` and then reused by `PoolManager`. Factory implementations include:
   - `AddressablesFactory` for Addressables-based asset loading/instantiation
   - `PrefabFactory` for direct prefab-map instantiation
   - `CompositeFactory` to choose between them
   The flow is: resolve factory by key → create object asynchronously → optionally route through pooling. This is the main content-loading and reuse path in the package.

8. **Event-driven messaging subsystem**
   `Core.Events` provides a lightweight event bus via `IEventsManager`, with `EventType` and listener metadata. `EventListenerManager` tracks subscriptions and helps with cleanup. The design is central-dictionary based and supports safe listener changes while events are being processed. This is the primary internal messaging boundary between systems.

9. **User interaction as a higher-level layer**
   `Runtime/UserInteractions/` sits above the generic event system. It translates Unity input/pointer behavior into semantic interaction events, using `UserInteractionsService` and Unity source adapters like `PointerClickUserInteractionSource`. This module depends on `Core.Events`, but not vice versa, so the dependency direction is one-way: raw input becomes domain-level interaction events.

10. **Update loop management**
    `UpdateManager`, `FixedUpdateManager`, and `LateUpdateManager` centralize per-frame observer dispatch. Systems implement observer interfaces and register with the relevant manager instead of each component owning its own Unity update method. This creates a controllable and inspectable update boundary, useful for ordering and throttling.

11. **Async, threading, and Unity main-thread safety**
    `MainThreadDispatcher` is a runtime utility that queues actions onto Unity’s main thread. `TaskExtensions` build on that to allow async continuations to safely touch Unity objects. This is an important infrastructure boundary because several systems—factories, loading, and service initialization—can run asynchronously but must re-enter the main thread for Unity API calls.

12. **Persistence and data storage**
    `JsonFileSaveSystem` implements `ISaveSystem` using JSON files stored under `Application.persistentDataPath`, with Newtonsoft Json as the serialization dependency. Saves are slot-based and version-aware, which makes the save system a separate persistence boundary rather than an in-memory cache.

13. **Utility layer**
    `Core/Utils/` contains shared infrastructure that many subsystems depend on: logging, prefab and dictionary helpers, layer attributes, JSON object helpers, and game-object extensions. `Logger` centralizes debug output and is compiled conditionally, so logging can be disabled globally in production builds.

14. **Editor tooling**
    The `Editor/` folder contains support tools for the Unity editor only, such as custom drawers and inspector locking/opening utilities. These do not participate in runtime data flow, but they support authoring and debugging of the runtime systems.

15. **External dependencies that affect architecture**
    The package materially depends on Unity Addressables for asset loading and Newtonsoft Json for save serialization. Firebase is optional and isolated behind compile-time/runtime checks. This means the core architecture is designed to function without backend services, while still allowing production integrations to be swapped in through the same interface layer.

Main entry points: [`Runtime/Bootstrap/Loader.cs`](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Bootstrap/Loader.cs) (Loader), [`Runtime/Core/Services/CoreServices.cs`](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/CoreServices.cs) (Core Services), [`Runtime/Core/DefaultServices/DefaultSceneLoader.cs`](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/DefaultSceneLoader.cs) (Default Services), [`Runtime/Core/Services/CompositeFactory.cs`](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/CompositeFactory.cs) (Factory Pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime_core["Runtime Core"]
  node_loader["Loader<br/>bootstrap root<br/>[Loader.cs]"]
  node_core_services["Core Services<br/>service registry<br/>[CoreServices.cs]"]
  node_contracts["Contracts<br/>interfaces<br/>[IServices.cs]"]
  node_default_services["Default Services<br/>unity-backed impls"]
  node_stub_services["Stub Services<br/>no-op impls"]
  node_firebase_services["Firebase Services<br/>optional backend"]
  node_events_contracts["Event API<br/>event contracts<br/>[EventType.cs]"]
  node_events_manager(("Events Manager<br/>event bus<br/>[EventsManager.cs]"))
  node_factory_pipeline["Factory Pipeline<br/>object creation"]
  node_pool_manager["Pool Manager<br/>object pooling<br/>[PoolManager.cs]"]
  node_update_managers["Update Managers<br/>frame dispatch<br/>[UpdateManager.cs]"]
  node_main_thread(("Main Thread<br/>async bridge"))
  node_persistence[("Save System<br/>json persistence")]
  node_utils["Utils<br/>shared helpers<br/>[Logger.cs]"]
end

subgraph group_user_interactions["User Interactions"]
  node_user_api["Interaction API<br/>interaction contracts"]
  node_user_service["Interaction Service"]
  node_pointer_source["Pointer Source<br/>unity input adapter"]
end

subgraph group_editor["Editor"]
  node_editor_tools["Editor Tools<br/>unity editor<br/>[OpenLoaderTool.cs]"]
end

node_loader -->|"compose"| node_core_services
node_loader -->|"register"| node_default_services
node_loader -->|"fallbacks"| node_stub_services
node_loader -.->|"optional"| node_firebase_services
node_loader -->|"wire"| node_events_manager
node_loader -->|"wire"| node_factory_pipeline
node_loader -->|"wire"| node_pool_manager
node_loader -->|"wire"| node_update_managers
node_loader -->|"wire"| node_persistence
node_core_services -->|"resolves"| node_contracts
node_core_services -->|"hosts"| node_events_manager
node_core_services -->|"hosts"| node_factory_pipeline
node_core_services -->|"hosts"| node_pool_manager
node_core_services -->|"hosts"| node_persistence
node_core_services -->|"binds"| node_default_services
node_core_services -->|"binds"| node_stub_services
node_core_services -.->|"overrides"| node_firebase_services
node_events_manager -->|"uses"| node_events_contracts
node_user_service -->|"emits"| node_user_api
node_pointer_source -->|"feeds"| node_user_service
node_user_service -->|"publishes"| node_events_manager
node_factory_pipeline -->|"syncs"| node_main_thread
node_factory_pipeline -->|"uses"| node_utils
node_pool_manager -->|"wraps"| node_factory_pipeline
node_update_managers -->|"uses"| node_utils
node_default_services -->|"uses"| node_main_thread
node_default_services -->|"uses"| node_utils
node_firebase_services -.->|"extends"| node_default_services
node_editor_tools -->|"supports"| node_loader
node_editor_tools -->|"supports"| node_contracts

click node_loader "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Bootstrap/Loader.cs"
click node_core_services "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/CoreServices.cs"
click node_contracts "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Interfaces/IServices.cs"
click node_default_services "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/DefaultSceneLoader.cs"
click node_stub_services "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/StubServices/StubAudioManager.cs"
click node_firebase_services "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/Firebase/FirebaseInitializer.cs"
click node_events_contracts "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Events/EventType.cs"
click node_events_manager "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/EventsManager.cs"
click node_factory_pipeline "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/CompositeFactory.cs"
click node_pool_manager "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/PoolManager.cs"
click node_update_managers "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/UpdateManagers/UpdateManager.cs"
click node_main_thread "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Utils/MainThreadDispatcher.cs"
click node_persistence "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/JsonFileSaveSystem.cs"
click node_utils "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Utils/Logs/Logger.cs"
click node_user_api "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/UserInteractions/IUserInteractions.cs"
click node_user_service "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/UserInteractions/Services/UserInteractionsService.cs"
click node_pointer_source "https://github.com/burnemdown/unitycorekit/blob/master/Runtime/UserInteractions/Unity/PointerClickUserInteractionSource.cs"
click node_editor_tools "https://github.com/burnemdown/unitycorekit/blob/master/Editor/OpenLoaderTool.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_loader,node_core_services,node_contracts,node_default_services,node_stub_services,node_firebase_services,node_events_contracts,node_events_manager,node_factory_pipeline,node_pool_manager,node_update_managers,node_main_thread,node_persistence,node_utils toneBlue
class node_user_api,node_user_service,node_pointer_source toneAmber
class node_editor_tools toneMint
```

## Components

### Runtime Core

Runtime services, contracts, and infrastructure

- [Loader](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Bootstrap/Loader.cs): bootstrap root · Entry point that composes and registers runtime services · `Runtime/Bootstrap/Loader.cs`
- [Core Services](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/CoreServices.cs): service registry · Central lazy registry and resolver for runtime services · `Runtime/Core/Services/CoreServices.cs`
- [Contracts](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Interfaces/IServices.cs): interfaces · Stable service interfaces consumed by host gameplay code · `Runtime/Core/Interfaces/IServices.cs`
- [Default Services](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/DefaultSceneLoader.cs): unity-backed impls · Core runtime implementations such as time, scene loading, and networking · `Runtime/Core/DefaultServices/DefaultSceneLoader.cs`
- [Stub Services](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/StubServices/StubAudioManager.cs): no-op impls · Safe default implementations for optional services · `Runtime/Core/StubServices/StubAudioManager.cs`
- [Firebase Services](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/Firebase/FirebaseInitializer.cs): optional backend · Firebase-backed analytics, crash reporting, and remote config · `Runtime/Core/DefaultServices/Firebase/FirebaseInitializer.cs`
- [Event API](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Events/EventType.cs): event contracts · Event types and listener metadata shared across systems · `Runtime/Core/Events/EventType.cs`
- [Events Manager](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/EventsManager.cs): event bus · Central event dispatch and listener management · `Runtime/Core/Services/EventsManager.cs`
- [Factory Pipeline](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/CompositeFactory.cs): object creation · Factory selection and object creation abstraction · `Runtime/Core/Services/CompositeFactory.cs`
- [Pool Manager](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Services/PoolManager.cs): object pooling · Reuses created objects through pooling · `Runtime/Core/Services/PoolManager.cs`
- [Update Managers](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/UpdateManagers/UpdateManager.cs): frame dispatch · Centralized Update, FixedUpdate, and LateUpdate observer dispatch · `Runtime/Core/UpdateManagers/UpdateManager.cs`
- [Main Thread](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Utils/MainThreadDispatcher.cs): async bridge · Queues work back onto Unity's main thread · `Runtime/Core/Utils/MainThreadDispatcher.cs`
- [Save System](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/DefaultServices/JsonFileSaveSystem.cs): json persistence · Slot-based JSON file save/load under persistent data path · `Runtime/Core/DefaultServices/JsonFileSaveSystem.cs`
- [Utils](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/Core/Utils/Logs/Logger.cs): shared helpers · Cross-cutting helpers for logging, JSON, prefabs, and tasks · `Runtime/Core/Utils/Logs/Logger.cs`

### User Interactions

Input-to-domain interaction layer

- [Interaction API](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/UserInteractions/IUserInteractions.cs): interaction contracts · User interaction abstractions and event types · `Runtime/UserInteractions/IUserInteractions.cs`
- [Interaction Service](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/UserInteractions/Services/UserInteractionsService.cs): interaction service · Maps input source behavior into semantic interaction events · `Runtime/UserInteractions/Services/UserInteractionsService.cs`
- [Pointer Source](https://github.com/burnemdown/unitycorekit/blob/master/Runtime/UserInteractions/Unity/PointerClickUserInteractionSource.cs): unity input adapter · Unity pointer-click adapter feeding the interaction layer · `Runtime/UserInteractions/Unity/PointerClickUserInteractionSource.cs`

### Editor

Unity editor-only tooling

- [Editor Tools](https://github.com/burnemdown/unitycorekit/blob/master/Editor/OpenLoaderTool.cs): unity editor · Editor-only drawers and loader utilities · `Editor/OpenLoaderTool.cs`

## Connections

- Loader → Core Services: compose · Bootstraps and wires the central service registry
- Loader → Default Services: register · Installs runtime implementations into the service graph
- Loader → Stub Services: fallbacks · Uses stubs for optional services when no backend is present
- Loader → Firebase Services: optional · Enables Firebase-backed implementations when available
- Loader → Events Manager: wire · Initializes the event subsystem early in startup
- Loader → Factory Pipeline: wire · Connects object creation implementations
- Loader → Pool Manager: wire · Registers pooling alongside factories
- Loader → Update Managers: wire · Sets up frame-driven observer dispatch
- Loader → Save System: wire · Makes save/load available through services
- Core Services → Contracts: resolves · Provides interface-first access to runtime systems
- Core Services → Events Manager: hosts · Owns the event bus as a core service
- Core Services → Factory Pipeline: hosts · Exposes factory selection and creation
- Core Services → Pool Manager: hosts · Exposes object pooling as a shared service
- Core Services → Save System: hosts · Registers the save system implementation
- Core Services → Default Services: binds · Maps service interfaces to default Unity-backed implementations
- Core Services → Stub Services: binds · Maps optional interfaces to safe defaults
- Core Services → Firebase Services: overrides · Can replace stubs with Firebase-backed services
- Events Manager → Event API: uses · Dispatches typed events and listener metadata
- Interaction Service → Interaction API: emits · Produces semantic user interaction events
- Pointer Source → Interaction Service: feeds · Turns Unity pointer clicks into interaction requests
- Interaction Service → Events Manager: publishes · Uses the event bus to broadcast interactions
- Factory Pipeline → Main Thread: syncs · Re-enters Unity main thread for object creation work
- Factory Pipeline → Utils: uses · Relies on shared helpers and logging support
- Pool Manager → Factory Pipeline: wraps · Pools objects created by the factory layer
- Update Managers → Utils: uses · Shares logging and extension helpers
- Default Services → Main Thread: uses · Re-enters Unity safely after async work
- Default Services → Utils: uses · Depends on shared runtime utilities
- Firebase Services → Default Services: extends · Optional backend services sit beside the default implementations
- Editor Tools → Loader: supports · Editor helpers help open and inspect the runtime bootstrap
- Editor Tools → Contracts: supports · Editor tooling assists authoring against runtime contracts
