# ignromanov/big-decimal architecture

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

- Interactive diagram: https://gitdiagram.com/ignromanov/big-decimal
- Repository: https://github.com/ignromanov/big-decimal

## Overview

##### Main Components Identification

The system should be represented as a modular library with these core components:

a) Core Layer:
- Base Module (Abstract implementations and types)
- Config Module (Configuration and rounding modes)
- Implementations Module (Concrete implementations)

b) Operations Layer:
- Formatting Operations
- Mathematical Operations (implied by the README's API section)

c) Utils Layer:
- Parsing Utilities

d) Error Handling System:
- Various Error Types (Decimal, Factory, etc.)

**┌─ External Interface Layer ─────────────────┐**
- (Public API - BigDecimal & BD namespace)   │
- ┬───────────────────────┘
- ↓
**┌─ Core Layer ──────────────────────────────┐**
- ┌─────────────┐ ┌──────────┐ ┌──────────┐ │
- Base Abstract│ │  Config  │ │   Impl   │ │
- ┘ └──────────┘ └──────────┘ │
- ┬───────────────────────┘
- ↓
**┌─ Operations Layer ────────────────────────┐**
- ┌─────────────┐ ┌──────────────────────┐ │
- Formatting  │ │ Mathematical Ops      │ │
- ┘ └──────────────────────┘ │
- ┬───────────────────────┘
- ↓
**┌─ Utils Layer ──────────────────────────────┐**
- ┌─────────────┐                           │
- Parsing   │                           │
- ┘                           │
- ┬───────────────────────┘
- ↓
**┌─ Error Handling Layer ──────────────────────┐**
- ┌─────────────┐ ┌──────────┐ ┌──────────┐  │
- Decimal Error│ │Factory Er│ │Type Error │  │
- ┘ └──────────┘ └──────────┘  │
- ┘

##### Key Architectural Patterns to Highlight

- Immutable data pattern (all operations return new instances)
- Factory pattern (static creation methods)
- Strategy pattern (for different rounding modes)
- Chain of responsibility (for operation handling)

##### Implementation Details

- Tree-shaking support indication
- TypeScript type safety implementation
- Arbitrary precision handling mechanism
- Error handling flow

##### The type safety system

- How the different components interact
- The flow of data through the system
- Where to find specific functionality
- How to extend the system
- The error handling mechanisms
- The type safety implementation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Interface["External Interface Layer"]
        API["BigDecimal & BD Namespace"]:::interface
    end

    subgraph Core["Core Layer"]
        direction TB
        Base["Base Module"]:::core
        Config["Config Module"]:::core
        Impl["Implementations Module"]:::core
        
        subgraph BaseDetails["Base Components"]
            direction TB
            Abstract["Abstract Implementation"]:::core
            Types["Types Namespace"]:::core
        end
        
        subgraph ConfigDetails["Configuration Components"]
            direction TB
            ConfigTypes["Configuration Types"]:::core
            RoundingModes["Rounding Modes"]:::core
        end
        
        Base --> BaseDetails
        Config --> ConfigDetails
    end

    subgraph Ops["Operations Layer"]
        direction TB
        Format["Formatting Operations"]:::ops
        Math["Mathematical Operations"]:::ops
        
        subgraph FormatDetails["Formatting Components"]
            ToString["ToString Implementation"]:::ops
        end
        
        Format --> FormatDetails
    end

    subgraph Utils["Utils Layer"]
        Parse["Parsing Utilities"]:::utils
    end

    subgraph Errors["Error Handling Layer"]
        direction TB
        DecimalErr["Decimal Errors"]:::error
        FactoryErr["Factory Errors"]:::error
        TypeError["Type Errors"]:::error
        ErrorCodes["Error Codes"]:::error
    end

    Interface --> Core
    Core --> Ops
    Ops --> Utils
    Core --> Utils
    Utils --> Errors
    Ops --> Errors
    Core --> Errors

    classDef interface fill:#2374ab,stroke:#2374ab,color:white
    classDef core fill:#57a773,stroke:#57a773,color:white
    classDef ops fill:#ffc857,stroke:#ffc857,color:black
    classDef utils fill:#ff7f51,stroke:#ff7f51,color:white
    classDef error fill:#ef476f,stroke:#ef476f,color:white

    %% Click events for component mapping
    click API "https://github.com/ignromanov/big-decimal/blob/main/src/index.ts"
    click Base "https://github.com/ignromanov/big-decimal/tree/main/src/core/base/"
    click Abstract "https://github.com/ignromanov/big-decimal/blob/main/src/core/base/abstract-decimal.methods.ts"
    click Types "https://github.com/ignromanov/big-decimal/blob/main/src/core/base/types.namespace.ts"
    click Config "https://github.com/ignromanov/big-decimal/tree/main/src/core/config/"
    click ConfigTypes "https://github.com/ignromanov/big-decimal/blob/main/src/core/config/config.types.ts"
    click RoundingModes "https://github.com/ignromanov/big-decimal/blob/main/src/core/config/rounding-modes.ts"
    click Impl "https://github.com/ignromanov/big-decimal/tree/main/src/core/implementations/"
    click Format "https://github.com/ignromanov/big-decimal/tree/main/src/operations/formatting/"
    click ToString "https://github.com/ignromanov/big-decimal/blob/main/src/operations/formatting/toString.ts"
    click Parse "https://github.com/ignromanov/big-decimal/tree/main/src/utils/parsing/"
    click DecimalErr "https://github.com/ignromanov/big-decimal/blob/main/src/errors/decimal.error.ts"
    click FactoryErr "https://github.com/ignromanov/big-decimal/blob/main/src/errors/factory.error.ts"
    click TypeError "https://github.com/ignromanov/big-decimal/blob/main/src/errors/types.error.ts"
    click ErrorCodes "https://github.com/ignromanov/big-decimal/blob/main/src/errors/codes.error.ts"
```
