# mmower/rez architecture

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

- Interactive diagram: https://gitdiagram.com/mmower/rez
- Repository: https://github.com/mmower/rez

## Overview

##### Main Components

a) Compiler Components (Elixir-based):
- Parser System (lib/parser/*)
- AST System (lib/AST/*)
- Compiler Core (lib/compiler/*)
- Template Engine (lib/compiler/template_compiler.ex)

b) Runtime Components (JavaScript-based):
- Core Runtime Objects (assets/templates/runtime/*.js)
- Asset Management System
- Game State Management
- User Interface Layer

**┌─────────────────────────────────────────────┐**
- Development                  │
- ┌─────────┐    ┌─────────┐    ┌─────────┐  │
- .rez files│ -> │Compiler │ -> │Generated│  │
- ┘    └─────────┘    │  Game   │  │
- ┘  │
- ┘

**┌─────────────────────────────────────────────┐**
- Runtime                    │
- ┌─────────┐    ┌─────────┐    ┌─────────┐  │
- Game Core│ <- │Browser  │ -> │  UI     │  │
- ┘    │Runtime  │    │ Layer   │  │
- ┘    └─────────┘  │
- ┘

##### Component Details

a) Compiler Pipeline:
- Source Parser (show parsing stages)
- AST Generation
- Node Validation
- Template Processing
- Asset Management
- Output Generation

b) Runtime Architecture:
- Core Game Objects (Scene, Actor, Item, etc.)
- Event System
- State Management
- UI Components (Alpine.js + Bulma)

##### Key Relationships

- Parser → AST → Compiler pipeline
- Template system → Generated code
- Runtime objects → Browser execution
- Event system → State management
- UI components → Player interaction

##### Technical Details

- Elixir/Erlang compiler components
- JavaScript runtime components
- External dependencies (Bulma, Alpine.js, etc.)
- Asset processing system
- Template processing pipeline

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Development
        RezFiles[".rez Files"]
        
        subgraph "Parser System"
            Parser["Main Parser"]:::parser
            TemplateParser["Template Parser"]:::parser
            ValueParser["Value Parsers"]:::parser
        end
        
        subgraph "AST System"
            CoreNode["Core Node"]:::ast
            NodeValidator["Node Validator"]:::ast
            HTMLTransformer["HTML Transformer"]:::ast
        end
        
        subgraph "Compiler Core"
            MainCompiler["Main Compiler"]:::compiler
            CompilationProcess["Compilation Process"]:::compiler
            TemplateCompiler["Template Compiler"]:::compiler
            AssetCompiler["Asset Compiler"]:::compiler
        end
        
        GeneratedGame["Generated Game"]:::output
    end
    
    subgraph Runtime
        subgraph "Core Objects"
            BaseObject["Base Object"]:::runtime
            GameObject["Game Object"]:::runtime
            SceneObject["Scene Object"]:::runtime
            ActorObject["Actor Object"]:::runtime
        end
        
        subgraph "State Management"
            UndoManager["Undo Manager"]:::state
            StateSystem["State System"]:::state
            EventSystem["Event System"]:::state
        end
        
        subgraph "Game Systems"
            InventorySystem["Inventory System"]:::game
            RelationshipSystem["Relationship System"]:::game
            PlotSystem["Plot System"]:::game
            DecisionSystem["Decision System"]:::game
        end
        
        subgraph "Asset Management"
            AssetHandler["Asset Handler"]:::asset
            TemplateRuntime["Template Runtime"]:::asset
        end
        
        UI["UI Layer<br>(Alpine.js + Bulma)"]:::ui
    end
    
    %% Relationships
    RezFiles --> Parser
    Parser --> CoreNode
    TemplateParser --> CoreNode
    ValueParser --> CoreNode
    
    CoreNode --> NodeValidator
    NodeValidator --> HTMLTransformer
    HTMLTransformer --> MainCompiler
    
    MainCompiler --> CompilationProcess
    CompilationProcess --> TemplateCompiler
    TemplateCompiler --> GeneratedGame
    AssetCompiler --> GeneratedGame
    
    GeneratedGame --> BaseObject
    BaseObject --> GameObject
    GameObject --> |Initializes| SceneObject
    GameObject --> |Manages| ActorObject
    
    GameObject --> StateSystem
    StateSystem --> UndoManager
    StateSystem --> EventSystem
    
    GameObject --> InventorySystem
    GameObject --> RelationshipSystem
    GameObject --> PlotSystem
    GameObject --> DecisionSystem
    
    GameObject --> AssetHandler
    AssetHandler --> TemplateRuntime
    
    EventSystem --> UI
    
    %% Styles
    classDef parser fill:#6495ED
    classDef ast fill:#4169E1
    classDef compiler fill:#1E90FF
    classDef output fill:#FFA500
    classDef runtime fill:#90EE90
    classDef state fill:#98FB98
    classDef game fill:#3CB371
    classDef asset fill:#20B2AA
    classDef ui fill:#DDA0DD
    
    %% Click events
    click Parser "https://github.com/mmower/rez/blob/main/lib/parser/parser.ex"
    click TemplateParser "https://github.com/mmower/rez/blob/main/lib/parser/template_parser.ex"
    click ValueParser "https://github.com/mmower/rez/blob/main/lib/parser/value_parsers.ex"
    click CoreNode "https://github.com/mmower/rez/blob/main/lib/AST/node.ex"
    click NodeValidator "https://github.com/mmower/rez/blob/main/lib/AST/node_validator.ex"
    click HTMLTransformer "https://github.com/mmower/rez/blob/main/lib/AST/html_transformer.ex"
    click MainCompiler "https://github.com/mmower/rez/blob/main/lib/compiler.ex"
    click CompilationProcess "https://github.com/mmower/rez/blob/main/lib/compiler/compilation.ex"
    click TemplateCompiler "https://github.com/mmower/rez/blob/main/lib/compiler/template_compiler.ex"
    click BaseObject "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_0_basic_object.js"
    click GameObject "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_game.js"
    click SceneObject "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_scene.js"
    click ActorObject "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_actor.js"
    click UndoManager "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_undo_manager.js"
    click StateSystem "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_system.js"
    click EventSystem "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_event.js"
    click AssetHandler "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_asset.js"
    click AssetCompiler "https://github.com/mmower/rez/blob/main/lib/compiler/copy_assets.ex"
    click TemplateRuntime "https://github.com/mmower/rez/blob/main/assets/templates/runtime.js.eex"
    click InventorySystem "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_inventory.js"
    click RelationshipSystem "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_relationship.js"
    click PlotSystem "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_plot.js"
    click DecisionSystem "https://github.com/mmower/rez/blob/main/assets/templates/runtime/rez_decision.js"
```
