# schwa/ultraviolence architecture

> Architecture diagram of the GitHub repository schwa/ultraviolence, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/schwa/ultraviolence
- Repository: https://github.com/schwa/ultraviolence

## Overview

##### Main Components Identification

The system should be represented with these key components:

a) Core Framework Layer
- Contains the fundamental rendering architecture
- Houses state management and render pass handling
- Located in Sources/Ultraviolence/Core/

b) Support Layer
- Provides utility functions and base support
- Contains Metal-specific support code
- Located in Sources/UltraviolenceSupport/

c) Macro Processing Layer
- Handles compile-time code generation
- Located in Sources/UltraviolenceMacros/

d) Examples/Demo Layer
- Demonstrates framework usage
- Located in Sources/UltraviolenceExamples/

**┌─────────────────────────────────────────┐**
- Client Code                │
- ┬─────────────────────┬─┘
**┌─────────────────┴─────────────────────┴─┐**
- Declarative API Layer           │
- ┬─────────────────────┬─┘
**┌─────────────────┴─────────────────────┴─┐**
- Core Framework               │
- ┌─────────────┐  ┌─────────────────┐  │
- RenderPass  │  │  State Manager  │  │
- ┘  └─────────────────┘  │
- ┬─────────────────────┬─┘
**┌─────────────────┴─────────────────────┴─┐**
- Metal Support Layer           │
- ┬─────────────────────┬─┘
**┌─────────────────┴─────────────────────┴─┐**
- Metal Framework            │
- ┘

##### Key Elements to Highlight

a) Core Components:
- RenderPass system
- Graph management
- State handling
- Environment values

b) Support Features:
- Metal integration
- Angle and projection utilities
- Error handling
- Base support functions

##### Implementation Details

- How the declarative API translates to Metal commands
- The relationship between RenderPass and Metal command encoding
- State propagation through the rendering pipeline
- Macro expansion points and their effects

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Code"]
        DemoApp["Demo App"]:::demo
        Examples["Example Implementations"]:::demo
    end

    subgraph API["Declarative API Layer"]
        RenderView["Render View"]:::api
        Parameters["Parameters Handler"]:::api
        Compute["Compute Operations"]:::api
        OffscreenRenderer["Offscreen Renderer"]:::api
    end

    subgraph Core["Core Framework Layer"]
        RenderPass["RenderPass System"]:::core
        State["State Management"]:::core
        Graph["Graph Management"]:::core
        EnvValues["Environment Values"]:::core
    end

    subgraph Support["Metal Support Layer"]
        MetalSupport["Metal Integration"]:::support
        AngleUtils["Angle Utilities"]:::support
        ProjUtils["Projection Utilities"]:::support
        ErrorHandling["Error Handling"]:::support
        BaseSupport["Base Support"]:::support
    end

    subgraph Macros["Macro Processing Layer"]
        MainMacro["Main Macro Implementation"]:::macro
        EntryMacro["Entry Macro"]:::macro
        MetaEnumMacro["Meta Enum Macro"]:::macro
        StringMacro["String Macro"]:::macro
    end

    subgraph Metal["Metal Framework"]
        MetalFW["Metal API"]:::external
    end

    %% Relationships
    DemoApp --> RenderView
    Examples --> RenderView
    RenderView --> RenderPass
    Parameters --> State
    Compute --> Graph
    OffscreenRenderer --> RenderPass

    RenderPass --> MetalSupport
    State --> BaseSupport
    Graph --> MetalSupport
    EnvValues --> ErrorHandling

    MetalSupport --> MetalFW
    AngleUtils --> MetalFW
    ProjUtils --> MetalFW

    MainMacro -.-> RenderPass
    EntryMacro -.-> State
    MetaEnumMacro -.-> Graph
    StringMacro -.-> EnvValues

    %% Click Events
    click DemoApp "https://github.com/schwa/ultraviolence/blob/main/Demo/UltraviolenceDemo/UltraviolenceDemoApp.swift"
    click Examples "https://github.com/schwa/ultraviolence/tree/main/Sources/UltraviolenceExamples"
    click RenderView "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/RenderView.swift"
    click Parameters "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/Parameters.swift"
    click Compute "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/Compute.swift"
    click OffscreenRenderer "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/OffscreenRenderer.swift"
    click RenderPass "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/Core/RenderPass.swift"
    click State "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/Core/State.swift"
    click Graph "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/Core/Graph.swift"
    click EnvValues "https://github.com/schwa/ultraviolence/blob/main/Sources/Ultraviolence/Core/EnvironmentValues.swift"
    click MetalSupport "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceSupport/MetalSupport.swift"
    click AngleUtils "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceSupport/Angle.swift"
    click ProjUtils "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceSupport/Projection.swift"
    click ErrorHandling "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceSupport/Error.swift"
    click BaseSupport "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceSupport/BaseSupport.swift"
    click MainMacro "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceMacros/UltraviolenceMacros.swift"
    click EntryMacro "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceMacros/EntryMacro.swift"
    click MetaEnumMacro "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceMacros/MetaEnumMacro.swift"
    click StringMacro "https://github.com/schwa/ultraviolence/blob/main/Sources/UltraviolenceMacros/StringifyMacro.swift"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef support fill:#2ecc71,stroke:#27ae60,color:white
    classDef macro fill:#e67e22,stroke:#d35400,color:white
    classDef demo fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef api fill:#e74c3c,stroke:#c0392b,color:white
```
