Skip to content

Primitives: Foundational Design Patterns

This document describes the fundamental design patterns that serve as primitives in the NERV architecture - the basic building blocks from which more complex patterns and components are constructed.

Overview

While the NERV architecture defines its own higher-level patterns (Reactive Event Mesh, Temporal Versioning, etc.), these patterns are built upon well-established foundational design patterns from software engineering. These primitives form the atomic building blocks of our architecture - they are the basic elements from which all higher-level components are constructed.

Core Primitive Patterns

PatternPurposeNERV UsageImplementation Library
ObserverEnable notification of state changesEvent notification and reactive programmingBlinker
CommandEncapsulate operations as objectsExplicit side effect managementEffect
MonadEncapsulate computation with contextFunctional composition with effectsEffect
StrategyDefine family of interchangeable algorithmsRuntime algorithm selectionPython protocols
BuilderConstruct complex objects step by stepMulti-stage object constructionPython dataclasses
DAGOrganize nodes with dependenciesDependency-based schedulingTaskMap
FactoryDelegate object creation to specialized methodsObject creation with configurationStatic methods
DecoratorAdd behavior to objects dynamicallyAdding capabilities without inheritancePython decorators

Pattern Relationships to NERV Architecture

The primitives form the foundation for NERV’s higher-level architectural patterns:

NERV PatternPrimitive CompositionImplementation Libraries
Reactive Event MeshObserver + Command + FactoryBlinker
Temporal VersioningCommand + Decorator + FactoryEventsourcing
Perspective ShiftingStrategy + Decorator + FactoryMarshmallow
State ProjectionCommand + Strategy + BuilderPyrsistent
Effect SystemCommand + Monad + DecoratorEffect
Quantum PartitioningBuilder + DAG + FactoryTaskMap

Key Primitive Implementations

Each primitive pattern is implemented using specific libraries within NERV:

  • Observer Pattern: Blinker library for signal dispatch (EventBus)
  • Command Pattern: Effect library for effect descriptions
  • Monad Pattern: Effect library for monadic operations
  • Strategy Pattern: Python protocols with Marshmallow for schema-based transformations
  • Builder Pattern: Python dataclasses with builder methods in QuantumPartitioner
  • DAG Pattern: TaskMap library for dependency execution
  • Factory Pattern: Static factory methods on various domain classes
  • Decorator Pattern: Python decorators and function wrappers for aspect-oriented programming

Implementation Guidance

When implementing NERV components, consider these primitive patterns:

  1. Favor composition over inheritance by using these patterns to combine behaviors
  2. Make interfaces explicit by clearly defining the pattern relationships
  3. Consider pattern combinations to solve complex problems
  4. Document pattern usage to explain design decisions and architecture
  5. Leverage library primitives when available to reduce custom implementation

Understanding these primitives is crucial for effective implementation of the NERV architecture, as they form the foundation upon which all higher-level patterns and components are built.

Cross-Cutting Architectural Properties

The primitive patterns combined in NERV create these emergent architectural properties:

PropertyDescriptionEnabled ByPrimary Libraries
DecouplingComponents can evolve independentlyObserver, CommandBlinker, Effect
ComposabilitySimple units combine into complex behaviorsMonad, DecoratorEffect, Python decorators
ExtensibilityNew behaviors without changing core codeStrategy, FactoryMarshmallow, Python protocols
ObservabilityIntrospection of system behaviorObserver, CommandBlinker, Effect
ParallelismEfficient concurrent executionDAG, BuilderTaskMap
FlexibilityRuntime adaptation to changing needsStrategy, DecoratorMarshmallow, Python decorators

Learn More

For detailed explanations and implementation examples of each primitive pattern, see their individual documentation pages:

Released under the MIT License.