# dnzengou/tariffs-impact-simulation-game architecture

> Architecture diagram of the GitHub repository dnzengou/tariffs-impact-simulation-game, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dnzengou/tariffs-impact-simulation-game
- Repository: https://github.com/dnzengou/tariffs-impact-simulation-game

## Overview

##### Project type and purpose
- This is a purely client-side, static web application (no backend server or database) for running interactive “Liberation Day” tariff‐impact simulations.
- Users load one of several HTML entry points (e.g., index.html, tariff-simulator.html, abm-ca-simulations.html), adjust parameters in the browser UI, run Monte Carlo–style or ABM simulations in Web Workers, and view results via D3.js visualizations.

##### File structure
- Top-level HTML pages:
- index.html – landing page
- tariff-simulator.html – main tariff sim UI
- abm-ca-simulations.html – agent-based model UI
- various backup HTML files for previous versions
- script.js – application logic orchestrating UI events, sending tasks to workers, handling results
- worker.js, worker-simu.js – Web Worker scripts that perform the core simulation computations off the main thread
- worker_tariff-simulator.html.js – likely a generated/inline worker loader for tariff-simulator
- No server code or configuration files – project is hosted statically on GitHub Pages or Netlify

##### README for additional insights
- Confirms tech stack: HTML, CSS, vanilla JavaScript, D3.js
- Emphasis on lightweight, browser‐only deployment, user‐adjustable parameters, D3 visualizations

a. Main Components
- Hosting Platform (GitHub Pages / Netlify)
- Client Browser Environment
- UI Layer (HTML + CSS; parameter controls, buttons)
- App Controller (script.js)
- Web Worker Pool (worker.js, worker-simu.js) – simulation engine
- Visualization Engine (D3.js) – charting, graphs
- (Optional) Configuration/Parameter Model (in-memory JS objects)

b. Relationships & Data Flows
1. Browser requests the static files from Hosting Platform
2. UI Layer renders HTML forms/sliders & captures user input
3. App Controller reads parameters and spawns one or more Web Workers, passing input via postMessage
4. Web Workers perform compute‐intensive simulations and postMessage results back
5. App Controller receives simulation data and invokes D3.js routines to render visualizations in the DOM
6. User interacts further, possibly re-running simulations or altering views

c. Architectural Patterns & Principles
- Single-Page / Multi-Entry Static App pattern – separate HTML shell pages, each with its own script loader
- Separation of concerns – UI vs. compute logic handled in Web Workers
- Asynchronous messaging (main thread ↔ workers) to keep UI responsive
- Modular JavaScript – script.js orchestrator, worker.js compute modules, D3 for visualization

d. Key Technologies & Libraries
- HTML5, CSS3 – markup & styling
- Vanilla JavaScript – core application logic (script.js)
- Web Workers (worker.js, worker-simu.js) – parallel simulation computing
- D3.js – dynamic, data-driven visualizations
- Static hosting (GitHub Pages / Netlify)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Hosting
    Hosting["Hosting Platform<br/>(GitHub Pages / Netlify)"]:::host

    %% Browser Environment
    subgraph "Browser Environment"
        direction TB
        subgraph "UI Layer" 
            direction TB
            Index["index.html<br/>(Landing Page)"]:::ui
            TariffUI["tariff-simulator.html<br/>(Tariff Simulator)"]:::ui
            ABMUI["abm-ca-simulations.html<br/>(ABM CA Simulations)"]:::ui
            subgraph "Backup HTML Versions"
                direction TB
                Backup1["tariffs-impact-simulation-backup30042025.html"]:::ui
                Backup2["tariffs-impact-simulation_backup28042025.html"]:::ui
                Backup3["tariffs-simu-chaostheory-entropy-ga.html"]:::ui
            end
        end

        AppController["script.js<br/>(App Controller)"]:::controller

        subgraph "Web Worker Pool"
            direction TB
            WorkerGeneral["worker.js<br/>(Simulation Engine)"]:::compute
            WorkerMC["worker-simu.js<br/>(Monte Carlo Engine)"]:::compute
            WorkerLoader["worker_tariff-simulator.html.js<br/>(Tariff Worker Loader)"]:::compute
        end

        VizEngine["D3.js Visualization Engine"]:::viz
    end

    %% Flow
    Hosting -->|HTTP GET Static Files| Index
    Hosting -->|HTTP GET Static Files| TariffUI
    Hosting -->|HTTP GET Static Files| ABMUI
    Hosting -->|HTTP GET Static Files| Backup1
    Hosting -->|HTTP GET Static Files| Backup2
    Hosting -->|HTTP GET Static Files| Backup3
    Hosting -->|HTTP GET Static Files| AppController
    Hosting -->|HTTP GET Static Files| WorkerGeneral
    Hosting -->|HTTP GET Static Files| WorkerMC
    Hosting -->|HTTP GET Static Files| WorkerLoader

    Index -->|User Input| AppController
    TariffUI -->|User Input| AppController
    ABMUI -->|User Input| AppController
    Backup1 -->|User Input| AppController
    Backup2 -->|User Input| AppController
    Backup3 -->|User Input| AppController

    AppController -->|"postMessage(params)"| WorkerGeneral
    AppController -->|"postMessage(params)"| WorkerMC
    AppController -->|"importScripts / Loader"| WorkerLoader

    WorkerGeneral -->|"postMessage(results)"| AppController
    WorkerMC -->|"postMessage(results)"| AppController
    WorkerLoader -->|"postMessage(results)"| AppController

    AppController -->|"invoke D3 routines"| VizEngine
    VizEngine -->|DOM Rendering| AppController

    %% Click Events
    click Index "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/index.html"
    click TariffUI "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/tariff-simulator.html"
    click ABMUI "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/abm-ca-simulations.html"
    click Backup1 "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/tariffs-impact-simulation-backup30042025.html"
    click Backup2 "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/tariffs-impact-simulation_backup28042025.html"
    click Backup3 "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/tariffs-simu-chaostheory-entropy-ga.html"
    click AppController "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/script.js"
    click WorkerGeneral "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/worker.js"
    click WorkerMC "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/worker-simu.js"
    click WorkerLoader "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/worker_tariff-simulator.html.js"
    click README "https://github.com/dnzengou/tariffs-impact-simulation-game/blob/main/README.md"

    %% Styles
    classDef host fill:#dddddd,stroke:#999,stroke-width:1px,color:#333;
    classDef ui fill:#cce5ff,stroke:#3399ff,stroke-width:1px,color:#03396c;
    classDef controller fill:#e6ffe6,stroke:#33cc33,stroke-width:1px,color:#006600;
    classDef compute fill:#d5f5e3,stroke:#28a745,stroke-width:1px,color:#155724;
    classDef viz fill:#fff3cd,stroke:#ffc107,stroke-width:1px,color:#856404;
```
