# mayu-live/framework architecture

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

- Interactive diagram: https://gitdiagram.com/mayu-live/framework
- Repository: https://github.com/mayu-live/framework

## Overview

##### Main Components

a) Core System Components:
- Server-Side Runtime
- VirtualDOM Engine
- Component Manager
- State Management System
- Resource System
- Router
- Client-Side Runtime (minimal)
- DOM Updater
- Event Handler
- Stream Handler
- Development Tools
- Hot Reload System
- Asset Pipeline
- Metrics Collector

b) External Systems:
- HTTP/2 Server
- Prometheus Metrics
- File System (for component storage)
- Browser Client
- Development Tools (optional subsystem)

##### Key Relationships to Highlight

a) Data Flow:
- Server → Client Stream (DOM updates)
- Client → Server (Event callbacks)
- File System → Resource System → Component Manager
- VirtualDOM → DOM Patch Generator → Client
- Metrics Collection → Prometheus Endpoint

b) Component Lifecycle:
- File Loading → Compilation → Component Registry
- State Updates → VDOM Reconciliation → DOM Patches
- Event Handling → State Updates → Re-render

##### Architectural Patterns to Emphasize

- Component-based Architecture
- Event-driven System
- Asynchronous Processing
- Hot Module Replacement
- File-system Based Routing
- Resource Pipeline

##### Implementation Details

- Mayu Framework                                       |

- Server Core    |  |  Resource System  |  |   Component     |  |    Client      |  |
- Pipeline      |  |    Runtime     |  |
- VDOM Engine    |  | - Asset Loading   |  | - Compilation   |  | - DOM Updates  |  |
- State Manager  |  | - Hot Reload      |  | - Registration  |  | - Event Hand.  |  |
- Router         |  | - Cache Manager   |  | - Lifecycle     |  | - Streaming    |  |

- Development     |  |     Metrics       |  |   HTTP/2        |                     |
- Tools           |  |     System        |  |   Server        |                     |
- Hot Reloader   |  | - Prometheus      |  | - Session Mgmt  |                     |
- Debug Tools    |  | - Performance     |  | - Compression   |                     |

##### Important Notes

- Async nature of the system
- Minimal client-side footprint
- Demonstrate the hot-reload capability
- Metrics collection system
- HTTP/2 streaming connection
- File system routing structure

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Mayu["Mayu Framework"]
        subgraph Server["Server-Side Components"]
            VDOM["VirtualDOM Engine"]:::core
            CompMgr["Component Manager"]:::core
            StateMgr["State Management"]:::core
            Router["Router"]:::core
            ResSys["Resource System"]:::core
            
            subgraph Pipeline["Component Pipeline"]
                Compile["Compilation"]:::pipeline
                Register["Registration"]:::pipeline
                Lifecycle["Lifecycle Mgmt"]:::pipeline
            end
        end

        subgraph Client["Client Runtime"]
            DOMUpdate["DOM Updater"]:::client
            EventHandler["Event Handler"]:::client
            StreamHandler["Stream Handler"]:::client
        end

        subgraph DevTools["Development Tools"]
            HotReload["Hot Reload System"]:::dev
            AssetPipe["Asset Pipeline"]:::dev
            DebugTools["Debug Tools"]:::dev
        end

        subgraph Infrastructure["Supporting Infrastructure"]
            HTTP2["HTTP/2 Server"]:::infra
            Metrics["Metrics System"]:::infra
            Session["Session Management"]:::infra
            Config["Configuration"]:::infra
        end
    end

    %% Relationships
    VDOM --> DOMUpdate
    CompMgr --> Register
    StateMgr --> VDOM
    Router --> HTTP2
    ResSys --> AssetPipe
    
    EventHandler --> StateMgr
    StreamHandler --> HTTP2
    
    HotReload --> ResSys
    AssetPipe --> CompMgr
    Metrics --> HTTP2
    
    %% Click Events
    click VDOM "https://github.com/mayu-live/framework/tree/main/lib/mayu/vdom/"
    click CompMgr "https://github.com/mayu-live/framework/tree/main/lib/mayu/component/"
    click StateMgr "https://github.com/mayu-live/framework/tree/main/lib/mayu/state/"
    click ResSys "https://github.com/mayu-live/framework/tree/main/lib/mayu/resources/"
    click Router "https://github.com/mayu-live/framework/tree/main/lib/mayu/routing/"
    click Client "https://github.com/mayu-live/framework/tree/main/lib/mayu/client/"
    click HotReload "https://github.com/mayu-live/framework/tree/main/lib/mayu/resources/hot_swap/"
    click AssetPipe "https://github.com/mayu-live/framework/tree/main/lib/mayu/resources/transformers/"
    click Metrics "https://github.com/mayu-live/framework/tree/main/lib/mayu/metrics/"
    click HTTP2 "https://github.com/mayu-live/framework/tree/main/lib/mayu/server/"
    click EventHandler "https://github.com/mayu-live/framework/blob/main/lib/mayu/event_stream.rb"
    click Session "https://github.com/mayu-live/framework/blob/main/lib/mayu/session.rb"
    click DevTools "https://github.com/mayu-live/framework/tree/main/lib/mayu/commands/"
    click Config "https://github.com/mayu-live/framework/blob/main/lib/mayu/configuration.rb"

    %% Styling
    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef client fill:#ff7f50,stroke:#ff7f50,color:#fff
    classDef dev fill:#4caf50,stroke:#4caf50,color:#fff
    classDef infra fill:#9c27b0,stroke:#9c27b0,color:#fff
    classDef pipeline fill:#607d8b,stroke:#607d8b,color:#fff

    %% Legend
    subgraph Legend
        CoreComp["Core Components"]:::core
        ClientComp["Client Components"]:::client
        DevComp["Development Tools"]:::dev
        InfraComp["Infrastructure"]:::infra
        PipeComp["Pipeline Components"]:::pipeline
    end
```
