# jundayw/message-pack-codec architecture

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

- Interactive diagram: https://gitdiagram.com/jundayw/message-pack-codec
- Repository: https://github.com/jundayw/message-pack-codec

## Overview

MessagePackCodec is a PHP library for declaratively encoding and decoding binary records. The principal workflow begins with an application supplying data or binary plus a field schema to MessagePackCodec, which resolves each field’s type and context-dependent options, then invokes type-specific packing or unpacking and returns a message object. The tree also documents numeric, bit, string, BCD, and other byte-oriented field types; only selected implementations were sampled, so their internal wiring is shown at the shared type layer rather than inferred individually.

Main entry points: [`src/MessagePackCodec.php`](https://github.com/jundayw/message-pack-codec/blob/main/src/MessagePackCodec.php) (Codec orchestrator), [`src/Concerns/Type.php`](https://github.com/jundayw/message-pack-codec/blob/main/src/Concerns/Type.php) (Shared type engine), [`src/Support/Format.php`](https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Format.php) (Binary formats), [`src/Context/EncodeContext.php`](https://github.com/jundayw/message-pack-codec/blob/main/src/Context/EncodeContext.php) (Encode context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Codec API"]
  node_codec["Codec orchestrator"]
  node_message_bag["Message and bags<br/>[Bag.php]"]
  node_encode_message["Encoded message<br/>[EncodeMessage.php]"]
  node_decode_message["Decoded message<br/>[DecodeMessage.php]"]
end

subgraph group_runtime["Field Runtime"]
  node_encode_context["Encode context<br/>[EncodeContext.php]"]
  node_decode_context["Decode context<br/>[DecodeContext.php]"]
  node_context_contract["Context contract<br/>[Context.php]"]
  node_type_contract["Type contract<br/>[Type.php]"]
  node_type_base["Shared type engine<br/>[Type.php]"]
end

subgraph group_types["Binary Types"]
  node_type_families["Field type families"]
  node_string_type["String type<br/>[StringType.php]"]
  node_bit_type["Bit type<br/>[BitType.php]"]
end

subgraph group_support["Encoding Support"]
  node_format["Binary formats<br/>[Format.php]"]
  node_endian["Byte order<br/>[Endian.php]"]
  node_helper_formats["Endian helpers<br/>[Endian.php]"]
end

node_application(("PHP application"))
node_encode_input["Data and schema"]
node_decode_input["Binary and schema"]
node_encoded_output["Encoded bytes"]
node_decoded_output["Decoded values"]

node_application -->|"calls encode/decode"| node_codec
node_application -->|"supplies data"| node_encode_input
node_application -->|"supplies binary"| node_decode_input
node_encode_input -->|"passes fields"| node_codec
node_decode_input -->|"passes fields"| node_codec
node_codec -->|"creates context"| node_encode_context
node_codec -->|"creates context"| node_decode_context
node_codec -->|"instantiates configured"| node_type_families
node_codec -->|"resolves and invokes"| node_type_base
node_type_families -->|"implements"| node_type_contract
node_type_base -->|"implements"| node_type_contract
node_type_base -->|"packs by format"| node_format
node_type_base -->|"resolves options"| node_encode_context
node_type_base -->|"resolves options"| node_decode_context
node_string_type -->|"extends"| node_type_base
node_bit_type -->|"extends"| node_type_base
node_string_type -->|"selects format"| node_format
node_bit_type -->|"selects format"| node_format
node_format -->|"reports byte order"| node_endian
node_endian -->|"defines order"| node_helper_formats
node_encode_context -->|"stores input and options"| node_message_bag
node_decode_context -->|"stores options and schema"| node_message_bag
node_codec -->|"writes field results"| node_encode_message
node_codec -->|"writes field results"| node_decode_message
node_encode_message -->|"returns bytes"| node_encoded_output
node_decode_message -->|"returns values"| node_decoded_output
node_codec -->|"returns message"| node_application

click node_codec "https://github.com/jundayw/message-pack-codec/blob/main/src/MessagePackCodec.php"
click node_encode_context "https://github.com/jundayw/message-pack-codec/blob/main/src/Context/EncodeContext.php"
click node_decode_context "https://github.com/jundayw/message-pack-codec/blob/main/src/Context/DecodeContext.php"
click node_context_contract "https://github.com/jundayw/message-pack-codec/blob/main/src/Contract/Context.php"
click node_message_bag "https://github.com/jundayw/message-pack-codec/blob/main/src/Message/Bag.php"
click node_encode_message "https://github.com/jundayw/message-pack-codec/blob/main/src/Message/EncodeMessage.php"
click node_decode_message "https://github.com/jundayw/message-pack-codec/blob/main/src/Message/DecodeMessage.php"
click node_type_contract "https://github.com/jundayw/message-pack-codec/blob/main/src/Contract/Type.php"
click node_type_base "https://github.com/jundayw/message-pack-codec/blob/main/src/Concerns/Type.php"
click node_type_families "https://github.com/jundayw/message-pack-codec/tree/main/src/Type"
click node_string_type "https://github.com/jundayw/message-pack-codec/blob/main/src/Type/StringType.php"
click node_bit_type "https://github.com/jundayw/message-pack-codec/blob/main/src/Type/BitType.php"
click node_format "https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Format.php"
click node_endian "https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Endian.php"
click node_helper_formats "https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Endian.php"

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_codec,node_message_bag,node_encode_message,node_decode_message toneBlue
class node_encode_context,node_decode_context,node_context_contract,node_type_contract,node_type_base toneAmber
class node_type_families,node_string_type,node_bit_type toneMint
class node_format,node_endian,node_helper_formats toneRose
class node_application,node_encode_input,node_decode_input,node_encoded_output,node_decoded_output toneIndigo
```

## Components

### Codec API

- [Codec orchestrator](https://github.com/jundayw/message-pack-codec/blob/main/src/MessagePackCodec.php): `src/MessagePackCodec.php`
- [Message and bags](https://github.com/jundayw/message-pack-codec/blob/main/src/Message/Bag.php): `src/Message/Bag.php`
- [Encoded message](https://github.com/jundayw/message-pack-codec/blob/main/src/Message/EncodeMessage.php): `src/Message/EncodeMessage.php`
- [Decoded message](https://github.com/jundayw/message-pack-codec/blob/main/src/Message/DecodeMessage.php): `src/Message/DecodeMessage.php`

### Field Runtime

- [Encode context](https://github.com/jundayw/message-pack-codec/blob/main/src/Context/EncodeContext.php): `src/Context/EncodeContext.php`
- [Decode context](https://github.com/jundayw/message-pack-codec/blob/main/src/Context/DecodeContext.php): `src/Context/DecodeContext.php`
- [Context contract](https://github.com/jundayw/message-pack-codec/blob/main/src/Contract/Context.php): `src/Contract/Context.php`
- [Type contract](https://github.com/jundayw/message-pack-codec/blob/main/src/Contract/Type.php): `src/Contract/Type.php`
- [Shared type engine](https://github.com/jundayw/message-pack-codec/blob/main/src/Concerns/Type.php): `src/Concerns/Type.php`

### Binary Types

- [Field type families](https://github.com/jundayw/message-pack-codec/tree/main/src/Type): `src/Type`
- [String type](https://github.com/jundayw/message-pack-codec/blob/main/src/Type/StringType.php): `src/Type/StringType.php`
- [Bit type](https://github.com/jundayw/message-pack-codec/blob/main/src/Type/BitType.php): `src/Type/BitType.php`

### Encoding Support

- [Binary formats](https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Format.php): `src/Support/Format.php`
- [Byte order](https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Endian.php): `src/Support/Endian.php`
- [Endian helpers](https://github.com/jundayw/message-pack-codec/blob/main/src/Support/Endian.php): `src/Support/Endian.php`

### Other components

- **PHP application**
- **Data and schema**
- **Binary and schema**
- **Encoded bytes**
- **Decoded values**

## Connections

- PHP application → Codec orchestrator: calls encode/decode
- PHP application → Data and schema: supplies data
- PHP application → Binary and schema: supplies binary
- Data and schema → Codec orchestrator: passes fields
- Binary and schema → Codec orchestrator: passes fields
- Codec orchestrator → Encode context: creates context
- Codec orchestrator → Decode context: creates context
- Codec orchestrator → Field type families: instantiates configured
- Codec orchestrator → Shared type engine: resolves and invokes
- Field type families → Type contract: implements
- Shared type engine → Type contract: implements
- Shared type engine → Binary formats: packs by format
- Shared type engine → Encode context: resolves options
- Shared type engine → Decode context: resolves options
- String type → Shared type engine: extends
- Bit type → Shared type engine: extends
- String type → Binary formats: selects format
- Bit type → Binary formats: selects format
- Binary formats → Byte order: reports byte order
- Byte order → Endian helpers: defines order
- Encode context → Message and bags: stores input and options
- Decode context → Message and bags: stores options and schema
- Codec orchestrator → Encoded message: writes field results
- Codec orchestrator → Decoded message: writes field results
- Encoded message → Encoded bytes: returns bytes
- Decoded message → Decoded values: returns values
- Codec orchestrator → PHP application: returns message
