# rubymoney/money architecture

> Architecture diagram of the GitHub repository rubymoney/money, 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/rubymoney/money
- Repository: https://github.com/rubymoney/money

## Overview

##### Project type and purpose
- This is a Ruby library (a gem) named Money for representing, manipulating, formatting, and converting monetary values. It is not a full-stack web app but a domain library with clear internal modules and extension points.

##### File structure
Top-level directories and files:
- lib/money – source code, subdivided into:
– bank (exchange logic: Base, SingleCurrency, VariableExchange)
– currency (currency metadata, loader, heuristics)
– locale_backend (formatting backends: I18n, legacy)
– money (core Money class: arithmetic, allocation, constructors, formatting)
– rates_store (in-memory store)
– version.rb
- config – JSON currency definitions (ISO, backward compatibility, non-ISO)
- sig – RBS signatures mirroring lib structure (for static typing)
- spec – RSpec tests covering every module
- Gemfile, Rakefile, README, CI workflows, LICENSE, etc.

##### README for additional insights
- Describes core features: Money and Currency classes, integer-cents storage, exchange via banks & stores, formatting backends, extensibility for custom banks or stores.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    subgraph "Core Modules" 
        direction TB
        MoneyAPI["Money API"]
    end

    %% Currency Subsystem
    subgraph "Currency Subsystem"
        direction TB
        Currency["Currency Subsystem"]
    end

    %% Exchange Bank Subsystem
    subgraph "Exchange Bank Subsystem"
        direction TB
        Bank["Exchange Bank"]
    end

    %% Rate Store Subsystem
    subgraph "Rate Store Subsystem"
        direction TB
        RateStore["Rate Store"]
    end

    %% Locale Backend Subsystem
    subgraph "Locale Backend Subsystem"
        direction TB
        LocaleBackend["Locale Backend"]
    end

    %% External Integrations
    subgraph "External Integrations"
        direction TB
        I18nExt["I18n Integration"]
        CustomStore["Custom Store (ActiveRecord/Redis)"]
    end

    Caller["Caller"]:::external

    %% Relationships
    Caller -->|"uses"| MoneyAPI
    MoneyAPI -->|"loads metadata"| Currency
    MoneyAPI -->|"delegates exchange"| Bank
    MoneyAPI -->|"formats via"| LocaleBackend
    Bank -->|"gets rate"| RateStore
    RateStore -->|"adapter to"| CustomStore
    LocaleBackend -->|"calls"| I18nExt

    %% Click Events
    click MoneyAPI "https://github.com/rubymoney/money/blob/main/lib/money/money.rb"
    click Currency "https://github.com/rubymoney/money/blob/main/lib/money/currency.rb"
    click Bank "https://github.com/rubymoney/money/blob/main/lib/money/bank/base.rb"
    click RateStore "https://github.com/rubymoney/money/blob/main/lib/money/rates_store/memory.rb"
    click LocaleBackend "https://github.com/rubymoney/money/blob/main/lib/money/locale_backend/base.rb"
    click I18nExt "https://github.com/rubymoney/money/blob/main/lib/money/locale_backend/i18n.rb"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:1px
    classDef currency fill:#ff9,stroke:#333,stroke-width:1px
    classDef exchange fill:#9ff,stroke:#333,stroke-width:1px
    classDef ratestore fill:#cfc,stroke:#333,stroke-width:1px
    classDef locale fill:#fcf,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px

    class MoneyAPI core
    class Currency currency
    class Bank exchange
    class RateStore ratestore
    class LocaleBackend locale
    class I18nExt,CustomStore external
```
