# davidfranco3/intl-currency-helper architecture

> Architecture diagram of the GitHub repository davidfranco3/intl-currency-helper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davidfranco3/intl-currency-helper
- Repository: https://github.com/davidfranco3/intl-currency-helper

## Overview

This repository is a small, single-purpose JavaScript package: a currency-formatting helper built on top of the native `Intl.NumberFormat` API. Its architecture is intentionally thin, with almost all behavior centered in a single formatting module and a small set of supporting utilities.

1. **Public API surface**
   - The package exports one core formatter, `formatCurrency`, plus convenience shorthands for common currencies: `formatMXN`, `formatUSD`, and `formatEUR`.
   - It also exports `configure`, which mutates shared defaults used by later formatting calls.
   - TypeScript consumers are supported through `index.d.ts`, which mirrors the runtime API.

2. **Entry-point boundary**
   - `index.js` is the package entry point and likely re-exports the library’s public functions.
   - This is the boundary between consumers and internal implementation details.
   - The README indicates the library is meant to be imported directly from the package root, so the internal module layout is hidden from users.

3. **Formatting pipeline**
   - The core data flow is: input amount + options → validation/normalization → `Intl.NumberFormat` formatting → optional currency code suffix.
   - The formatter appears to support both explicit per-call options and globally configured defaults.
   - The final string output is the only product of the library; there are no side effects beyond optional global configuration.

4. **Global configuration model**
   - `configure(...)` establishes process-wide defaults for currency and locale.
   - This means the library has a shared state layer, but it is intentionally narrow: it only affects subsequent formatting calls.
   - In an architecture diagram, this is the main mutable state boundary in an otherwise stateless formatter.

5. **Locale and currency abstractions**
   - The README references `CURRENCIES` and `LOCALES`, which suggests the library exposes constants/enums for common values.
   - These constants form a small configuration vocabulary that reduces string literals in consumer code.
   - The formatting engine still accepts raw locale and currency strings, so the abstraction is convenience-oriented rather than restrictive.

6. **Validation and normalization**
   - The library advertises input validation, so numeric inputs and option values are checked before formatting.
   - `utils.js` is the likely home for this shared logic: coercion, defaults, validation, and any helper functions used by both the core formatter and shorthand wrappers.
   - This is a clear internal utility boundary separate from the public API.

7. **Shorthand wrappers**
   - `formatMXN`, `formatUSD`, and `formatEUR` are thin convenience layers over the core formatter.
   - Their role is to prefill currency and, in some cases, locale defaults while still allowing override options.
   - In a diagram, these should be shown as wrappers feeding into the same core formatting path rather than separate subsystems.

8. **Platform/runtime scope**
   - The package is runtime-agnostic and depends only on standard JavaScript internationalization support.
   - It is explicitly compatible with both Node.js and browser/React environments, which means there is no framework coupling and no server/client split in the architecture.
   - There are no external services, databases, or network calls.

9. **Dependency profile**
   - The project is zero-dependency, so all behavior is implemented in-repo.
   - That makes the architecture especially flat: one public entry point, one core formatter, one utility module, and type definitions/tests around them.

10. **Testing boundary**
   - `test.js` and `test_intl.js` indicate two layers of verification: general library behavior and Intl-specific behavior.
   - These tests likely validate formatting outputs, configuration behavior, and edge cases around locale/currency formatting.
   - For architecture purposes, tests are an outer quality gate around the formatting core.

11. **Package shape**
   - `package.json` defines the library metadata and package entry wiring.
   - Together with `index.js` and `index.d.ts`, it forms a standard publishable npm library structure rather than an application runtime.

12. **What is not in the architecture**
   - There are no UI components, routing layers, persistence layers, API clients, or background workers.
   - The entire repository is centered on a single deterministic transformation: numbers to localized currency strings.

If you are drawing this repository, the cleanest diagram is a small library box with:
- public API functions at the top,
- a shared configuration state,
- a core formatter using `Intl.NumberFormat`,
- a utility/helper layer for validation and defaults,
- and tests/type definitions surrounding the implementation.

Main entry points: [`index.js`](https://github.com/davidfranco3/intl-currency-helper/blob/master/index.js) (Entry point), [`utils.js`](https://github.com/davidfranco3/intl-currency-helper/blob/master/utils.js) (Utilities), [`package.json`](https://github.com/davidfranco3/intl-currency-helper/blob/master/package.json) (package.json), [`index.d.ts`](https://github.com/davidfranco3/intl-currency-helper/blob/master/index.d.ts) (index.d.ts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_package_json["package.json<br/>package metadata<br/>[package.json]"]
  node_index_js["Entry point<br/>[index.js]"]
  node_format_currency["formatCurrency<br/>formatter"]
  node_format_mxn["formatMXN<br/>wrapper"]
  node_format_usd["formatUSD<br/>wrapper"]
  node_format_eur["formatEUR<br/>wrapper"]
  node_index_dts["index.d.ts<br/>types<br/>[index.d.ts]"]
end

subgraph group_core["Core formatting"]
  node_configure["configure<br/>state setter"]
  node_shared_defaults(("Defaults<br/>shared state"))
  node_utils_js["Utilities<br/>helper module<br/>[utils.js]"]
  node_intl_number_format["Intl.NumberFormat<br/>runtime API"]
end

subgraph group_quality["Quality gates"]
  node_tests["Tests<br/>test suite"]
end

node_package_json -->|"entry"| node_index_js
node_index_js -->|"exports"| node_format_currency
node_index_js -->|"exports"| node_configure
node_index_js -->|"exports"| node_format_mxn
node_index_js -->|"exports"| node_format_usd
node_index_js -->|"exports"| node_format_eur
node_index_js -->|"typed by"| node_index_dts
node_format_mxn -->|"wraps"| node_format_currency
node_format_usd -->|"wraps"| node_format_currency
node_format_eur -->|"wraps"| node_format_currency
node_configure -->|"updates"| node_shared_defaults
node_format_currency -->|"reads"| node_shared_defaults
node_format_currency -->|"uses"| node_utils_js
node_utils_js -->|"feeds"| node_intl_number_format
node_format_currency -->|"formats"| node_intl_number_format
node_tests -->|"verifies"| node_index_js
node_tests -->|"verifies"| node_intl_number_format

click node_package_json "https://github.com/davidfranco3/intl-currency-helper/blob/master/package.json"
click node_index_js "https://github.com/davidfranco3/intl-currency-helper/blob/master/index.js"
click node_utils_js "https://github.com/davidfranco3/intl-currency-helper/blob/master/utils.js"
click node_index_dts "https://github.com/davidfranco3/intl-currency-helper/blob/master/index.d.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_package_json,node_index_js,node_format_currency,node_format_mxn,node_format_usd,node_format_eur,node_index_dts toneBlue
class node_configure,node_shared_defaults,node_utils_js,node_intl_number_format toneAmber
class node_tests toneMint
```

## Components

### Public API

Consumer-facing entry point, shorthands, and type surface.

- [package.json](https://github.com/davidfranco3/intl-currency-helper/blob/master/package.json): package metadata · Package metadata and publish wiring. · `package.json`
- [Entry point](https://github.com/davidfranco3/intl-currency-helper/blob/master/index.js): module · Root export surface for the package. · `index.js`
- **formatCurrency**: formatter · Core currency formatting API.
- **formatMXN**: wrapper · MXN convenience wrapper over the core formatter.
- **formatUSD**: wrapper · USD convenience wrapper over the core formatter.
- **formatEUR**: wrapper · EUR convenience wrapper over the core formatter.
- [index.d.ts](https://github.com/davidfranco3/intl-currency-helper/blob/master/index.d.ts): types · TypeScript declaration surface mirroring the runtime API. · `index.d.ts`

### Core formatting

Shared state and the formatting pipeline built on Intl.NumberFormat.

- **configure**: state setter · Mutates shared defaults for later formatting calls.
- **Defaults**: shared state · Process-wide currency and locale defaults.
- [Utilities](https://github.com/davidfranco3/intl-currency-helper/blob/master/utils.js): helper module · Validation, normalization, and shared helper logic. · `utils.js`
- **Intl.NumberFormat**: runtime API · Native internationalization formatter used for output rendering.

### Quality gates

Tests that verify library behavior and Intl-specific output.

- **Tests**: test suite · General behavior and Intl-specific verification.

## Connections

- package.json → Entry point: entry · Package metadata points consumers to the entry module.
- Entry point → formatCurrency: exports · Root module exposes the core formatter.
- Entry point → configure: exports · Root module exposes shared configuration.
- Entry point → formatMXN: exports · Root module exposes the MXN shorthand.
- Entry point → formatUSD: exports · Root module exposes the USD shorthand.
- Entry point → formatEUR: exports · Root module exposes the EUR shorthand.
- Entry point → index.d.ts: typed by · Declaration file mirrors the public runtime API.
- formatMXN → formatCurrency: wraps · Prefills currency before calling the core formatter.
- formatUSD → formatCurrency: wraps · Prefills currency before calling the core formatter.
- formatEUR → formatCurrency: wraps · Prefills currency before calling the core formatter.
- configure → Defaults: updates · Sets process-wide defaults for later calls.
- formatCurrency → Defaults: reads · Uses configured defaults when explicit options are absent.
- formatCurrency → Utilities: uses · Delegates validation and normalization to shared helpers.
- Utilities → Intl.NumberFormat: feeds · Prepares options for native formatting.
- formatCurrency → Intl.NumberFormat: formats · Produces the localized currency string via the native API.
- Tests → Entry point: verifies · Exercises the public API surface.
- Tests → Intl.NumberFormat: verifies · Checks Intl-specific formatting behavior.
