# h-sofie/maodie-runner architecture

> Architecture diagram of the GitHub repository h-sofie/maodie-runner, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/h-sofie/maodie-runner
- Repository: https://github.com/h-sofie/maodie-runner

## Overview

##### Project type and purpose
- This is a small, static, single-page web application: a fork of the Chrome T-Rex-runner offline game, packaged as a self-contained HTML/CSS/JS bundle and served from a static web server (for example GitHub Pages).

##### File structure
- Top-level:
- index.html – the entry point
- README.md, LICENSE – documentation
- src/ – all game assets and code
- src/ subdirectories and files:
- src/offline.js – the core game engine (Runner class, input handlers, game loop)
- src/styles.css – all the CSS rules for the game UI
- src/sounds/... – MP3 files (button-press, hit, reached)
- No backend code or API layers—purely client-side.

##### Extract insights from the README
- The project is a trimmed-down extraction from Chromium’s neterror page.
- All external dependencies have been inlined or removed, making this a zero-dependency, static deliverable.

##### Main components and their interactions
a. Static HTTP Server
– Serves index.html, offline.js, styles.css, images, and sounds over HTTP(S).
b. Web Browser (Client)
– Resource Loader: issues HTTP GETs for index.html, CSS, JS, images, sounds.
– DOM & CSSOM: index.html + styles.css → layout and render tree.
– JavaScript Engine: executes offline.js → instantiates new Runner('.interstitial-wrapper') → initializes the game loop.
– Canvas/DOM Subtree: game visuals are painted.
– Asset Manager: preloads sprites and sounds into memory.
c. Game Engine (offline.js)
– Input Handler: listens for keyboard/touch to start/restart the game.
– Game Loop: updates obstacles, dinosaur sprite, collision detection, score.
– Sound Controller: plays button-press, hit, reached sounds at events.

##### Architectural patterns and principles
- Static front-end architecture (“JAMstack”–style): all logic runs in the browser, no server-side processing.
- Single Responsibility:
- offline.js → game logic
- styles.css → presentation
- index.html → application shell
- Asset bundling: images and sounds are loaded separately but referenced inlined or via paths.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Static Server
    Server["Static HTTP Server\n(GitHub Pages)"]:::server

    %% Browser Client
    subgraph "Browser Client"
        RL["Resource Loader"]:::browser
        DOM["DOM & CSSOM"]:::browser
        VM["JavaScript VM\n(offline.js – Runner Engine)"]:::browser
        CANVAS["Canvas/Rendering Subsystem"]:::browser
        CACHE["Asset Cache\n(Images & Sounds)"]:::assets
    end

    %% Assets
    subgraph "Image Assets" 
        IM1["default_100_percent"]:::assets
        IM2["default_200_percent"]:::assets
    end

    subgraph "Sound Assets"
        SNDS["MP3 Sounds"]:::assets
    end

    %% Documentation
    subgraph "Documentation & Licensing"
        RD["README.md"]:::doc
        LIC["LICENSE"]:::doc
    end

    %% Data Flows
    RL -->|"GET index.html"| Server
    RL -->|"GET styles.css"| Server
    RL -->|"GET offline.js"| Server
    RL -->|"GET images"| Server
    RL -->|"GET sounds"| Server

    Server -->|"200 OK"| RL

    RL -->|"Bootstrap"| DOM
    RL -->|"Bootstrap"| VM
    RL -->|"Preload"| CACHE

    VM -->|"Execute JS"| VM
    VM -->|"Render Loop"| CANVAS
    VM -->|"Play Sound"| CACHE

    CACHE -->|"Provide Assets"| CANVAS
    CACHE -->|"Provide Assets"| VM

    %% Click Events
    click Server "https://github.com/h-sofie/maodie-runner/blob/main/index.html"
    click VM "https://github.com/h-sofie/maodie-runner/blob/main/src/offline.js"
    click RL "https://github.com/h-sofie/maodie-runner/blob/main/src/styles.css"
    click IM1 "https://github.com/h-sofie/maodie-runner/tree/main/src/images/default_100_percent"
    click IM2 "https://github.com/h-sofie/maodie-runner/tree/main/src/images/default_200_percent"
    click SNDS "https://github.com/h-sofie/maodie-runner/tree/main/src/sounds"
    click RD "https://github.com/h-sofie/maodie-runner/blob/main/README.md"
    click LIC "https://github.com/h-sofie/maodie-runner/tree/main/LICENSE"

    %% Styles
    classDef server fill:#dddddd,stroke:#333333,color:#000000;
    classDef browser fill:#a8cdf8,stroke:#1f77b4,color:#000000;
    classDef assets fill:#c8e6c9,stroke:#2e7d32,color:#000000;
    classDef doc fill:#f0ead6,stroke:#bf9033,color:#000000;
```
