# fairuse/okgame architecture

> Architecture diagram of the GitHub repository fairuse/okgame, 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/fairuse/okgame
- Repository: https://github.com/fairuse/okgame

## Overview

##### Client-Side Architecture
- Browser Environment (Main Container)
- HTML Runtime (index.html)
- WebAssembly Module (compiled from Go)
- JavaScript Bridge (wasm_exec.js)

##### Game Engine Components
- Ebitengine Core
- Game Objects Layer
- Ball Component (ball.go)
- Level Component (level.go)
- Obstacle Component (obstacle.go)
- Utility Layer (util.go)
- Main Game Loop (main.go)

Drawing Instructions:

##### Inside the Browser Container, Create Three Main Sections
- HTML Layer (Top)
- WebAssembly Runtime (Middle)
- Game Engine Layer (Bottom)

##### Component Relationships
- Wasm_exec.js to the WebAssembly module
- Game engine components hierarchy within the WebAssembly module

##### Game Engine Detail
- Rectangles for core components
- Rounded rectangles for game objects
- Ovals for utility functions

##### Data Flow Indicators

Specific Layout Guidelines:

**[Browser Environment]**
- [HTML Layer (index.html)]
- [JavaScript Bridge (wasm_exec.js)]
- [WebAssembly Module]
- [Game Engine (Ebitengine)]
- [Main Game Loop]
- [Game Objects]
- Ball Component
- Level Component
- Obstacle Component
- [Utility Functions]

- Blue: Browser environment
- Green: Game engine components
- Yellow: Game objects
- Gray: Utility functions
- Red: Critical path components

##### WebAssembly compilation pipeline
- How Go code is compiled to WebAssembly
- Role of buildweb.sh in the build process

##### Game loop architecture
- Update cycle
- Render pipeline
- Input handling flow

##### Technical specifications
- Use of tinygo vs standard go
- WebAssembly integration points
- Browser compatibility requirements

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef browser fill:#e1f5fe,stroke:#01579b
    classDef html fill:#e8f5e9,stroke:#2e7d32
    classDef js fill:#fff3e0,stroke:#ef6c00
    classDef wasm fill:#f3e5f5,stroke:#7b1fa2
    classDef engine fill:#e8eaf6,stroke:#3f51b5
    classDef gameObj fill:#fff8e1,stroke:#ffa000
    classDef util fill:#eceff1,stroke:#546e7a
    classDef build fill:#ffebee,stroke:#c62828

    subgraph Browser["Browser Environment"]
        HTML["HTML Runtime<br/>(index.html)"]
        JS["JavaScript Bridge<br/>(wasm_exec.js)"]
        
        subgraph WASM["WebAssembly Module"]
            subgraph Engine["Game Engine (Ebitengine)"]
                Main["Main Game Loop<br/>(main.go)"]
                
                subgraph GameObjects["Game Objects"]
                    Ball["Ball Component<br/>(ball.go)"]
                    Level["Level Component<br/>(level.go)"]
                    Obstacle["Obstacle Component<br/>(obstacle.go)"]
                end
                
                Util["Utility Functions<br/>(util.go)"]
            end
        end
        
        Build["Build Pipeline<br/>(buildweb.sh)"]
        GoConfig["Go Configuration<br/>(go.mod, go.sum)"]
    end

    %% Relationships
    HTML --> JS
    JS --> WASM
    Build --> WASM
    GoConfig --> Build
    Main --> Ball
    Main --> Level
    Main --> Obstacle
    Ball --> Util
    Level --> Util
    Obstacle --> Util

    %% Click Events
    click HTML "https://github.com/fairuse/okgame/blob/main/index.html"
    click JS "https://github.com/fairuse/okgame/blob/main/wasm_exec.js"
    click Build "https://github.com/fairuse/okgame/blob/main/buildweb.sh"
    click Main "https://github.com/fairuse/okgame/blob/main/main.go"
    click Ball "https://github.com/fairuse/okgame/blob/main/ball.go"
    click Level "https://github.com/fairuse/okgame/blob/main/level.go"
    click Obstacle "https://github.com/fairuse/okgame/blob/main/obstacle.go"
    click Util "https://github.com/fairuse/okgame/blob/main/util.go"
    click GoConfig "https://github.com/fairuse/okgame/blob/main/go.mod"

    %% Style Applications
    class Browser browser
    class HTML html
    class JS js
    class WASM wasm
    class Engine engine
    class Ball,Level,Obstacle gameObj
    class Util util
    class Build build
    class GoConfig build

    %% Legend
    subgraph Legend
        L1["Browser Components"]:::browser
        L2["HTML Elements"]:::html
        L3["JavaScript Components"]:::js
        L4["WebAssembly Components"]:::wasm
        L5["Game Engine"]:::engine
        L6["Game Objects"]:::gameObj
        L7["Utility Functions"]:::util
        L8["Build Components"]:::build
    end
```
