How mikebryant/ac-nh-turnip-prices works
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.