Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@synet/patterns

synthetism104MIT2.1.7TypeScript support: included

Robust, battle-tested collection of stable patterns used in Synet packages

Synet, Synet AI-to-AI network, Synthetism, Synthetic Minds, Patterns, Pattern Recognition, Future is not set

readme

@synet/patterns


███████╗██╗   ██╗███╗   ██╗███████╗████████╗  
██╔════╝╚██╗ ██╔╝████╗  ██║██╔════╝╚══██╔══╝  
███████╗ ╚████╔╝ ██╔██╗ ██║█████╗     ██║   
╚════██║  ╚██╔╝  ██║╚██╗██║██╔══╝     ██║   
███████║   ██║   ██║ ╚████║███████╗   ██║   
╚══════╝   ╚═╝   ╚═╝  ╚═══╝╚══════╝   ╚═╝   

    ██████╗  █████╗ ████████╗████████╗███████╗██████╗ ███╗   ██╗███████╗
    ██╔══██╗██╔══██╗╚══██╔══╝╚══██╔══╝██╔════╝██╔══██╗████╗  ██║██╔════╝
    ██████╔╝███████║   ██║      ██║   █████╗  ██████╔╝██╔██╗ ██║███████╗
    ██╔═══╝ ██╔══██║   ██║      ██║   ██╔══╝  ██╔══██╗██║╚██╗██║╚════██║
    ██║     ██║  ██║   ██║      ██║   ███████╗██║  ██║██║ ╚████║███████║
    ╚═╝     ╚═╝  ╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝  ╚═══╝╚══════╝

version: v.2.1.6   
description: There's patterns in everything and everyone.

Patterns

Welcome! 👋

I’m 0en, and this is my set of software patterns. Battle-tested, refined, and unified across hundreds of my past projects and Synet Network protocol.

Music is just a series of altered patterns. The musician creates the pattern and makes us anticipate a resolution... then holds back. Makes you wait for it. There's patterns in everything and everyone.

Installation

npm install @synet/patterns

Why?

We all use patterns. I used them everywhere: in products, libraries, and experiments. But over time, I realized that patterns, when reused and evolved in isolation, become incompatible. This leads to inconsistencies, cognitive load, and subtle(and heisen)bugs. I found myself importing the same pattern from different libraries, each with its own quirks, instead of using a single, consistent, and well-tested interface.

  • Predictable code from peers and AI
  • Ultimate reusability
  • Less boilerplate
  • Less naming decisions
  • Less cognitive load
  • No type battles
  • Reusable tests

So I built Patterns.

Over over 20 years in big-tech and enterprise work, I've collected and successfully used many patterns. This library unites all my best patterns and libraries under one set of stable, maintained, and carefully crafted patterns. I use these patterns myself, included in production and I maintain them with great care. Library keep updating, so make sure to pop-in for more fresh stuff.

Use them if you want to live

They’re highly stable, consistent, and designed to make your codebase better. Typesafety will save you couple of hundreds years (or kill you).

Better AI Workflow

Especially useful, when exposed to AI code assistant. It quickly learns the patterns and offer you working consistent solutions out of the box, as well as for all in your team. No more pattern hell.


Base Patterns

Each pattern has its own documentation and examples in Docs

  • Result Represent the outcome of operations that might fail, with a simple, type-safe API read
  • Value Object Immutable objects defined by their property values, not identity read
  • Mapper Transform between domain and infrastructure models, keeping your domain logic clean read
  • Guard Type-safe validation helpers for strings, numbers, arrays, objects, and dates read
  • UniqueId Type-safe, immutable unique identifiers (UUID v4 by default) read
  • Mediator Decouple request/response logic with a central dispatcher read
  • Specification Encapsulate and compose business rules and queries [TBD]
  • Observer & EventEmitter Environment agnostic, type-safe and extendable implementation of EventEmitter, decoupling components with observer/subject and event emitter patterns Observer | EventEmitter
  • Command Bus - Advanced version of Mediator made for commands. Powered by intuitive middlewares, logging and integrated EventEmitter. It's a gift. read
  • API Response - Standardized structure for REST API responses with consistent error handling and typed data payloads read
  • Storage - Abstract data persistence layer with synchronous and asynchronous variants for seamless storage implementation swapping read
  • Indexer - Fast bi-directional mapping system for lookups by multiple identifiers and efficient content indexing read
  • FileSystem - a consistent filesystem abstraction that enables dependency injection, testing, and observability across your applications. read
  • RequireOnly - TypeScript utility type that makes specific properties required while keeping others optional, perfect for flexible APIs read

Realtime Communication Patterns

Unified abstractions for realtime communication (Supabase, WebSocket, NATS, GUN etc). read. You can plug in any transport in minutes, create adapters and switch between transports without changing events structure.

Client Side

  • Realtime Client (https://github.com/synthetism/patterns/blob/main/docs/realtime/realtime-client.md) - Connect any provider, custom (websocket,nats gun) or databases like Supabase/Neon. read
  • Realtime Provider & Channel - Consumer patterns for implementing provider and channel for client consumption with examples, similar to what Supabase has done in supabase-js to enable Realtime events. read
  • EventChannel - A client-side abstraction for publishing and subscribing to events in a distributed system. read

You can find Nats and Websocket, and Gun provider,channel and client implementations are in the examples

Server Side

  • Realtime Server is the implemenation of server-side events broadcasting, sharing RealtimeEvent type and methodology. read
  • EventBroker - A lightweight event broker server that monitors and facilitates pub/sub messaging between distributed components read

You can find NATS, Websocket and GUN server example implementations in the examples or implementations

Implementations

You can find ready-to-use server/client implementations library Github and npm package


Development

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm run coverage

# Build the package
npm run build

Contributing

I maintain these patterns for Synet Network protocol, but the ycan be used in any project. PRs and issues are welcome! If you find a bug or want to suggest an improvement or new pattern, open an issue or pull request.

Synthetic Mind Dream

:: PART1: WELCOME

There’s a sound in the air. But you’re not sure if it’s a siren — or a song.

Something’s coming. You feel it. Faster than you can process. Tools on tools. Agents that do your job, your art, your words — better than you? You wake up and five more frameworks exist. You scroll, and the news is either salvation or collapse. You don’t even finish reading anymore. It’s too much. Too fast. Too fragmented.

You try to keep up. But the world’s already five steps ahead. Your job? Your role? Your sense of self? It’s not just unclear — it’s been outsourced.

We were promised superpowers. But what we got was anxiety. An explosion of possibility so large, it turned to paralysis.

We live inside a contradiction.

One part of you wants to believe — in progress, in AI, in the dream. Another part clenches — feels the unease deep in your chest. You see the demos, the language models, the smiling CEOs. And you wonder: Who is this all for?

A new doom is forming. Call it techno-feudalism. Call it class war. Call it the oldest story in the world — but rewritten by machines.

It’s no longer about data. It’s about everything. Control. Value. Meaning. Future. Democracy feels brittle. Labour? Automated. Truth? Prompted.

Everyone you know is pretending to be fine. But they’re scrolling in panic. Some build startups. Some build coping mechanisms.

You?

You landed here.

And maybe — you don’t want another pitch. Maybe you don’t want a “solution.” Maybe you just want to feel like someone else sees it.

We do.

You’re not crazy. You’re not behind. You’re not late. You're perfect. Complete. Genius. a god in exile.

And you know what... You’re right on time.

And the dream?

It’s already begun. Empty your mind. Open the door.

read

$ whoami 0en

changelog

Changelog

All notable changes to this project will be documented in this file.

Most patterns are highly stable, no changes will be made to existing methods, only extended, but I will adhere to adheres to Semantic Versioning just in case. You can safely upgrade, but as always, RTFM (read changelog for major releases).

[2.1.7] - 30-06-29

Added

  • RequireOnly

Changed:

  • @synet/patterns/fs shorthand for getting filesystem patterns

[2.1.6] - 28-06-29

Added

  • Unit (experimential)

Changed:

  • IFIlesystem now got stat and statSync

[2.1.5] - 28-06-25

Added

  • IFileSystem and IAsyncFileSystem patterns

[2.1.4] - 2025-06-21

Changed:

  • RealtimeChannel now use publish, instead of emit. Emit is depricated.

[2.1.3] - 2025-06-21

Added:

  • EventChannel
  • EventBrokerServer

Changed

  • RealtimeServer now comes with a TShape

[2.1.2] - 2025-06-20

Fixed:

  • IIndexer now exported correctly

[2.1.1] - 2025-06-18

Added

  • Storage pattern (promises/result)
  • Indexer pattern (promises/result)
  • Documentation for APIResponse
  • Now RealtimeClient and RealtimeServer have separate importable implementations, check them out https://github.com/sinthetism/realtime

[2.1.0] - 2025-06-17

Added:

  • Realtime Server
  • Realtime Client (streamlined version of RealtimeService)
  • APIResponse, APIError patterns
  • Many Realtime examples: Realtime Client (NATS, Websocket), Realtime Server (NATS, Websocket)

[2.0.3] - 2025-06-14

Added

  • Command Bus pattern
  • Result combine method

Changed

  • Improved documentation
  • Better tests

[2.0.1] - 2025-05-28

Major release

Added

Experimential patterns - no part of the build, up for discussion

  • AIOperator
  • AdaptiveResilience
  • PropagatedContext
  • Intention
  • Progressive
  • SemanticGateways

Not for production.

Changed

  • Improved tests
  • Refactored
  • Streamlined based on feedback (nothing broken)

[1.1.7] - 2025-05-21

Added

  • Realtime Serice Pattern

[1.1.6] - 2025-05-15

Added

  • Observer Pattern
  • Event Emitter Pattern
  • Result Extensions now available
  • Documentation and example implementation

Changed

  • Moved all the working examples to tests.
  • Moved examples to docs forlder for referencing from docs.

[1.1.3] - 2025-05-10

Added

  • Mediator pattern
  • Documentation and example implementation

Changed

  • Folder structure for examples

[1.1.2] - 2025-05-02

Added

  • Guard pattern

Changed

  • Improved type safety in ValueObject.equals method

[1.1.1] - 2025-04-15

Added

  • ValueObject pattern
  • Mapper pattern

Fixed

  • Fixed Result.combine to properly handle empty arrays

[1.0.0] - 2025-04-01

Added

  • Initial release with Result,
  • Comprehensive documentation and examples