# faif/python-patterns architecture

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

- Interactive diagram: https://gitdiagram.com/faif/python-patterns
- Repository: https://github.com/faif/python-patterns

## Overview

python-patterns is a collection of independent Python design-pattern examples, not a single application with a shared runtime pipeline. The user-facing workflow is to choose a pattern by its design purpose, inspect its implementation, and use the demonstrated behavior as a reference. The graph groups implementations by pattern family; the README documents these capabilities, while sampled source confirms selected examples. Since examples generally do not call one another, the graph does not imply cross-pattern runtime links.

Main entry points: [`patterns/creational/abstract_factory.py`](https://github.com/faif/python-patterns/blob/master/patterns/creational/abstract_factory.py) (Abstract factory), [`patterns/creational/borg.py`](https://github.com/faif/python-patterns/blob/master/patterns/creational/borg.py) (Borg), [`patterns/creational/builder.py`](https://github.com/faif/python-patterns/blob/master/patterns/creational/builder.py) (Builder), [`patterns/creational/factory.py`](https://github.com/faif/python-patterns/blob/master/patterns/creational/factory.py) (Factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_creation["Object creation"]
  node_abstract_factory["Abstract factory"]
  node_borg["Borg<br/>[borg.py]"]
  node_builder["Builder<br/>[builder.py]"]
  node_factory["Factory<br/>[factory.py]"]
  node_lazy_evaluation["Lazy evaluation<br/>[lazy_evaluation.py]"]
  node_pool["Object pool<br/>[pool.py]"]
  node_prototype["Prototype<br/>[prototype.py]"]
end

subgraph group_structure["Object structure"]
  node_tier["Three-tier<br/>[3-tier.py]"]
  node_adapter["Adapter<br/>[adapter.py]"]
  node_bridge["Bridge<br/>[bridge.py]"]
  node_composite["Composite<br/>[composite.py]"]
  node_decorator["Decorator<br/>[decorator.py]"]
  node_facade["Facade<br/>[facade.py]"]
  node_flyweight["Flyweight<br/>[flyweight.py]"]
  node_flyweight_meta["Flyweight metaclass"]
  node_front_controller["Front controller"]
  node_mvc["MVC<br/>[mvc.py]"]
  node_proxy["Proxy<br/>[proxy.py]"]
end

subgraph group_behavior["Object behavior"]
  node_catalog["Catalog dispatch<br/>[catalog.py]"]
  node_chain["Responsibility chain"]
  node_chaining["Chaining method<br/>[chaining_method.py]"]
  node_command["Command<br/>[command.py]"]
  node_iterator["Iterator<br/>[iterator.py]"]
  node_iterator_alt["Iterator alternative<br/>[iterator_alt.py]"]
  node_mediator["Mediator<br/>[mediator.py]"]
  node_memento["Memento<br/>[memento.py]"]
  node_observer["Observer<br/>[observer.py]"]
  node_publish_subscribe["Publish subscribe"]
  node_registry["Registry<br/>[registry.py]"]
  node_servant["Servant<br/>[servant.py]"]
  node_specification["Specification<br/>[specification.py]"]
  node_state["State<br/>[state.py]"]
  node_strategy["Strategy<br/>[strategy.py]"]
end

subgraph group_testability["Testability"]
end

subgraph group_other["Other patterns"]
end

node_user(("Pattern user"))

node_user -->|"chooses example"| node_abstract_factory
node_user -->|"chooses example"| node_borg
node_user -->|"chooses example"| node_builder
node_user -->|"chooses example"| node_factory
node_user -->|"chooses example"| node_lazy_evaluation
node_user -->|"chooses example"| node_pool
node_user -->|"chooses example"| node_prototype
node_user -->|"chooses example"| node_tier
node_user -->|"chooses example"| node_adapter
node_user -->|"chooses example"| node_bridge
node_user -->|"chooses example"| node_composite
node_user -->|"chooses example"| node_decorator
node_user -->|"chooses example"| node_facade
node_user -->|"chooses example"| node_flyweight
node_user -->|"chooses example"| node_flyweight_meta
node_user -->|"chooses example"| node_front_controller
node_user -->|"chooses example"| node_mvc
node_user -->|"chooses example"| node_proxy
node_user -->|"chooses example"| node_catalog
node_user -->|"chooses example"| node_chain
node_user -->|"chooses example"| node_chaining
node_user -->|"chooses example"| node_command
node_user -->|"chooses example"| node_iterator
node_user -->|"chooses example"| node_iterator_alt
node_user -->|"chooses example"| node_mediator
node_user -->|"chooses example"| node_memento
node_user -->|"chooses example"| node_observer
node_user -->|"chooses example"| node_publish_subscribe
node_user -->|"chooses example"| node_registry
node_user -->|"chooses example"| node_servant
node_user -->|"chooses example"| node_specification
node_user -->|"chooses example"| node_state
node_user -->|"chooses example"| node_strategy

click node_abstract_factory "https://github.com/faif/python-patterns/blob/master/patterns/creational/abstract_factory.py"
click node_borg "https://github.com/faif/python-patterns/blob/master/patterns/creational/borg.py"
click node_builder "https://github.com/faif/python-patterns/blob/master/patterns/creational/builder.py"
click node_factory "https://github.com/faif/python-patterns/blob/master/patterns/creational/factory.py"
click node_lazy_evaluation "https://github.com/faif/python-patterns/blob/master/patterns/creational/lazy_evaluation.py"
click node_pool "https://github.com/faif/python-patterns/blob/master/patterns/creational/pool.py"
click node_prototype "https://github.com/faif/python-patterns/blob/master/patterns/creational/prototype.py"
click node_tier "https://github.com/faif/python-patterns/blob/master/patterns/structural/3-tier.py"
click node_adapter "https://github.com/faif/python-patterns/blob/master/patterns/structural/adapter.py"
click node_bridge "https://github.com/faif/python-patterns/blob/master/patterns/structural/bridge.py"
click node_composite "https://github.com/faif/python-patterns/blob/master/patterns/structural/composite.py"
click node_decorator "https://github.com/faif/python-patterns/blob/master/patterns/structural/decorator.py"
click node_facade "https://github.com/faif/python-patterns/blob/master/patterns/structural/facade.py"
click node_flyweight "https://github.com/faif/python-patterns/blob/master/patterns/structural/flyweight.py"
click node_flyweight_meta "https://github.com/faif/python-patterns/blob/master/patterns/structural/flyweight_with_metaclass.py"
click node_front_controller "https://github.com/faif/python-patterns/blob/master/patterns/structural/front_controller.py"
click node_mvc "https://github.com/faif/python-patterns/blob/master/patterns/structural/mvc.py"
click node_proxy "https://github.com/faif/python-patterns/blob/master/patterns/structural/proxy.py"
click node_catalog "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/catalog.py"
click node_chain "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/chain_of_responsibility.py"
click node_chaining "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/chaining_method.py"
click node_command "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/command.py"
click node_iterator "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/iterator.py"
click node_iterator_alt "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/iterator_alt.py"
click node_mediator "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/mediator.py"
click node_memento "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/memento.py"
click node_observer "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/observer.py"
click node_publish_subscribe "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/publish_subscribe.py"
click node_registry "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/registry.py"
click node_servant "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/servant.py"
click node_specification "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/specification.py"
click node_state "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/state.py"
click node_strategy "https://github.com/faif/python-patterns/blob/master/patterns/behavioral/strategy.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_abstract_factory,node_borg,node_builder,node_factory,node_lazy_evaluation,node_pool,node_prototype,node_user toneBlue
class node_tier,node_adapter,node_bridge,node_composite,node_decorator,node_facade,node_flyweight,node_flyweight_meta,node_front_controller,node_mvc,node_proxy toneAmber
class node_catalog,node_chain,node_chaining,node_command,node_iterator,node_iterator_alt,node_mediator,node_memento,node_observer,node_publish_subscribe,node_registry,node_servant,node_specification,node_state,node_strategy toneMint
```

## Components

### Object creation

- [Abstract factory](https://github.com/faif/python-patterns/blob/master/patterns/creational/abstract_factory.py): `patterns/creational/abstract_factory.py`
- [Borg](https://github.com/faif/python-patterns/blob/master/patterns/creational/borg.py): `patterns/creational/borg.py`
- [Builder](https://github.com/faif/python-patterns/blob/master/patterns/creational/builder.py): `patterns/creational/builder.py`
- [Factory](https://github.com/faif/python-patterns/blob/master/patterns/creational/factory.py): `patterns/creational/factory.py`
- [Lazy evaluation](https://github.com/faif/python-patterns/blob/master/patterns/creational/lazy_evaluation.py): `patterns/creational/lazy_evaluation.py`
- [Object pool](https://github.com/faif/python-patterns/blob/master/patterns/creational/pool.py): `patterns/creational/pool.py`
- [Prototype](https://github.com/faif/python-patterns/blob/master/patterns/creational/prototype.py): `patterns/creational/prototype.py`

### Object structure

- [Three-tier](https://github.com/faif/python-patterns/blob/master/patterns/structural/3-tier.py): `patterns/structural/3-tier.py`
- [Adapter](https://github.com/faif/python-patterns/blob/master/patterns/structural/adapter.py): `patterns/structural/adapter.py`
- [Bridge](https://github.com/faif/python-patterns/blob/master/patterns/structural/bridge.py): `patterns/structural/bridge.py`
- [Composite](https://github.com/faif/python-patterns/blob/master/patterns/structural/composite.py): `patterns/structural/composite.py`
- [Decorator](https://github.com/faif/python-patterns/blob/master/patterns/structural/decorator.py): `patterns/structural/decorator.py`
- [Facade](https://github.com/faif/python-patterns/blob/master/patterns/structural/facade.py): `patterns/structural/facade.py`
- [Flyweight](https://github.com/faif/python-patterns/blob/master/patterns/structural/flyweight.py): `patterns/structural/flyweight.py`
- [Flyweight metaclass](https://github.com/faif/python-patterns/blob/master/patterns/structural/flyweight_with_metaclass.py): `patterns/structural/flyweight_with_metaclass.py`
- [Front controller](https://github.com/faif/python-patterns/blob/master/patterns/structural/front_controller.py): `patterns/structural/front_controller.py`
- [MVC](https://github.com/faif/python-patterns/blob/master/patterns/structural/mvc.py): `patterns/structural/mvc.py`
- [Proxy](https://github.com/faif/python-patterns/blob/master/patterns/structural/proxy.py): `patterns/structural/proxy.py`

### Object behavior

- [Catalog dispatch](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/catalog.py): `patterns/behavioral/catalog.py`
- [Responsibility chain](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/chain_of_responsibility.py): `patterns/behavioral/chain_of_responsibility.py`
- [Chaining method](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/chaining_method.py): `patterns/behavioral/chaining_method.py`
- [Command](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/command.py): `patterns/behavioral/command.py`
- [Iterator](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/iterator.py): `patterns/behavioral/iterator.py`
- [Iterator alternative](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/iterator_alt.py): `patterns/behavioral/iterator_alt.py`
- [Mediator](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/mediator.py): `patterns/behavioral/mediator.py`
- [Memento](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/memento.py): `patterns/behavioral/memento.py`
- [Observer](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/observer.py): `patterns/behavioral/observer.py`
- [Publish subscribe](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/publish_subscribe.py): `patterns/behavioral/publish_subscribe.py`
- [Registry](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/registry.py): `patterns/behavioral/registry.py`
- [Servant](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/servant.py): `patterns/behavioral/servant.py`
- [Specification](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/specification.py): `patterns/behavioral/specification.py`
- [State](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/state.py): `patterns/behavioral/state.py`
- [Strategy](https://github.com/faif/python-patterns/blob/master/patterns/behavioral/strategy.py): `patterns/behavioral/strategy.py`

### Other components

- **Pattern user**

## Connections

- Pattern user → Abstract factory: chooses example (evidence: `README.md`)
- Pattern user → Borg: chooses example (evidence: `README.md`)
- Pattern user → Builder: chooses example (evidence: `README.md`)
- Pattern user → Factory: chooses example (evidence: `README.md`)
- Pattern user → Lazy evaluation: chooses example (evidence: `README.md`)
- Pattern user → Object pool: chooses example (evidence: `README.md`)
- Pattern user → Prototype: chooses example (evidence: `README.md`)
- Pattern user → Three-tier: chooses example (evidence: `README.md`)
- Pattern user → Adapter: chooses example (evidence: `README.md`)
- Pattern user → Bridge: chooses example (evidence: `README.md`)
- Pattern user → Composite: chooses example (evidence: `README.md`)
- Pattern user → Decorator: chooses example (evidence: `README.md`)
- Pattern user → Facade: chooses example (evidence: `README.md`)
- Pattern user → Flyweight: chooses example (evidence: `README.md`)
- Pattern user → Flyweight metaclass: chooses example (evidence: `README.md`)
- Pattern user → Front controller: chooses example (evidence: `README.md`)
- Pattern user → MVC: chooses example (evidence: `README.md`)
- Pattern user → Proxy: chooses example (evidence: `README.md`)
- Pattern user → Catalog dispatch: chooses example (evidence: `README.md`)
- Pattern user → Responsibility chain: chooses example (evidence: `README.md`)
- Pattern user → Chaining method: chooses example (evidence: `README.md`)
- Pattern user → Command: chooses example (evidence: `README.md`)
- Pattern user → Iterator: chooses example (evidence: `README.md`)
- Pattern user → Iterator alternative: chooses example (evidence: `README.md`)
- Pattern user → Mediator: chooses example (evidence: `README.md`)
- Pattern user → Memento: chooses example (evidence: `README.md`)
- Pattern user → Observer: chooses example (evidence: `README.md`)
- Pattern user → Publish subscribe: chooses example (evidence: `README.md`)
- Pattern user → Registry: chooses example (evidence: `README.md`)
- Pattern user → Servant: chooses example (evidence: `README.md`)
- Pattern user → Specification: chooses example (evidence: `README.md`)
- Pattern user → State: chooses example (evidence: `README.md`)
- Pattern user → Strategy: chooses example (evidence: `README.md`)
