# klokare/decimal architecture

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

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

## Overview

This is a dependency-free Go library implementing .NET-compatible 96-bit fixed-point decimal values. Its main workflow is constructing or parsing a Decimal, performing arithmetic and rounding, then formatting or converting the result. It also provides JSON, binary/.NET-layout, and database/sql interoperability. The arithmetic excerpts are partial, so the graph shows the documented core/helper relationship without detailing individual arithmetic operations.

Main entry points: [`decimal.go`](https://github.com/klokare/decimal/blob/master/decimal.go) (Decimal API), [`parse.go`](https://github.com/klokare/decimal/blob/master/parse.go) (Parse values), [`encoding.go`](https://github.com/klokare/decimal/blob/master/encoding.go) (Text and binary encodings), [`format.go`](https://github.com/klokare/decimal/blob/master/format.go) (Format values)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_value_core["Decimal core"]
  node_decimal_api["Decimal API<br/>[decimal.go]"]
  node_arithmetic["Arithmetic core<br/>[calc.go]"]
  node_word_buffers["Word buffers<br/>[buf.go]"]
  node_errors["Errors and recovery<br/>[errors.go]"]
end

subgraph group_text_io["Text and formats"]
  node_parser["Parse values<br/>[parse.go]"]
  node_formatter["Format values<br/>[format.go]"]
  node_number_format["Number formats<br/>[numberformat.go]"]
end

subgraph group_interop["Interoperability"]
  node_encoding["Text and binary encodings<br/>[encoding.go]"]
  node_sql_adapter["SQL adapter<br/>[sql.go]"]
end

node_caller(("Go caller"))
node_json_consumer(("JSON consumer"))
node_sql_driver(("SQL driver"))
node_dotnet_peer((".NET peer"))

node_caller -->|"constructs and operates"| node_decimal_api
node_caller -->|"parses text"| node_parser
node_parser -->|"builds values"| node_decimal_api
node_decimal_api -->|"uses arithmetic"| node_arithmetic
node_arithmetic -->|"uses word operations"| node_word_buffers
node_decimal_api -->|"reports failures"| node_errors
node_parser -->|"reports syntax errors"| node_errors
node_caller -->|"formats values"| node_formatter
node_formatter -->|"uses symbols and patterns"| node_number_format
node_formatter -->|"reports format errors"| node_errors
node_decimal_api -->|"provides value encoding"| node_encoding
node_encoding -->|"formats text"| node_formatter
node_encoding -->|"parses text"| node_parser
node_json_consumer -->|"marshals and unmarshals"| node_encoding
node_sql_driver -->|"scans and values"| node_sql_adapter
node_sql_adapter -->|"converts values"| node_decimal_api
node_sql_adapter -->|"parses text values"| node_parser
node_caller -->|"uses SQL values"| node_sql_adapter
node_dotnet_peer -->|"exchanges .NET bytes"| node_encoding

click node_decimal_api "https://github.com/klokare/decimal/blob/master/decimal.go"
click node_arithmetic "https://github.com/klokare/decimal/blob/master/calc.go"
click node_word_buffers "https://github.com/klokare/decimal/blob/master/buf.go"
click node_errors "https://github.com/klokare/decimal/blob/master/errors.go"
click node_parser "https://github.com/klokare/decimal/blob/master/parse.go"
click node_formatter "https://github.com/klokare/decimal/blob/master/format.go"
click node_number_format "https://github.com/klokare/decimal/blob/master/numberformat.go"
click node_encoding "https://github.com/klokare/decimal/blob/master/encoding.go"
click node_sql_adapter "https://github.com/klokare/decimal/blob/master/sql.go"

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_decimal_api,node_arithmetic,node_word_buffers,node_errors toneBlue
class node_parser,node_formatter,node_number_format toneAmber
class node_encoding,node_sql_adapter toneMint
class node_caller,node_json_consumer,node_sql_driver,node_dotnet_peer toneIndigo
```

## Components

### Decimal core

- [Decimal API](https://github.com/klokare/decimal/blob/master/decimal.go): `decimal.go`
- [Arithmetic core](https://github.com/klokare/decimal/blob/master/calc.go): `calc.go`
- [Word buffers](https://github.com/klokare/decimal/blob/master/buf.go): `buf.go`
- [Errors and recovery](https://github.com/klokare/decimal/blob/master/errors.go): `errors.go`

### Text and formats

- [Parse values](https://github.com/klokare/decimal/blob/master/parse.go): `parse.go`
- [Format values](https://github.com/klokare/decimal/blob/master/format.go): `format.go`
- [Number formats](https://github.com/klokare/decimal/blob/master/numberformat.go): `numberformat.go`

### Interoperability

- [Text and binary encodings](https://github.com/klokare/decimal/blob/master/encoding.go): `encoding.go`
- [SQL adapter](https://github.com/klokare/decimal/blob/master/sql.go): `sql.go`

### Other components

- **Go caller**
- **JSON consumer**
- **SQL driver**
- **.NET peer**

## Connections

- Go caller → Decimal API: constructs and operates
- Go caller → Parse values: parses text
- Parse values → Decimal API: builds values
- Decimal API → Arithmetic core: uses arithmetic
- Arithmetic core → Word buffers: uses word operations
- Decimal API → Errors and recovery: reports failures
- Parse values → Errors and recovery: reports syntax errors
- Go caller → Format values: formats values
- Format values → Number formats: uses symbols and patterns
- Format values → Errors and recovery: reports format errors
- Decimal API → Text and binary encodings: provides value encoding
- Text and binary encodings → Format values: formats text
- Text and binary encodings → Parse values: parses text
- JSON consumer → Text and binary encodings: marshals and unmarshals
- SQL driver → SQL adapter: scans and values
- SQL adapter → Decimal API: converts values
- SQL adapter → Parse values: parses text values
- Go caller → SQL adapter: uses SQL values
- .NET peer → Text and binary encodings: exchanges .NET bytes
