Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,11 @@ var cachedRemoteProxy = Proxy<int, string>.Create(id => remoteProxy.Execute(id))
---

## Patterns Table
PatternKit currently tracks 104 production-readiness patterns. Each catalog pattern is represented in tests, documentation, real-world examples, IoC integration, and the BenchmarkDotNet coverage matrix.
PatternKit currently tracks 105 production-readiness patterns. Each catalog pattern is represented in tests, documentation, real-world examples, IoC integration, and the BenchmarkDotNet coverage matrix.

| Category | Count | Patterns |
| --- | ---: | --- |
| Application Architecture | 19 | Activity Tracker, Aggregate Root, Anti-Corruption Layer, Audit Log, CQRS, Data Mapper, Domain Event, Domain Service, Event Sourcing, Feature Toggle, Identity Map, Materialized View, Repository, Service Layer, Specification, Table Data Gateway, Transaction Script, Unit of Work, Value Object |
| Application Architecture | 20 | Activity Tracker, Aggregate Root, Anti-Corruption Layer, Audit Log, Bounded Context, CQRS, Data Mapper, Domain Event, Domain Service, Event Sourcing, Feature Toggle, Identity Map, Materialized View, Repository, Service Layer, Specification, Table Data Gateway, Transaction Script, Unit of Work, Value Object |
| Behavioral | 11 | Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor |
| Cloud Architecture | 17 | Ambassador, Backends for Frontends, Bulkhead, Cache-Aside, Circuit Breaker, External Configuration Store, Gateway Aggregation, Gateway Routing, Health Endpoint Monitoring, Leader Election, Priority Queue, Queue-Based Load Leveling, Rate Limiting, Retry, Scheduler Agent Supervisor, Sidecar, Strangler Fig |
| Creational | 5 | Abstract Factory, Builder, Factory Method, Prototype, Singleton |
Expand Down Expand Up @@ -561,6 +561,8 @@ BenchmarkDotNet guidance is documented in [docs/guides/benchmarks.md](docs/guide
| Decorator | Execution | 60.765 ns | 384 B | 35.551 ns | 304 B | Generated decorator execution was faster and allocated less for decorated storage reads. |
| Domain Event | Construction | 199.5 ns | 1.34 KB | 157.6 ns | 1.04 KB | Generated reduced construction time and allocation in this microbenchmark. |
| Domain Event | Execution | 367.2 ns | 1.77 KB | 346.4 ns | 1.55 KB | Generated reduced execution time and allocation for the order-placed dispatch workflow. |
| Bounded Context | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Bounded Context | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Domain Service | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Domain Service | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Event-Carried State Transfer | Construction | 7.552 ns | 48 B | 6.751 ns | 48 B | Same allocation; generated was slightly faster in this microbenchmark. |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using BenchmarkDotNet.Attributes;
using PatternKit.Application.BoundedContexts;
using PatternKit.Examples.BoundedContextDemo;

namespace PatternKit.Benchmarks.Application;

[BenchmarkCategory("ApplicationArchitecture", "BoundedContext")]
public class BoundedContextBenchmarks
{
private static readonly FulfillmentBoundedContextDemo.CatalogProduct Product = new("SKU-1", 42m);

private readonly BoundedContextDescriptor _fluent = FulfillmentBoundedContextDemo.CreateFluentDescriptor();

private readonly BoundedContextDescriptor _generated = FulfillmentBoundedContextDemo.CreateGeneratedDescriptor();

[Benchmark(Baseline = true, Description = "Fluent: create bounded context descriptor")]
[BenchmarkCategory("Fluent", "Construction")]
public BoundedContextDescriptor Fluent_CreateDescriptor()
=> FulfillmentBoundedContextDemo.CreateFluentDescriptor();

[Benchmark(Description = "Generated: create bounded context descriptor")]
[BenchmarkCategory("Generated", "Construction")]
public BoundedContextDescriptor Generated_CreateDescriptor()
=> FulfillmentBoundedContextDemo.CreateGeneratedDescriptor();

[Benchmark(Description = "Fluent: inspect bounded context boundary")]
[BenchmarkCategory("Fluent", "Execution")]
public int Fluent_InspectBoundary()
=> _fluent.Capabilities.Count + _fluent.Adapters.Count + FulfillmentBoundedContextDemo.Translate(Product).Sku.Length;

[Benchmark(Description = "Generated: inspect bounded context boundary")]
[BenchmarkCategory("Generated", "Execution")]
public int Generated_InspectBoundary()
=> _generated.Capabilities.Count + _generated.Adapters.Count + FulfillmentBoundedContextDemo.Translate(Product).Sku.Length;
}
21 changes: 21 additions & 0 deletions docs/examples/fulfillment-bounded-context-pattern.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Fulfillment Bounded Context Pattern

The fulfillment example demonstrates a production-shaped context boundary around shipment quoting and inventory allocation.

The example exposes:

- a fluent `BoundedContextDescriptor`
- a generated descriptor from `GeneratedFulfillmentContext`
- `IShipmentQuoter`, `IInventoryAllocator`, and `FulfillmentPlanner`
- `AddFulfillmentBoundedContextDemo()` for `IServiceCollection`

```csharp
var services = new ServiceCollection()
.AddFulfillmentBoundedContextDemo();

using var provider = services.BuildServiceProvider();
var planner = provider.GetRequiredService<FulfillmentPlanner>();
var plan = planner.Plan(new CatalogProduct("SKU-1", 42m));
```

The descriptor makes it clear that catalog products are translated into fulfillment items before the fulfillment model owns shipment and reservation decisions.
3 changes: 3 additions & 0 deletions docs/examples/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,6 @@

- name: Warehouse Scheduler Agent Supervisor
href: warehouse-scheduler-agent-supervisor.md

- name: Fulfillment Bounded Context Pattern
href: fulfillment-bounded-context-pattern.md
21 changes: 21 additions & 0 deletions docs/generators/bounded-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Bounded Context Generator

`BoundedContextDescriptorGenerator` emits a `BoundedContextDescriptor` factory from attributes on a partial class or struct.

```csharp
[GenerateBoundedContextDescriptor("Fulfillment", FactoryMethodName = "Build")]
[BoundedContextCapability("quote shipment", typeof(IShipmentQuoter))]
[BoundedContextAdapter("Catalog", "Fulfillment", typeof(CatalogProduct), typeof(FulfillmentItem))]
public static partial class FulfillmentContext;
```

The generated method creates the descriptor, adds capabilities in deterministic order, adds model adapters, and returns the built descriptor.

Diagnostics:

| Id | Meaning |
| --- | --- |
| `PKCTX001` | The host type must be partial. |
| `PKCTX002` | At least one capability is required. |
| `PKCTX003` | Capability names must be unique within the context. |
| `PKCTX004` | Adapter registrations must be unique. |
3 changes: 3 additions & 0 deletions docs/generators/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@
- name: Value Object
href: value-object.md

- name: Bounded Context
href: bounded-context.md

- name: State Machine
href: state-machine.md

Expand Down
14 changes: 9 additions & 5 deletions docs/guides/benchmark-results.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ The latest measured timings below were captured on Windows 11, Intel Core i9-149
| Decorator | Execution | 60.765 ns | 384 B | 35.551 ns | 304 B | Generated decorator execution was faster and allocated less for decorated storage reads. |
| Domain Event | Construction | 199.5 ns | 1.34 KB | 157.6 ns | 1.04 KB | Generated reduced construction time and allocation in this microbenchmark. |
| Domain Event | Execution | 367.2 ns | 1.77 KB | 346.4 ns | 1.55 KB | Generated reduced execution time and allocation for the order-placed dispatch workflow. |
| Bounded Context | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Bounded Context | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Domain Service | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Domain Service | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Event-Carried State Transfer | Construction | 7.552 ns | 48 B | 6.751 ns | 48 B | Same allocation; generated was slightly faster in this microbenchmark. |
Expand Down Expand Up @@ -226,19 +228,19 @@ The latest measured timings below were captured on Windows 11, Intel Core i9-149

## Coverage Matrix Summary

The coverage matrix currently publishes 104 catalog patterns and 416 pattern route results. Each pattern has four BenchmarkDotNet routes: fluent construction, fluent execution, source-generated construction, and source-generated execution. The reusable hosting integration matrix publishes 9 reusable hosting integration route results for package-level `IServiceCollection` registrations.
The coverage matrix currently publishes 105 catalog patterns and 420 pattern route results. Each pattern has four BenchmarkDotNet routes: fluent construction, fluent execution, source-generated construction, and source-generated execution. The reusable hosting integration matrix publishes 9 reusable hosting integration route results for package-level `IServiceCollection` registrations.

| Category | Patterns | Published route results |
| --- | ---: | ---: |
| Application Architecture | 19 | 76 |
| Application Architecture | 20 | 80 |
| Behavioral | 11 | 44 |
| Cloud Architecture | 17 | 68 |
| Creational | 5 | 20 |
| Enterprise Integration | 41 | 164 |
| Messaging Reliability | 3 | 12 |
| Structural | 7 | 28 |

The generator matrix currently publishes 99 generator source route results.
The generator matrix currently publishes 100 generator source route results.

## Hosting Integration Matrix Results

Expand All @@ -261,8 +263,9 @@ The generator matrix currently publishes 99 generator source route results.
| Application Architecture | Activity Tracker | Covered | Covered | Covered | Covered |
| Application Architecture | Aggregate Root | Covered | Covered | Covered | Covered |
| Application Architecture | Anti-Corruption Layer | Covered | Covered | Covered | Covered |
| Application Architecture | Audit Log | Covered | Covered | Covered | Covered |
| Application Architecture | CQRS | Covered | Covered | Covered | Covered |
| Application Architecture | Audit Log | Covered | Covered | Covered | Covered |
| Application Architecture | Bounded Context | Covered | Covered | Covered | Covered |
| Application Architecture | CQRS | Covered | Covered | Covered | Covered |
| Application Architecture | Data Mapper | Covered | Covered | Covered | Covered |
| Application Architecture | Domain Event | Covered | Covered | Covered | Covered |
| Application Architecture | Domain Service | Covered | Covered | Covered | Covered |
Expand Down Expand Up @@ -387,6 +390,7 @@ The generator matrix currently publishes 99 generator source route results.
| DataMapperGenerator | `src/PatternKit.Generators/DataMapping/DataMapperGenerator.cs` | Covered |
| DecoratorGenerator | `src/PatternKit.Generators/DecoratorGenerator.cs` | Covered |
| DomainEventDispatcherGenerator | `src/PatternKit.Generators/DomainEvents/DomainEventDispatcherGenerator.cs` | Covered |
| BoundedContextDescriptorGenerator | `src/PatternKit.Generators/BoundedContexts/BoundedContextDescriptorGenerator.cs` | Covered |
| DomainServiceRegistryGenerator | `src/PatternKit.Generators/DomainServices/DomainServiceRegistryGenerator.cs` | Covered |
| EventCarriedStateTransferGenerator | `src/PatternKit.Generators/EventCarriedStateTransfer/EventCarriedStateTransferGenerator.cs` | Covered |
| EventNotificationGenerator | `src/PatternKit.Generators/EventNotification/EventNotificationGenerator.cs` | Covered |
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ The following numbers were captured on Windows 11, Intel Core i9-14900K, .NET SD
| Decorator | Execution | 60.765 ns | 384 B | 35.551 ns | 304 B | Generated decorator execution was faster and allocated less for decorated storage reads. |
| Domain Event | Construction | 199.5 ns | 1.34 KB | 157.6 ns | 1.04 KB | Generated reduced construction time and allocation in this microbenchmark. |
| Domain Event | Execution | 367.2 ns | 1.77 KB | 346.4 ns | 1.55 KB | Generated reduced execution time and allocation for the order-placed dispatch workflow. |
| Bounded Context | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Bounded Context | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Domain Service | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Domain Service | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
| Event-Carried State Transfer | Construction | 7.552 ns | 48 B | 6.751 ns | 48 B | Same allocation; generated was slightly faster in this microbenchmark. |
Expand Down
1 change: 1 addition & 0 deletions docs/guides/pattern-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The source of truth is `PatternKitPatternCatalog` in `src/PatternKit.Examples/Pr
| Application Architecture | Service Layer | `IServiceOperation<TRequest,TResponse>` and `ServiceLayerOperation<TRequest,TResponse>` | Service Layer generator |
| Application Architecture | Domain Event | `IDomainEvent` and `DomainEventDispatcher<TEventBase>` | Domain Event generator |
| Application Architecture | Domain Service | `DomainServiceOperation<TRequest,TResponse>` and named registries | Domain Service generator |
| Application Architecture | Bounded Context | `BoundedContextDescriptor` capabilities and adapters | Bounded Context generator |
| Application Architecture | Table Data Gateway | `ITableDataGateway<TRow,TKey>` and `InMemoryTableDataGateway<TRow,TKey>` | Table Data Gateway generator |
| Application Architecture | Event Sourcing | `IEventStore<TEvent,TStreamId>` and `InMemoryEventStore<TEvent,TStreamId>` | Event Sourcing generator |
| Application Architecture | Feature Toggle | `IFeatureToggleSet<TContext>` and `FeatureToggleSet<TContext>` | Feature Toggle generator |
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ if (parser.Execute("123", out var value))

## 📚 Available Patterns

PatternKit covers 104 production-readiness patterns with fluent APIs, source-generated routes where applicable, IoC integration examples, TinyBDD coverage, and BenchmarkDotNet coverage-matrix validation:
PatternKit covers 105 production-readiness patterns with fluent APIs, source-generated routes where applicable, IoC integration examples, TinyBDD coverage, and BenchmarkDotNet coverage-matrix validation:

| Category | Count | Patterns |
| --- | ---: | --- |
| Application Architecture | 19 | Activity Tracker, Aggregate Root, Anti-Corruption Layer, Audit Log, CQRS, Data Mapper, Domain Event, Domain Service, Event Sourcing, Feature Toggle, Identity Map, Materialized View, Repository, Service Layer, Specification, Table Data Gateway, Transaction Script, Unit of Work, Value Object |
| Application Architecture | 20 | Activity Tracker, Aggregate Root, Anti-Corruption Layer, Audit Log, Bounded Context, CQRS, Data Mapper, Domain Event, Domain Service, Event Sourcing, Feature Toggle, Identity Map, Materialized View, Repository, Service Layer, Specification, Table Data Gateway, Transaction Script, Unit of Work, Value Object |
| Behavioral | 11 | Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor |
| Cloud Architecture | 17 | Ambassador, Backends for Frontends, Bulkhead, Cache-Aside, Circuit Breaker, External Configuration Store, Gateway Aggregation, Gateway Routing, Health Endpoint Monitoring, Leader Election, Priority Queue, Queue-Based Load Leveling, Rate Limiting, Retry, Scheduler Agent Supervisor, Sidecar, Strangler Fig |
| Creational | 5 | Abstract Factory, Builder, Factory Method, Prototype, Singleton |
Expand Down
25 changes: 25 additions & 0 deletions docs/patterns/application/bounded-context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Bounded Context

Bounded Context makes a domain boundary explicit: the capabilities it owns, the services that implement those capabilities, and the adapters required when models cross into or out of that boundary.

Use PatternKit's fluent path when the boundary is assembled dynamically or by configuration:

```csharp
var descriptor = BoundedContextDescriptor.Create("Fulfillment")
.AddCapability("quote shipment", typeof(IShipmentQuoter))
.AddCapability("allocate inventory", typeof(IInventoryAllocator))
.AddAdapter("Catalog", "Fulfillment", typeof(CatalogProduct), typeof(FulfillmentItem))
.Build();
```

Use the generated path when the boundary is stable and should be reviewed at compile time:

```csharp
[GenerateBoundedContextDescriptor("Fulfillment")]
[BoundedContextCapability("quote shipment", typeof(IShipmentQuoter))]
[BoundedContextCapability("allocate inventory", typeof(IInventoryAllocator))]
[BoundedContextAdapter("Catalog", "Fulfillment", typeof(CatalogProduct), typeof(FulfillmentItem))]
public static partial class FulfillmentContext;
```

The generated descriptor is suitable for `IServiceCollection` registration and for production-readiness checks that need to verify every context publishes its owned capabilities and model translations.
2 changes: 2 additions & 0 deletions docs/patterns/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@
href: application/domain-event.md
- name: Domain Service
href: application/domain-service.md
- name: Bounded Context
href: application/bounded-context.md
- name: Table Data Gateway
href: application/table-data-gateway.md
- name: Event Sourcing
Expand Down
Loading
Loading