# cisa-cell/pastanation architecture

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

- Interactive diagram: https://gitdiagram.com/cisa-cell/pastanation
- Repository: https://github.com/cisa-cell/pastanation

## Overview

##### Project Type and Purpose
- This is a single‐page, client‐side web game built with Phaser 3 and bundled via Vite.
- Its purpose is to run in the browser, load scenes, assets (audio, sprites, fonts), and deliver an interactive game experience.

##### High-Level File Structure Analysis
- Top-level:
- package.json / node_modules – dev dependencies (Phaser, Vite) and scripts.
- log.js – optional telemetry script.
- vite/config.dev.mjs & config.prod.mjs – Vite build configurations.
- index.html & public/style.css – host template and global styles.
- public/assets – static assets served in dev and copied to dist.
- src/main.js – game bootstrap (Phaser config & entry point).
- src/scenes – all Phaser Scenes (MainMenu, PreLoader, Game, GameOver, plus level-1 subfolder with intros and Outro).
- dist – production build output (bundled JS, CSS, and copied assets).

##### Core Components
a. Developer Environment
– Source code (src folder)
– Static assets (public/assets)
– Vite Dev Server (hot‐reload, local file watcher)
– log.js telemetry call to external API
b. Build Pipeline
– Vite config (dev vs. prod)
– `npm run dev` / `npm run build` scripts
– Output: dist/ (index.html, style.css, assets, hashed JS bundles)
c. Browser Runtime
– index.html loads CSS & JS bundle
– Phaser Engine initializes using config from main.js
– Scene Manager cycles through PreLoader → MainMenu → Game → GameOver (and level-1 intros/outro)
– AssetLoader loads fonts, audio, sprites from bundled imports or assets folder
d. External Services
– Optional telemetry endpoint at gryzor.co triggered by log.js

##### Relationships and Interactions
- Dev Machine: invokes Vite Dev Server → serves index.html + public assets + in‐memory JS bundles → browser
- Build: Vite reads src/, public/assets → applies plugins (JS transpile, CSS, asset inlining) → writes dist/
- Browser:
- index.html references dist/assets/index-*.js and style.css
- Phaser instantiates Game object → uses Scene modules
- Scenes call this.load to fetch assets (bundled or from dist/assets)
- Scenes push/pop in Phaser’s scene graph (directional flow)
- Telemetry (if enabled): log.js sends “template, env, Phaser version” via HTTP request

##### Architectural Patterns & Design Principles
- Modular Scene Pattern: each game state is encapsulated in its own JS class (PreLoader, MainMenu, etc.).
- Asset Pipeline Separation: code assets vs. static assets; code imports vs. public folder loads.
- Dev vs. Prod Config Branching: separate Vite configs for speed/hot-reload vs. optimization.
- Single‐Page‐App (SPA): one HTML entry point, dynamic scene switching.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer & Build Zone
    subgraph "Developer & Build" 
        direction TB
        DevWorkstation["Developer Workstation"]:::dev
        NPM["package.json\n(npm scripts & deps)"]:::dev
        ViteDev["Vite Dev Server\n(port 8080)"]:::dev
        ViteConfigDev["vite/config.dev.mjs"]:::dev
        ViteConfigProd["vite/config.prod.mjs"]:::dev
        SrcCode["src/"]:::dev
        StaticAssets["public/assets/"]:::dev
        TelemetryScript["log.js"]:::dev
    end

    %% Production Artifacts Zone
    subgraph "Production Artifacts" 
        direction TB
        Dist["dist/"]:::prod
        AssetsFonts["dist/assets/fonts/Pixelify-Sans/"]:::prod
        JSBundle["dist/assets/index-*.js"]:::prod
        AudioLevel1["dist/assets/level-1/"]:::prod
        SoundFX["dist/assets/sound-effects/"]:::prod
        Sprites["dist/assets/sprites/"]:::prod
    end

    %% Browser Runtime Zone
    subgraph "Browser Runtime"
        direction TB
        Browser["Browser"]:::runtime
        HTML["index.html"]:::runtime
        CSS["public/style.css"]:::runtime
        MainJS["src/main.js"]:::runtime
        PhaserEngine["Phaser Engine"]:::runtime
        subgraph "Scenes"
            direction TB
            PreLoader["src/scenes/PreLoader.js"]:::runtime
            MainMenu["src/scenes/MainMenu.js"]:::runtime
            GameScene["src/scenes/Game.js"]:::runtime
            GameOver["src/scenes/GameOver.js"]:::runtime
            subgraph "Level-1"
                direction TB
                Level1["src/scenes/level-1/Level1.js"]:::runtime
                subgraph "Intros"
                    direction TB
                    Step1["src/scenes/level-1/intros/Step1.js"]:::runtime
                    Step2["src/scenes/level-1/intros/Step2.js"]:::runtime
                    Step3["src/scenes/level-1/intros/Step3.js"]:::runtime
                end
                Outro["src/scenes/level-1/Outro.js"]:::runtime
            end
        end
    end

    %% External Services Zone
    subgraph "External Services"
        direction TB
        TelemetryAPI["Telemetry API\n(gryzor.co)"]:::external
    end

    %% Connections: Development to Server
    DevWorkstation -->|npm run dev| ViteDev
    ViteDev -->|uses config| ViteConfigDev
    ViteDev -->|serves| HTML
    ViteDev -->|serves| StaticAssets
    ViteDev -->|serves| SrcCode

    %% Build Pipeline
    DevWorkstation -->|npm run build| ViteConfigProd
    ViteConfigProd -->|bundles src & assets| Dist
    ViteConfigProd -->|outputs| AssetsFonts
    ViteConfigProd -->|outputs| JSBundle
    ViteConfigProd -->|outputs| AudioLevel1
    ViteConfigProd -->|outputs| SoundFX
    ViteConfigProd -->|outputs| Sprites

    %% Telemetry
    DevWorkstation -->|on start| TelemetryScript
    TelemetryScript -->|POST data| TelemetryAPI

    %% Browser Runtime Flow
    Browser -->|loads| HTML
    HTML -->|includes| CSS
    HTML -->|loads| JSBundle
    JSBundle -->|executes| MainJS
    MainJS -->|initializes| PhaserEngine
    PhaserEngine -->|loads| PreLoader
    PreLoader -->|then| MainMenu
    MainMenu -->|then| GameScene
    GameScene -->|then on end| GameOver
    GameOver -->|or level start| Level1
    Level1 -->|plays intros| Step1
    Step1 -->|then| Step2
    Step2 -->|then| Step3
    Step3 -->|then| Outro

    %% Asset Loading
    PreLoader -->|loads assets| StaticAssets
    PreLoader -->|loads bundled| JSBundle

    %% Click Events
    click SrcCode "https://github.com/cisa-cell/pastanation/tree/main/src/"
    click StaticAssets "https://github.com/cisa-cell/pastanation/tree/main/public/assets/"
    click TelemetryScript "https://github.com/cisa-cell/pastanation/blob/main/log.js"
    click ViteConfigDev "https://github.com/cisa-cell/pastanation/blob/main/vite/config.dev.mjs"
    click ViteConfigProd "https://github.com/cisa-cell/pastanation/blob/main/vite/config.prod.mjs"
    click NPM "https://github.com/cisa-cell/pastanation/blob/main/package.json"
    click Dist "https://github.com/cisa-cell/pastanation/tree/main/dist/"
    click HTML "https://github.com/cisa-cell/pastanation/blob/main/index.html"
    click CSS "https://github.com/cisa-cell/pastanation/blob/main/public/style.css"
    click MainJS "https://github.com/cisa-cell/pastanation/blob/main/src/main.js"
    click PreLoader "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/PreLoader.js"
    click MainMenu "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/MainMenu.js"
    click GameScene "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/Game.js"
    click GameOver "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/GameOver.js"
    click Level1 "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/level-1/Level1.js"
    click Step1 "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/level-1/intros/Step1.js"
    click Step2 "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/level-1/intros/Step2.js"
    click Step3 "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/level-1/intros/Step3.js"
    click Outro "https://github.com/cisa-cell/pastanation/blob/main/src/scenes/level-1/Outro.js"

    %% Styles
    classDef dev fill:#ADD8E6,stroke:#000
    classDef prod fill:#90EE90,stroke:#000
    classDef runtime fill:#FFFFE0,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000
```
