# veyga/funstruct architecture

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

- Interactive diagram: https://gitdiagram.com/veyga/funstruct
- Repository: https://github.com/veyga/funstruct

## Overview

funstruct is a Python functional-programming library: immutable algebraic data types and collections gain reusable behavior through typeclasses and registered instances. A user composes values with operations such as map, bind, fold, and do; DataType dispatches those calls to the applicable instance, which implements the behavior for that type. The repository also provides async/error-handling values, persistent collections, optics, and experimental monad transformers. Edges follow the README or shown source/index references; several type families and integrations are represented at directory level because their implementations were not sampled.

Main entry points: [`funstruct/typeclasses/mixins/data_type.py`](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/data_type.py) (DataType Dispatch), [`funstruct/typeclasses/utils/registry.py`](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/utils/registry.py) (Instance Registry), [`funstruct/types/either/__init__.py`](https://github.com/veyga/funstruct/blob/main/funstruct/types/either/__init__.py) (Either), [`funstruct/types/result/__init__.py`](https://github.com/veyga/funstruct/blob/main/funstruct/types/result/__init__.py) (Result and AsyncResult)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Dispatch Runtime"]
  node_datatype["DataType Dispatch<br/>[data_type.py]"]
  node_registry[("Instance Registry<br/>[registry.py]")]
  node_dot["Dot Dispatch<br/>[dot_notation.py]"]
  node_constructor["Type Constructor"]
  node_created_at["Error Origin Capture<br/>[created_at.py]"]
  node_tailrec["Tail Recursion<br/>[tailrec.py]"]
end

subgraph group_algebra["Typeclass Algebra"]
  node_typeclass["Base Typeclass<br/>[typeclass.py]"]
  node_applicative["Applicative<br/>[applicative.py]"]
  node_monad["Monad<br/>[monad.py]"]
  node_monoid["Monoid<br/>[monoid.py]"]
  node_eq["Equality<br/>[eq.py]"]
  node_foldable["Folding<br/>[foldable.py]"]
  node_representable["Representation<br/>[representable.py]"]
  node_semigroup["Semigroup<br/>[semigroup.py]"]
  node_stringable["String Conversion<br/>[stringable.py]"]
end

subgraph group_values["Data Types"]
  node_option["Option<br/>[__init__.py]"]
  node_either["Either<br/>[__init__.py]"]
  node_result["Result and AsyncResult<br/>[__init__.py]"]
  node_collections["Persistent Collections<br/>[__init__.py]"]
  node_frozendict["Immutable Mapping<br/>[__init__.py]"]
  node_other_types["Other Data Types"]
end

subgraph group_extensions["Functional Extensions"]
  node_do_ast["Collection Do Notation<br/>[do_ast.py]"]
  node_transformers["Monad Transformers<br/>[_typeclass.py]"]
  node_optics["Lens Optics<br/>[_lens.py]"]
end

node_user(("Library User"))

node_user -->|"uses values"| node_datatype
node_datatype -->|"mixes in"| node_dot
node_datatype -->|"mixes in"| node_constructor
node_datatype -->|"dispatches via"| node_registry
node_datatype -->|"delegates dunders"| node_eq
node_option -->|"extends"| node_datatype
node_either -->|"extends"| node_datatype
node_result -->|"extends"| node_datatype
node_collections -->|"extends"| node_datatype
node_frozendict -->|"extends"| node_datatype
node_other_types -.->|"extend"| node_datatype
node_applicative -->|"inherits"| node_typeclass
node_monad -->|"inherits"| node_applicative
node_monoid -->|"inherits"| node_semigroup
node_monad -->|"instances registered"| node_registry
node_option -->|"type instances"| node_registry
node_either -->|"type instances"| node_registry
node_result -->|"type instances"| node_registry
node_result -->|"captures error origin"| node_created_at
node_either -->|"captures error origin"| node_created_at
node_collections -->|"uses trampoline"| node_tailrec
node_transformers -.->|"extends monad patterns"| node_monad
node_optics -->|"operates on"| node_frozendict
node_do_ast -->|"supports do notation"| node_collections

click node_datatype "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/data_type.py"
click node_registry "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/utils/registry.py"
click node_dot "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/dot_notation.py"
click node_constructor "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/type_constructor.py"
click node_typeclass "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/typeclass.py"
click node_applicative "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/applicative.py"
click node_monad "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/monad.py"
click node_monoid "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/monoid.py"
click node_eq "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/eq.py"
click node_foldable "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/foldable.py"
click node_representable "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/representable.py"
click node_semigroup "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/semigroup.py"
click node_stringable "https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/stringable.py"
click node_option "https://github.com/veyga/funstruct/blob/main/funstruct/types/option/__init__.py"
click node_either "https://github.com/veyga/funstruct/blob/main/funstruct/types/either/__init__.py"
click node_result "https://github.com/veyga/funstruct/blob/main/funstruct/types/result/__init__.py"
click node_collections "https://github.com/veyga/funstruct/blob/main/funstruct/types/cons/__init__.py"
click node_frozendict "https://github.com/veyga/funstruct/blob/main/funstruct/types/frozendict/__init__.py"
click node_other_types "https://github.com/veyga/funstruct/tree/main/funstruct/types"
click node_created_at "https://github.com/veyga/funstruct/blob/main/funstruct/util/created_at.py"
click node_tailrec "https://github.com/veyga/funstruct/blob/main/funstruct/util/tailrec.py"
click node_do_ast "https://github.com/veyga/funstruct/blob/main/funstruct/experimental/do_ast.py"
click node_transformers "https://github.com/veyga/funstruct/blob/main/funstruct/experimental/monadtransformer/_typeclass.py"
click node_optics "https://github.com/veyga/funstruct/blob/main/funstruct/experimental/optics/_lens.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_datatype,node_registry,node_dot,node_constructor,node_created_at,node_tailrec,node_user toneBlue
class node_typeclass,node_applicative,node_monad,node_monoid,node_eq,node_foldable,node_representable,node_semigroup,node_stringable toneAmber
class node_option,node_either,node_result,node_collections,node_frozendict,node_other_types toneMint
class node_do_ast,node_transformers,node_optics toneRose
```

## Components

### Dispatch Runtime

- [DataType Dispatch](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/data_type.py): `funstruct/typeclasses/mixins/data_type.py`
- [Instance Registry](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/utils/registry.py): `funstruct/typeclasses/utils/registry.py`
- [Dot Dispatch](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/dot_notation.py): `funstruct/typeclasses/mixins/dot_notation.py`
- [Type Constructor](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/mixins/type_constructor.py): `funstruct/typeclasses/mixins/type_constructor.py`
- [Error Origin Capture](https://github.com/veyga/funstruct/blob/main/funstruct/util/created_at.py): `funstruct/util/created_at.py`
- [Tail Recursion](https://github.com/veyga/funstruct/blob/main/funstruct/util/tailrec.py): `funstruct/util/tailrec.py`

### Typeclass Algebra

- [Base Typeclass](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/typeclass.py): `funstruct/typeclasses/typeclass.py`
- [Applicative](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/applicative.py): `funstruct/typeclasses/applicative.py`
- [Monad](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/monad.py): `funstruct/typeclasses/monad.py`
- [Monoid](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/monoid.py): `funstruct/typeclasses/monoid.py`
- [Equality](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/eq.py): `funstruct/typeclasses/eq.py`
- [Folding](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/foldable.py): `funstruct/typeclasses/foldable.py`
- [Representation](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/representable.py): `funstruct/typeclasses/representable.py`
- [Semigroup](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/semigroup.py): `funstruct/typeclasses/semigroup.py`
- [String Conversion](https://github.com/veyga/funstruct/blob/main/funstruct/typeclasses/stringable.py): `funstruct/typeclasses/stringable.py`

### Data Types

- [Option](https://github.com/veyga/funstruct/blob/main/funstruct/types/option/__init__.py): `funstruct/types/option/__init__.py`
- [Either](https://github.com/veyga/funstruct/blob/main/funstruct/types/either/__init__.py): `funstruct/types/either/__init__.py`
- [Result and AsyncResult](https://github.com/veyga/funstruct/blob/main/funstruct/types/result/__init__.py): `funstruct/types/result/__init__.py`
- [Persistent Collections](https://github.com/veyga/funstruct/blob/main/funstruct/types/cons/__init__.py): `funstruct/types/cons/__init__.py`
- [Immutable Mapping](https://github.com/veyga/funstruct/blob/main/funstruct/types/frozendict/__init__.py): `funstruct/types/frozendict/__init__.py`
- [Other Data Types](https://github.com/veyga/funstruct/tree/main/funstruct/types): `funstruct/types`

### Functional Extensions

- [Collection Do Notation](https://github.com/veyga/funstruct/blob/main/funstruct/experimental/do_ast.py): `funstruct/experimental/do_ast.py`
- [Monad Transformers](https://github.com/veyga/funstruct/blob/main/funstruct/experimental/monadtransformer/_typeclass.py): `funstruct/experimental/monadtransformer/_typeclass.py`
- [Lens Optics](https://github.com/veyga/funstruct/blob/main/funstruct/experimental/optics/_lens.py): `funstruct/experimental/optics/_lens.py`

### Other components

- **Library User**

## Connections

- Library User → DataType Dispatch: uses values
- DataType Dispatch → Dot Dispatch: mixes in (evidence: `funstruct/typeclasses/mixins/data_type.py`)
- DataType Dispatch → Type Constructor: mixes in (evidence: `funstruct/typeclasses/mixins/data_type.py`)
- DataType Dispatch → Instance Registry: dispatches via (evidence: `funstruct/typeclasses/mixins/data_type.py`)
- DataType Dispatch → Equality: delegates dunders (evidence: `funstruct/typeclasses/mixins/data_type.py`)
- Option → DataType Dispatch: extends (evidence: `funstruct/types/option/__init__.py`)
- Either → DataType Dispatch: extends (evidence: `funstruct/types/either/__init__.py`)
- Result and AsyncResult → DataType Dispatch: extends (evidence: `funstruct/types/result/__init__.py`)
- Persistent Collections → DataType Dispatch: extends (evidence: `funstruct/types/cons/__init__.py`)
- Immutable Mapping → DataType Dispatch: extends (evidence: `funstruct/types/frozendict/__init__.py`)
- Other Data Types → DataType Dispatch: extend (evidence: `funstruct/types/frozendict/__init__.py`)
- Applicative → Base Typeclass: inherits (evidence: `funstruct/typeclasses/applicative.py`)
- Monad → Applicative: inherits (evidence: `funstruct/typeclasses/monad.py`)
- Monoid → Semigroup: inherits (evidence: `funstruct/typeclasses/monoid.py`)
- Monad → Instance Registry: instances registered
- Option → Instance Registry: type instances
- Either → Instance Registry: type instances
- Result and AsyncResult → Instance Registry: type instances
- Result and AsyncResult → Error Origin Capture: captures error origin (evidence: `funstruct/types/result/__init__.py`)
- Either → Error Origin Capture: captures error origin (evidence: `funstruct/types/either/__init__.py`)
- Persistent Collections → Tail Recursion: uses trampoline (evidence: `funstruct/types/cons/__init__.py`)
- Monad Transformers → Monad: extends monad patterns
- Lens Optics → Immutable Mapping: operates on (evidence: `funstruct/experimental/optics/_lens.py`)
- Collection Do Notation → Persistent Collections: supports do notation
