# badestrand/theaviator2 architecture

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

- Interactive diagram: https://gitdiagram.com/badestrand/theaviator2
- Repository: https://github.com/badestrand/theaviator2

## Overview

##### Project type and purpose
- This is a browser‑based 3D arcade game (“The Aviator 2”) built on top of Three.js and TweenMax.
- There is no separate backend business logic or database—just a static file server (e.g. PHP built‑in server) delivering HTML, CSS, JS, 3D models, and audio assets to the client.

##### File structure
- Top level:
- index.html – entry point
- game.css – styles
- game.js – the main game script
- audio/ – sound effects (mp3 files)
- models/ – 3D model assets (OBJ/MTL)
- No “src” or “backend” directories, meaning the entire game runs in the browser.
- README lists dependencies: Three.js (WebGL renderer) and TweenMax (animations).

##### README for additional insights
- Describes how to serve the project with `php -S` (or any static file server).
- Credits the libraries and audio sources.
- Mentions game features: levels, collectibles, enemies, audio integration, and state handling.

##### Main components & their relationships
a. Components:
1. Static File Server
- Serves index.html, CSS, JS, audio, and model files over HTTP.
2. Browser Client
- HTML/CSS layer (UI overlay, score, life hearts)
- JavaScript Game Engine (game.js)
- Asset Loader (XHR/Fetch or Three.js loaders for models & audio)
- Scene Manager (Three.js WebGLRenderer, Camera, Scene graph)
- Input Manager (keyboard/mouse or touch)
- Physics & Collision Handler (basic collision detection)
- Audio Manager (HTML5 Audio or Web Audio API)
- Tween Manager (TweenMax for transitions)
3. Assets
- 3D Models: heart.obj/.mtl
- Audio Files: sound effects under /audio
b. Interactions:
- Browser sends HTTP GETs to the Static File Server to load index.html, CSS, JS, models, and audio.
- game.js initializes Three.js renderer, loads models & sounds, and enters the game loop.
- Input events flow from user → Input Manager → Game Engine
- Game state updates fire rendering passes → Scene Manager draws to canvas
- Audio Manager plays sound effects on events (coin collected, crash, shot, etc.)
- TweenMax drives UI and game object animations.

##### Architectural patterns & design principles
- Modular client‑side architecture: separate concerns (Asset Loading, Rendering, Input, Audio, Tweening).
- Event‑driven game loop: update → render → requestAnimationFrame.
- Use of external libraries (Three.js for rendering, TweenMax for animations) avoids reinventing core functionality.

##### Essential elements
- Labels for every component and sub‐component.
- A note on external libraries integrated into the game engine.

1) Static File Server
2) Browser Client (HTML/CSS + JS Game Engine + Third‑party libs)
3) Assets (models + audio)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Server[(Static File Server)]:::storage

    Index["index.html"]:::storage
    CSS["game.css"]:::storage
    JS["game.js"]:::storage

    Server --> Index
    Server --> CSS
    Server --> JS

    subgraph "Assets"
        Models[(models/)]:::storage
        heartMTL["heart.mtl"]:::storage
        heartOBJ["heart.obj"]:::storage
        Audio[(audio/)]:::storage
    end

    Server --> Models
    Server --> Audio

    Models --> heartMTL
    Models --> heartOBJ

    subgraph "Browser Client"
        subgraph "HTML/CSS Layer"
            HTML["HTML/CSS Layer"]:::ui
        end
        subgraph "JS Game Engine"
            AssetLoader["Asset Loader"]:::runtime
            SceneManager["Scene Manager"]:::runtime
            InputManager["Input Manager"]:::runtime
            Physics["Physics & Collision Handler"]:::runtime
            AudioManager["Audio Manager"]:::runtime
            TweenManager["Tween Manager"]:::runtime
            subgraph "Third-party Libraries"
                ThreeJS["Three.js"]:::lib
                TweenMax["TweenMax"]:::lib
            end
        end
        Canvas["Canvas Output"]:::ui
        Speaker["Speaker Output"]:::ui
    end

    Index --> HTML
    CSS --> HTML
    JS --> AssetLoader

    AssetLoader -->|"loads models"| Models
    AssetLoader -->|"loads audio"| Audio

    User([User]):::ui
    User --> InputManager

    InputManager --> AssetLoader
    AssetLoader --> SceneManager
    SceneManager --> Canvas
    Physics --> SceneManager
    SceneManager --> Physics
    AudioManager --> Speaker
    TweenManager --> SceneManager

    click Server "https://github.com/badestrand/theaviator2/tree/master//"
    click Index "https://github.com/badestrand/theaviator2/blob/master/index.html"
    click CSS "https://github.com/badestrand/theaviator2/blob/master/game.css"
    click JS "https://github.com/badestrand/theaviator2/blob/master/game.js"
    click Models "https://github.com/badestrand/theaviator2/tree/master/models/"
    click heartMTL "https://github.com/badestrand/theaviator2/blob/master/models/heart.mtl"
    click heartOBJ "https://github.com/badestrand/theaviator2/blob/master/models/heart.obj"
    click Audio "https://github.com/badestrand/theaviator2/tree/master/audio/"

    classDef storage fill:#9f6,stroke:#333,stroke-width:1px
    classDef runtime fill:#6cf,stroke:#333,stroke-width:1px
    classDef lib fill:#f96,stroke:#333,stroke-width:1px
    classDef ui fill:#ccc,stroke:#333,stroke-width:1px
```
