# besrourms/gold-price-converter architecture

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

- Interactive diagram: https://gitdiagram.com/besrourms/gold-price-converter
- Repository: https://github.com/besrourms/gold-price-converter

## Overview

##### Main Components
- GoldPriceConverter Class:
- Represents the core logic of the library.
- Contains the constructor (that accepts usdPerOunce, exchangeRate, precision, currencyCode) and the method getGoldPricesPerGram().
- Encapsulates the conversion formulas and input validations.
- Input Validation:
- This might be shown as an internal component or sub-module within GoldPriceConverter that ensures the parameters meet the necessary conditions.
- Conversion Logic Unit:
- The part responsible for calculating conversion from USD/ounce to target currency/gram by handling different gold karats.
- Output:
- The results object that returns prices for 24K, 21K, 18K, and 14K.
- External Interface / Usage:

##### Relationships/Interactions
- Gold price in USD per ounce.
- Exchange rate.
- Optional precision and currency code.
- Inside this block, include a validation sub-component that verifies:
- usdPerOunce and exchangeRate are positive finite numbers.
- Precision is a non-negative integer.
- The currency code is a non-empty string.
- Next, the “Conversion Logic” part of the block processes the validated inputs to compute values for each gold karat.
- Finally, the processed output (an object containing conversions for 24K, 21K, 18K, and 14K) is returned and can be used in an application or logged.

##### Architectural Patterns & Design Principles
- Modularity:
- The system is highly modular with the conversion logic encapsulated in a standalone JavaScript class.
- Single Responsibility:
- The GoldPriceConverter class has a clear purpose: performing gold price conversions.
- Input Validation:
- Built-in robust error handling ensures the correctness of the inputs before converting.
- No External Dependencies:
- This makes the design lightweight and easy to integrate into multiple environments (Node.js, browser, etc.).

##### Relevant Technologies and Frameworks
- JavaScript (Node.js/ES6):
- The design will note usage in these environments.
- No external libraries are involved (as per the README).

##### Adding Extra Detail
- To capture any potential error flows:
- A note showing configuration options like rounding precision.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Inputs
    Input["Input: (usdPerOunce,exchangeRate,precision,currencyCode)"]:::external
    ExternalInterface["External Interface/Usage (ES6,CommonJS,Browser)"]:::external

    %% GoldPriceConverter Subgraph
    subgraph "GoldPriceConverter"
        GPC["GoldPriceConverter Class"]:::converter
        GPC --> validator["Input Validation"]:::validation
        validator --> conversion["Conversion Logic"]:::logic
        conversion --> output["Output: {24K,21K,18K,14K}"]:::output
        %% Error Flow from Validation Failure
        validator -- "throwsError"--> error["Error: Invalid Inputs"]:::error
    end

    %% Connections from External sources
    Input -->|"suppliesData"| GPC
    ExternalInterface -->|"importsModule"| GPC

    %% Click Events
    click GPC "https://github.com/besrourms/gold-price-converter/blob/main/index.js"
    click validator "https://github.com/besrourms/gold-price-converter/blob/main/index.js"
    click conversion "https://github.com/besrourms/gold-price-converter/blob/main/index.js"
    click output "https://github.com/besrourms/gold-price-converter/blob/main/index.js"
    click ExternalInterface "https://github.com/besrourms/gold-price-converter/blob/main/index.js"

    %% Styles
    classDef external fill:#bbf,stroke:#333,stroke-width:2px;
    classDef converter fill:#ffd,stroke:#333,stroke-width:2px;
    classDef validation fill:#faa,stroke:#333,stroke-width:2px;
    classDef logic fill:#afa,stroke:#333,stroke-width:2px;
    classDef output fill:#cfc,stroke:#333,stroke-width:2px;
    classDef error fill:#fdd,stroke:#f33,stroke-width:2px;
```
