# thammin/unity-spring architecture

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

- Interactive diagram: https://gitdiagram.com/thammin/unity-spring
- Repository: https://github.com/thammin/unity-spring

## Overview

##### Project Type and Purpose
- This is an open-source Unity package: “A minimal spring physics library for Unity.”
- It implements multiple solvers for a damped harmonic oscillator (Closed-form, Semi-implicit Euler, RK4, Verlet).
- It ships as two assemblies: a Runtime DLL for the solvers and an Editor DLL for the visualizer, plus an automated test suite.

##### File Structure Analysis
- Top-level: LICENSE.md, README.md, package.json (Unity package manifest).
- Runtime/
- Thammin.UnitySpring.asmdef – Unity assembly definition for runtime code
- SpringBase.cs – base class defining the solver interface
- ClosedForm.cs, SemiImplicitEuler.cs, ExplicitRK4.cs, VerletIntegration.cs – concrete solver implementations
- Editor/
- Thammin.UnitySpring.Editor.asmdef – Editor-only assembly
- Visualizer.cs – MonoBehaviour that uses the solvers to render an animated spring in the Editor
- Tests/Editor/
- Thammin.UnitySpring.Tests.asmdef – Editor test assembly
- PerformanceTest.cs – measures solver performance
- Documentation~/ – supporting images and performance graphs

##### Key Insights from README
- Core functionality: simple C# classes with Evaluate(dt) to step the spring.
- Usage: user code (MonoBehaviour) instantiates one of the solver classes at runtime.
- Distribution: installed via Unity’s Package Manager or OpenUPM.

##### Detail and Clarity
- Every assembly and its purpose.
- Strategy pattern relationship: SpringBase → concrete solvers.
- Assembly dependencies (Runtime ← Editor, Tests ← Runtime).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    PM["Package Manager"]:::external
    UE["Unity Engine"]:::external
    Client["Game Script\n(MonoBehaviour)"]:::external

    %% Repository Artifacts
    subgraph "Repository Artifacts"
        direction TB
        Manifest["package.json"]:::external
        Readme["README.md"]:::external
        License["LICENSE.md"]:::external
        Docs["Documentation~"]:::external
    end

    %% Runtime Assembly
    subgraph "Runtime Assembly"
        direction TB
        RAsm["Thammin.UnitySpring.asmdef"]:::runtime
        SB["SpringBase"]:::runtime
        CF["ClosedForm Solver"]:::runtime
        SI["SemiImplicitEuler Solver"]:::runtime
        RK4["RK4 Solver"]:::runtime
        VE["Verlet Integration Solver"]:::runtime
    end

    %% Editor Assembly
    subgraph "Editor Assembly"
        direction TB
        EAsm["Thammin.UnitySpring.Editor.asmdef"]:::editor
        VZ["Visualizer"]:::editor
    end

    %% Test Assembly
    subgraph "Test Assembly"
        direction TB
        TAsm["Thammin.UnitySpring.Tests.asmdef"]:::test
        PT["Performance Test"]:::test
    end

    %% Relationships
    PM -->|"delivers"| RAsm
    PM -->|"delivers"| EAsm

    Client -->|"instantiates Evaluate()"| SB
    SB -->|"returns position/velocity"| Client

    VZ -->|"uses solvers"| SB

    PT -->|"invokes ClosedForm"| CF
    PT -->|"invokes SemiImplicitEuler"| SI
    PT -->|"invokes RK4"| RK4
    PT -->|"invokes VerletIntegration"| VE

    UE -->|"drives lifecycle"| Client
    UE -->|"drives Editor demo"| VZ

    Manifest -.-> PM
    Readme -.-> Manifest
    License -.-> Manifest
    Docs -.-> Manifest

    %% Click Events
    click RAsm "https://github.com/thammin/unity-spring/blob/master/Runtime/Thammin.UnitySpring.asmdef"
    click SB "https://github.com/thammin/unity-spring/blob/master/Runtime/SpringBase.cs"
    click CF "https://github.com/thammin/unity-spring/blob/master/Runtime/ClosedForm.cs"
    click SI "https://github.com/thammin/unity-spring/blob/master/Runtime/SemiImplicitEuler.cs"
    click RK4 "https://github.com/thammin/unity-spring/blob/master/Runtime/ExplicitRK4.cs"
    click VE "https://github.com/thammin/unity-spring/blob/master/Runtime/VerletIntegration.cs"

    click EAsm "https://github.com/thammin/unity-spring/blob/master/Editor/Thammin.UnitySpring.Editor.asmdef"
    click VZ "https://github.com/thammin/unity-spring/blob/master/Editor/Visualizer.cs"

    click TAsm "https://github.com/thammin/unity-spring/blob/master/Tests/Editor/Thammin.UnitySpring.Tests.asmdef"
    click PT "https://github.com/thammin/unity-spring/blob/master/Tests/Editor/PerformanceTest.cs"

    click Manifest "https://github.com/thammin/unity-spring/blob/master/package.json"
    click Readme "https://github.com/thammin/unity-spring/blob/master/README.md"
    click License "https://github.com/thammin/unity-spring/blob/master/LICENSE.md"
    click Docs "https://github.com/thammin/unity-spring/tree/master/Documentation~"

    %% Styles
    classDef runtime fill:#ADD8E6,stroke:#000
    classDef editor fill:#90EE90,stroke:#000
    classDef test fill:#D3D3D3,stroke:#000
    classDef external stroke-dasharray: 5 5,fill:#fff,stroke:#333
```
