Design Patterns

This section describes the key design patterns used throughout ascetic-ddd.

Domain Patterns

Aggregate

The Aggregate pattern enforces consistency boundaries. Each aggregate has a root entity that controls access to its internal objects.

Repository

The Repository pattern provides collection-like access to aggregates. Implementations exist for PostgreSQL (psycopg-based).

Specification

The Specification pattern encapsulates query criteria. Supported flavors:

  • JSONPath: RFC 9535 and jsonpath2 implementations

  • Lambda filter: In-memory predicate-based filtering

  • Query lookup: MongoDB-like query operators ($eq, $gt, $in, $rel, etc.)

Infrastructure Patterns

Transactional Outbox

The Outbox pattern ensures reliable event publishing by writing events to a database table within the same transaction as the business operation.

Idempotent Inbox

The Inbox pattern ensures messages are processed exactly once using deduplication based on message identifiers.

Saga

The Saga pattern coordinates distributed transactions across multiple aggregates or services using compensating actions.

Unit of Work

Session management implements the Unit of Work pattern, tracking changes and committing them atomically.

Test Data Patterns

Provider Topology

The faker module uses a Provider topology where each provider is responsible for generating a specific piece of test data. Providers form a directed acyclic graph with reference providers linking aggregates.

Distribution Strategies

Distributor strategies control how test data is selected or created:

  • Sequence: Round-robin through existing data

  • Weighted: Probability-weighted selection

  • Random: Random selection from available pool