# pek/jsno architecture

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

- Interactive diagram: https://gitdiagram.com/pek/jsno
- Repository: https://github.com/pek/jsno

## Overview

#### Purpose and public API
`jsno` is a dependency-free Python library that converts arbitrary supported Python values to JSON-compatible trees and reconstructs typed values from those trees. It deliberately delegates JSON text encoding/decoding to the standard library. Public package exports and convenience APIs are rooted in `jsno/__init__.py`; primary entry points are implemented in `jsno/jsonify.py`, `jsno/unjsonify.py`, and likely JSON-string wrappers in `jsno/jsonize.py`.

#### Serialization dispatch
`jsonify` is the outbound recursive conversion engine. It uses `singledispatch`, allowing built-in handlers and consumers to register serializers per concrete type. Native JSON values pass through; containers and domain objects recursively become lists, dictionaries, strings, or scalar JSON values. Type-family handlers are separated by concern in `jsno/standard.py`, `jsno/datetime.py`, `jsno/tuple.py`, and `jsno/abc.py`.

#### Typed deserialization dispatch
`unjsonify` is the inbound, target-type-driven engine: callers select a decoder through bracket syntax (for example, `unjsonify[MyType](data)`). Its dispatch and target-type interpretation live in `jsno/unjsonify.py`, with annotation/type-introspection support in `jsno/utils.py` and field-level decoding in `jsno/fields_unjsonifier.py`. This is the key boundary: JSON-compatible input is untyped, while output is validated and constructed according to Python type metadata.

#### Structured model reconstruction
Dataclasses are serialized as JSON objects and reconstructed from resolved field annotations. The decoder handles recursive/future annotations, optional and union-like typing, field naming, defaults, and unexpected-key policy. Relevant model features are distributed across `jsno/unjsonify.py`, `jsno/property_name.py`, and `jsno/extra_data.py`. Extra JSON keys normally cause an unjsonification error; context can instead ignore them, supporting backward-compatible persisted data.

#### Type-system extensions and validation
The library recognizes typing constructs beyond ordinary classes: `Annotated`, `Literal`, `TypedDict`, `NewType`, named tuples, unions, and schemas. `jsno/constraint.py` attaches boolean validation rules to annotations/classes and applies them after deserialization. `jsno/typeddict.py` implements TypedDict-specific shape semantics. These mechanisms make inbound conversion both structural and semantic rather than merely coercive.

#### Dynamic schemas and callable boundaries
`Schema` supports runtime-defined object shapes, including requiredness, ignored/typed extra fields, and extraction from function signatures for message-to-keyword-argument conversion. This enables integrations such as HTTP/event handler boundaries without defining a dataclass. The architecture is centered in `jsno/schema.py` and relies on `jsno/unjsonify.py` for actual value conversion.

#### Polymorphism and external boundaries
Variant families encode class identity into JSON object labels so a base type can be reconstructed as a registered subclass; this is implemented in `jsno/variant.py`. The package runs as a Python library (release notes indicate Python 3.13), has no third-party dependencies, and uses only standard-library facilities such as `json`, `dataclasses`, `typing`, datetime/path/UUID/regex support. Consumers provide persistence, APIs, files, or databases; jsno’s boundary output is JSON-compatible data or standard JSON strings through its convenience wrappers.

Main entry points: [`jsno/unjsonify.py`](https://github.com/pek/jsno/blob/main/jsno/unjsonify.py) (unjsonify[T]), [`jsno/jsonify.py`](https://github.com/pek/jsno/blob/main/jsno/jsonify.py) (jsonify), [`jsno/__init__.py`](https://github.com/pek/jsno/blob/main/jsno/__init__.py) (Package exports), [`jsno/fields_unjsonifier.py`](https://github.com/pek/jsno/blob/main/jsno/fields_unjsonifier.py) (Field decoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_package["Package exports<br/>public facade<br/>[__init__.py]"]
  node_jsonize["JSON string wrappers<br/>convenience API<br/>[jsonize.py]"]
end

subgraph group_outbound["Serialization"]
  node_jsonify["jsonify<br/>singledispatch encoder<br/>[jsonify.py]"]
  node_serializer_handlers["Type-family serializers<br/>registered handlers<br/>[standard.py]"]
end

subgraph group_inbound["Typed deserialization"]
  node_unjsonify["unjsonify&#91;T&#93;<br/>target-type decoder<br/>[unjsonify.py]"]
  node_type_utils["Type introspection<br/>annotation resolver<br/>[utils.py]"]
  node_field_decoder["Field decoder<br/>model field binding"]
  node_property_names["Property naming<br/>field mapping<br/>[property_name.py]"]
  node_extra_data["Extra-key policy<br/>decode context<br/>[extra_data.py]"]
end

subgraph group_models["Model extensions"]
  node_schemas["Schema<br/>[schema.py]"]
  node_typed_dicts["TypedDict support<br/>shape decoder<br/>[typeddict.py]"]
  node_constraints["Constraints<br/>semantic validator<br/>[constraint.py]"]
  node_variants["Variant families<br/>polymorphic codec<br/>[variant.py]"]
end

node_consumer(("Consumer application<br/>external caller"))
node_json_tree["JSON-compatible tree<br/>boundary data"]
node_typed_values["Typed Python values<br/>domain values"]

node_consumer -->|"imports API"| node_package
node_package -->|"exports"| node_jsonify
node_package -->|"exports"| node_unjsonify
node_package -->|"exports"| node_jsonize
node_consumer -->|"provides"| node_typed_values
node_typed_values -->|"serialize"| node_jsonify
node_jsonify -->|"dispatches by type"| node_serializer_handlers
node_jsonify -->|"produces"| node_json_tree
node_json_tree -->|"encodes or decodes"| node_jsonize
node_json_tree -->|"input data"| node_unjsonify
node_unjsonify -->|"resolves target metadata"| node_type_utils
node_unjsonify -->|"binds fields"| node_field_decoder
node_field_decoder -->|"maps keys"| node_property_names
node_field_decoder -->|"enforces key policy"| node_extra_data
node_unjsonify -->|"decodes TypedDicts"| node_typed_dicts
node_unjsonify -->|"executes schema conversion"| node_schemas
node_unjsonify -->|"validates result"| node_constraints
node_unjsonify -->|"reconstructs subtype"| node_variants
node_unjsonify -->|"constructs"| node_typed_values
node_variants -.->|"adds class label"| node_jsonify

click node_package "https://github.com/pek/jsno/blob/main/jsno/__init__.py"
click node_jsonize "https://github.com/pek/jsno/blob/main/jsno/jsonize.py"
click node_jsonify "https://github.com/pek/jsno/blob/main/jsno/jsonify.py"
click node_serializer_handlers "https://github.com/pek/jsno/blob/main/jsno/standard.py"
click node_unjsonify "https://github.com/pek/jsno/blob/main/jsno/unjsonify.py"
click node_type_utils "https://github.com/pek/jsno/blob/main/jsno/utils.py"
click node_field_decoder "https://github.com/pek/jsno/blob/main/jsno/fields_unjsonifier.py"
click node_property_names "https://github.com/pek/jsno/blob/main/jsno/property_name.py"
click node_extra_data "https://github.com/pek/jsno/blob/main/jsno/extra_data.py"
click node_schemas "https://github.com/pek/jsno/blob/main/jsno/schema.py"
click node_typed_dicts "https://github.com/pek/jsno/blob/main/jsno/typeddict.py"
click node_constraints "https://github.com/pek/jsno/blob/main/jsno/constraint.py"
click node_variants "https://github.com/pek/jsno/blob/main/jsno/variant.py"

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,node_jsonize toneBlue
class node_jsonify,node_serializer_handlers toneAmber
class node_unjsonify,node_type_utils,node_field_decoder,node_property_names,node_extra_data toneMint
class node_schemas,node_typed_dicts,node_constraints,node_variants toneRose
class node_consumer,node_json_tree,node_typed_values toneNeutral
```

## Components

### Public API

- [Package exports](https://github.com/pek/jsno/blob/main/jsno/__init__.py): public facade · `jsno/__init__.py`
- [JSON string wrappers](https://github.com/pek/jsno/blob/main/jsno/jsonize.py): convenience API · Delegates JSON text encoding and decoding to the standard library. · `jsno/jsonize.py`

### Serialization

- [jsonify](https://github.com/pek/jsno/blob/main/jsno/jsonify.py): singledispatch encoder · Recursively converts supported values into JSON-compatible trees. · `jsno/jsonify.py`
- [Type-family serializers](https://github.com/pek/jsno/blob/main/jsno/standard.py): registered handlers · Serializers for standard, datetime, tuple, and ABC types. · `jsno/standard.py`

### Typed deserialization

- [unjsonify[T]](https://github.com/pek/jsno/blob/main/jsno/unjsonify.py): target-type decoder · Interprets target types and constructs validated typed values. · `jsno/unjsonify.py`
- [Type introspection](https://github.com/pek/jsno/blob/main/jsno/utils.py): annotation resolver · Resolves typing constructs and recursive annotations. · `jsno/utils.py`
- [Field decoder](https://github.com/pek/jsno/blob/main/jsno/fields_unjsonifier.py): model field binding · Decodes resolved annotations for individual fields. · `jsno/fields_unjsonifier.py`
- [Property naming](https://github.com/pek/jsno/blob/main/jsno/property_name.py): field mapping · `jsno/property_name.py`
- [Extra-key policy](https://github.com/pek/jsno/blob/main/jsno/extra_data.py): decode context · Rejects or ignores unexpected object keys. · `jsno/extra_data.py`

### Model extensions

- [Schema](https://github.com/pek/jsno/blob/main/jsno/schema.py): runtime object schema · Defines dynamic shapes and maps messages to callable keyword arguments. · `jsno/schema.py`
- [TypedDict support](https://github.com/pek/jsno/blob/main/jsno/typeddict.py): shape decoder · `jsno/typeddict.py`
- [Constraints](https://github.com/pek/jsno/blob/main/jsno/constraint.py): semantic validator · Applies boolean annotation or class rules after decoding. · `jsno/constraint.py`
- [Variant families](https://github.com/pek/jsno/blob/main/jsno/variant.py): polymorphic codec · Encodes class labels and reconstructs registered subclasses. · `jsno/variant.py`

### Other components

- **Consumer application**: external caller · Supplies Python values or JSON-compatible data and target types.
- **JSON-compatible tree**: boundary data · Lists, objects, strings, and JSON scalars.
- **Typed Python values**: domain values · Dataclasses, typing constructs, schemas, and variant instances.

## Connections

- Consumer application → Package exports: imports API
- Package exports → jsonify: exports
- Package exports → unjsonify[T]: exports
- Package exports → JSON string wrappers: exports
- Consumer application → Typed Python values: provides
- Typed Python values → jsonify: serialize
- jsonify → Type-family serializers: dispatches by type
- jsonify → JSON-compatible tree: produces
- JSON-compatible tree → JSON string wrappers: encodes or decodes
- JSON-compatible tree → unjsonify[T]: input data
- unjsonify[T] → Type introspection: resolves target metadata
- unjsonify[T] → Field decoder: binds fields
- Field decoder → Property naming: maps keys
- Field decoder → Extra-key policy: enforces key policy
- unjsonify[T] → TypedDict support: decodes TypedDicts
- unjsonify[T] → Schema: executes schema conversion
- unjsonify[T] → Constraints: validates result
- unjsonify[T] → Variant families: reconstructs subtype
- unjsonify[T] → Typed Python values: constructs
- Variant families → jsonify: adds class label
