# spaghettifunk/anima architecture

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

- Interactive diagram: https://gitdiagram.com/spaghettifunk/anima
- Repository: https://github.com/spaghettifunk/anima

## Overview

##### Main Components
- Game Engine Core: Represented by the central engine code (files in engine/core, engine/application.go, engine/game.go).
- Asset Management: Covering asset loading and management (engine/assets, its loaders for fonts, images, models, shaders, etc.). This also relates to the external “assets” folder that holds fonts, models, materials, shaders, and textures.
- Renderer: A major component with two sub-layers:
– Rendering Abstractions and Metadata: (engine/renderer/components and engine/renderer/metadata).
– Vulkan Backend: (engine/renderer/vulkan) including command buffers, pipelines, framebuffers, descriptor sets, swapchain management, and shader compilation.
- Systems: Game and engine systems (engine/systems) for camera, font rendering, geometry, materials, shaders, textures, etc.
- Supporting Modules:
– Math Library: (engine/math) handling transformations, geometry, and other mathematical operations.
– Platform Abstraction: (engine/platform) for interfacing with the underlying system.
– Containers: (engine/containers) such as the ring queue used for event/message management.
– Vendors: External libraries (engine/vendors) for third-party tools like stb_image and stb_truetype.
- Build & Run Infrastructure: Magefiles (magefiles) and Go modules (go.mod, go.sum) facilitating the build and run processes.
- Testbed/Application Entrypoints: The main executable (main.go) and sample/testbed (testbed/game.go) to run and test your engine.

##### Relationships and Interactions
- The Main Executable/Application (main.go, testbed) is the entry point that initializes the Engine Core.
- The Engine Core orchestrates the game loop, processes events (engine/core/events.go), manages input, logging, and error handling.
- Asset Management actively loads resources from the “assets” directory through dedicated loaders and makes them available to both the Renderer and various Systems.
- Systems (camera, font, etc.) interface with both the Core and Renderer to update game state and render frames.
- Helper libraries (Math, Platform, Containers) support computations, abstraction layers, or data management that are used across almost every subsystem.
- The build system (magefiles) is logically separate from runtime but is essential for compiling shaders (using glslc) and wiring up the engine.

##### Architectural Patterns & Design Principles
- Modularity: The separation into core, assets, renderer, and systems reflects a modular design. Each major responsibility is isolated in its own directory and interfaced with clearly.
- Abstraction Layers: There’s an explicit separation between general engine functionality (core, math, systems) and platform-specific or graphics-specific code (renderer/vulkan).
- Data Driven Design: The “assets” folder with fonts, materials, models, shaders, and textures suggests that much of the engine’s behavior is parameterized by external resources.
- Build and Deployment: Using Magefiles indicates an automated build and run scheme that complements continuous integration practices.

- Components: Each major module (Core, Asset Management, Renderer – with submodules for Metadata and Vulkan Backend, Systems, Math, Platform, etc.) should be clearly labeled. Optionally, also include the external “assets” as a resource repository.
- Optional Build Pipeline: Consider adding an element for the magefiles/build scripts that leads from source files to a built application.

##### Final Remarks

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Points and Build Infrastructure
    subgraph "Entry Points"
        Main["Main Application Entrypoint"]:::entry
        Testbed["Testbed/Game Entrypoint"]:::entry
    end

    subgraph "Build & Run Infrastructure"
        Build["Build & Run Infrastructure"]:::build
    end

    %% Core Engine
    subgraph "Engine Core"
        EngineCore["Engine Core"]:::core
    end

    %% Asset Management
    subgraph "Asset Management"
        AssetMgr["Asset Manager"]:::assets
        AssetsRep["External Assets Repository"]:::assets
    end

    %% Renderer Layer
    subgraph "Renderer"
        Renderer["Renderer (Abstraction/Metadata)"]:::renderer
        subgraph "Vulkan Backend"
            Vulkan["Vulkan Backend"]:::renderer
        end
    end

    %% Systems
    subgraph "Systems"
        Systems["Systems"]:::systems
    end

    %% Supporting Modules
    subgraph "Supporting Modules"
        Math["Math Library"]:::support
        Platform["Platform Abstraction"]:::support
        Containers["Containers"]:::support
        Vendors["Vendors (External Libraries)"]:::support
    end

    %% GPU Communication Node
    GPU["GPU (Vulkan)"]:::gpu

    %% Relationships and Data Flow
    Build -->|"builds"| Main
    Build -->|"builds"| EngineCore
    Main -->|"initializes"| EngineCore
    Testbed -->|"initializes"| EngineCore
    EngineCore -->|"manages"| AssetMgr
    AssetMgr -->|"loads-from"| AssetsRep
    EngineCore -->|"controls"| Systems
    EngineCore -->|"invokes"| Renderer
    Systems -->|"updates"| Renderer
    Renderer -->|"delegates"| Vulkan
    Vulkan -->|"communicates-with"| GPU

    %% Supporting Modules used by various components
    EngineCore -->|"uses"| Math
    EngineCore -->|"uses"| Platform
    EngineCore -->|"uses"| Containers
    AssetMgr -->|"uses"| Vendors
    Systems -->|"uses"| Math
    Systems -->|"uses"| Platform

    %% Click Events for Component Mapping
    click EngineCore "https://github.com/spaghettifunk/anima/tree/main/engine/core"
    click EngineCore "https://github.com/spaghettifunk/anima/blob/main/engine/application.go"
    click EngineCore "https://github.com/spaghettifunk/anima/blob/main/engine/game.go"
    click AssetMgr "https://github.com/spaghettifunk/anima/tree/main/engine/assets"
    click AssetMgr "https://github.com/spaghettifunk/anima/blob/main/engine/assets/assets.go"
    click AssetMgr "https://github.com/spaghettifunk/anima/blob/main/engine/assets/loader.go"
    click AssetsRep "https://github.com/spaghettifunk/anima/tree/main/assets/"
    click Renderer "https://github.com/spaghettifunk/anima/tree/main/engine/renderer/components"
    click Renderer "https://github.com/spaghettifunk/anima/tree/main/engine/renderer/metadata"
    click Vulkan "https://github.com/spaghettifunk/anima/tree/main/engine/renderer/vulkan"
    click Systems "https://github.com/spaghettifunk/anima/tree/main/engine/systems"
    click Math "https://github.com/spaghettifunk/anima/tree/main/engine/math"
    click Platform "https://github.com/spaghettifunk/anima/tree/main/engine/platform"
    click Containers "https://github.com/spaghettifunk/anima/tree/main/engine/containers"
    click Vendors "https://github.com/spaghettifunk/anima/tree/main/engine/vendors"
    click Build "https://github.com/spaghettifunk/anima/tree/main/magefiles"
    click Build "https://github.com/spaghettifunk/anima/blob/main/go.mod"
    click Build "https://github.com/spaghettifunk/anima/blob/main/go.sum"
    click Main "https://github.com/spaghettifunk/anima/blob/main/main.go"
    click Testbed "https://github.com/spaghettifunk/anima/blob/main/testbed/game.go"

    %% Styles
    classDef core fill:#FFD700,stroke:#333,stroke-width:2px
    classDef assets fill:#87CEFA,stroke:#333,stroke-width:2px
    classDef renderer fill:#90EE90,stroke:#333,stroke-width:2px
    classDef systems fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef support fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef build fill:#F5DEB3,stroke:#333,stroke-width:2px
    classDef entry fill:#FFE4C4,stroke:#333,stroke-width:2px
    classDef gpu fill:#FF6347,stroke:#333,stroke-width:2px
```
