# mikebryant/ac-nh-turnip-prices architecture

> Architecture diagram of the GitHub repository mikebryant/ac-nh-turnip-prices, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mikebryant/ac-nh-turnip-prices
- Repository: https://github.com/mikebryant/ac-nh-turnip-prices

## Overview

##### Project Type and Purpose
- This is a single-page web application (SPA) focused on predicting turnip prices in Animal Crossing: New Horizons.
- It is entirely client-side with no backend. User interaction, data handling, and even PWA features (offline support, caching) are managed within the browser.
- The README makes it clear that the app is not designed to handle backend processes (like storing islands or multi-user data) but rather focuses on price prediction via JavaScript.

##### File Structure Analysis
- Top-level files include index.html (main entry point), manifest.json, and service-worker.js, which indicate Progressive Web App (PWA) functionality.
- The “css” directory holds stylesheet(s) for presentation.
- The “js” directory contains multiple JavaScript modules:
- scripts.js likely manages the general logic.
- predictions.js probably contains the core logic related to computing turnip price predictions.
- chart.js hints at graphical representation (charts/graphs) of the data.
- translations.js along with the “locales” folder (with multiple language JSON files) indicate that the app supports internationalization.
- themes.js and contributors.js add additional UI theming and credits functionality.
- Additionally, standard repository files (.github, LICENSE, README, etc.) facilitate project management and open-source contributions.

##### Architecture and Component Breakdown
a. The Browser Client:
- The main user interface rendered from index.html.
- CSS (css/styles.css) for styling.
- JavaScript modules (js/scripts.js, js/predictions.js, js/chart.js, etc.) that drive interactivity.
b. PWA Components:
- manifest.json defining the app’s PWA characteristics.
- service-worker.js for caching assets and enabling offline functionality.
c. Internationalization:
- The locales folder (with JSON files per language) which is read/used by js/translations.js to display the user interface in different languages.
d. Static Assets:
- Image assets in the img folder.
- Any additional assets like CNAME (for custom domain configuration).

##### Relationships and Interactions
- The browser loads index.html, which in turn loads CSS and JavaScript files.
- JavaScript files interact with the DOM and determine app logic. For instance, predictions.js calculates price probabilities and chart.js visualizes them.
- translations.js dynamically loads the correct language file from the locales folder based on user selection or browser settings.
- The service worker intercepts network requests to serve cached files (from index.html, CSS, JS, and locale JSON files), thus enabling the offline mode as defined by the manifest.json.

##### Architectural Patterns and Design Principles
- The project exhibits a modular design, with separate JavaScript files handling distinct functionalities, which is akin to dividing responsibilities (clean separation of concerns).
- Given it is a SPA with PWA features, it is built with the progressive enhancement and client-side routing in mind.
- Internationalization is explicitly handled via the separate locales directory and a dedicated translations module, emphasizing support for multiple languages.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Client Subgraph
    subgraph "Browser Client"
        A["HTML Shell (index.html)"]:::ui
        B["CSS Styling (styles.css)"]:::ui
        subgraph "JavaScript Modules"
            C["General Application Logic (scripts.js)"]:::js
            D["Price Prediction Engine (predictions.js)"]:::js
            E["Data Visualization (chart.js)"]:::js
            F["Internationalization (translations.js)"]:::js
            F1["Language Files (locales)"]:::js
            G["Theming (themes.js)"]:::js
            H["Contributors (contributors.js)"]:::js
        end
    end

    %% PWA Components Subgraph
    subgraph "PWA Components"
        I["PWA Manifest (manifest.json)"]:::pwa
        J["Service Worker (service-worker.js)"]:::pwa
    end

    %% Static Assets Subgraph
    subgraph "Static Assets"
        K["Static Assets: Images (img/)"]:::assets
        L["Domain Config (CNAME)"]:::assets
    end

    %% Connections within Browser Client
    A -->|"loads"| B
    A -->|"loads"| C
    A -->|"loads"| F
    A -->|"loads"| G
    A -->|"loads"| H
    C -->|"triggers"| D
    D -->|"sendsDataTo"| E
    F -->|"fetches"| F1

    %% Connections involving PWA Components
    A -->|"registers"| I
    I -->|"activates"| J
    J -->|"caches"| A
    J -->|"caches"| B
    J -->|"caches"| C
    J -->|"caches"| D
    J -->|"caches"| E
    J -->|"caches"| F1
    J -->|"caches"| K
    J -->|"caches"| L

    %% Click Events for Browser Client
    click A "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/index.html"
    click B "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/css/styles.css"
    click C "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/js/scripts.js"
    click D "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/js/predictions.js"
    click E "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/js/chart.js"
    click F "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/js/translations.js"
    click F1 "https://github.com/mikebryant/ac-nh-turnip-prices/tree/master/locales/"
    click G "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/js/themes.js"
    click H "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/js/contributors.js"

    %% Click Events for PWA Components
    click I "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/manifest.json"
    click J "https://github.com/mikebryant/ac-nh-turnip-prices/blob/master/service-worker.js"

    %% Click Events for Static Assets
    click K "https://github.com/mikebryant/ac-nh-turnip-prices/tree/master/img/"
    click L "https://github.com/mikebryant/ac-nh-turnip-prices/tree/master/CNAME"

    %% Styles
    classDef ui fill:#f9d,stroke:#333,stroke-width:2px;
    classDef js fill:#9df,stroke:#333,stroke-width:2px;
    classDef pwa fill:#cfc,stroke:#333,stroke-width:2px;
    classDef assets fill:#ffd,stroke:#333,stroke-width:2px;
```
