Skip to content

feat: add Backends for Frontends pattern#324

Merged
JerrettDavis merged 2 commits into
mainfrom
feature/backends-for-frontends-314
May 22, 2026
Merged

feat: add Backends for Frontends pattern#324
JerrettDavis merged 2 commits into
mainfrom
feature/backends-for-frontends-314

Conversation

@JerrettDavis
Copy link
Copy Markdown
Owner

Summary

  • add Backends for Frontends runtime builder and source generator path
  • add commerce BFF production example with IServiceCollection and ASP.NET Core mapping
  • document the pattern/generator/example and wire production catalogs
  • add TinyBDD runtime, generator, abstraction, catalog, and example coverage

Closes #314.

Validation

  • dotnet build src\PatternKit.Core\PatternKit.Core.csproj -f net8.0 /p:UseSharedCompilation=false
  • dotnet build src\PatternKit.Core\PatternKit.Core.csproj -f net9.0 /p:UseSharedCompilation=false
  • dotnet build src\PatternKit.Core\PatternKit.Core.csproj -f net10.0 /p:UseSharedCompilation=false
  • dotnet build src\PatternKit.Core\PatternKit.Core.csproj -f netstandard2.0 /p:UseSharedCompilation=false
  • dotnet build src\PatternKit.Generators.Abstractions\PatternKit.Generators.Abstractions.csproj /p:UseSharedCompilation=false
  • dotnet build src\PatternKit.Generators\PatternKit.Generators.csproj /p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj -f net8.0 --no-restore --filter "FullyQualifiedName~BackendsForFrontendsTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj -f net9.0 --no-restore --filter "FullyQualifiedName~BackendsForFrontendsTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj -f net10.0 --no-restore --filter "FullyQualifiedName~BackendsForFrontendsTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj -f net8.0 --no-restore --filter "FullyQualifiedNameBackendsForFrontendsGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj -f net9.0 --no-restore --filter "FullyQualifiedNameBackendsForFrontendsGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=false
  • dotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj -f net10.0 --no-restore --filter "FullyQualifiedNameBackendsForFrontendsGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=false
  • git diff --check

Note: the local full examples build still hits the existing analyzer/compiler mismatch (CS9057 with generated demo types); hosted CI validates the full examples/docs surface.

Copilot AI review requested due to automatic review settings May 22, 2026 17:40
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Test Results

783 tests   783 ✅  28s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit eec4eab.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

🔍 PR Validation Results

Version: ``

✅ Validation Steps

  • Build solution
  • Run tests
  • Build documentation
  • Dry-run NuGet packaging

📊 Artifacts

Dry-run artifacts have been uploaded and will be available for 7 days.


This comment was automatically generated by the PR validation workflow.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 90.71429% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.78%. Comparing base (c08bcc4) to head (eec4eab).

Files with missing lines Patch % Lines
...kendsForFrontends/BackendsForFrontendsGenerator.cs 90.90% 13 Missing ⚠️
...rFrontendsDemo/CommerceBackendsForFrontendsDemo.cs 70.58% 10 Missing ⚠️
...Cloud/BackendsForFrontends/BackendsForFrontends.cs 95.31% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #324      +/-   ##
==========================================
+ Coverage   89.88%   95.78%   +5.90%     
==========================================
  Files         460      464       +4     
  Lines       38077    38355     +278     
  Branches     5424     5468      +44     
==========================================
+ Hits        34227    36740    +2513     
+ Misses       1715     1615     -100     
+ Partials     2135        0    -2135     
Flag Coverage Δ
unittests 95.78% <90.71%> (+5.90%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces Backends for Frontends (BFF) as a first-class PatternKit cloud-architecture pattern, including a fluent runtime API, a Roslyn incremental generator path, and a production-style commerce example wired into the PatternKit catalogs and documentation.

Changes:

  • Added BackendsForFrontends<TRequest,TResponse> runtime builder + result/context types.
  • Added BackendsForFrontendsGenerator and new generator attributes + diagnostics registration.
  • Added commerce BFF example (DI + minimal API mapping), tests, and docs/catalog coverage.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/PatternKit.Tests/Cloud/BackendsForFrontends/BackendsForFrontendsTests.cs Adds runtime behavioral tests for fluent BFF dispatch, fallback, and validation.
test/PatternKit.Generators.Tests/BackendsForFrontendsGeneratorTests.cs Adds generator tests for successful factory generation + invalid-declaration diagnostics.
test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs Extends attribute coverage tests to include new BFF generator attributes.
test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs Updates production-readiness catalog expectations for the new pattern and family counts.
test/PatternKit.Examples.Tests/BackendsForFrontendsDemo/CommerceBackendsForFrontendsDemoTests.cs Adds end-to-end example tests (fluent + generated + DI registration + catalogs).
src/PatternKit.Generators/BackendsForFrontends/BackendsForFrontendsGenerator.cs Implements the incremental generator that emits a BFF factory from selector/handler pairs.
src/PatternKit.Generators/AnalyzerReleases.Unshipped.md Registers new analyzer diagnostic IDs PKBFF001–PKBFF004.
src/PatternKit.Generators.Abstractions/Cloud/BackendsForFrontendsAttributes.cs Introduces [GenerateBackendsForFrontends] and related method-level attributes.
src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs Adds the BFF pattern entry (docs/source/tests/example links) to the pattern catalog.
src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs Adds the commerce BFF example to the example catalog with integration-surface metadata.
src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs Wires the commerce BFF example into the aggregate example registration extensions.
src/PatternKit.Examples/BackendsForFrontendsDemo/CommerceBackendsForFrontendsDemo.cs Adds the commerce BFF demo (fluent + generated host + DI + minimal API mapping).
src/PatternKit.Core/Cloud/BackendsForFrontends/BackendsForFrontends.cs Adds the core BFF runtime types (context, result, builder, dispatch).
docs/patterns/toc.yml Adds BFF to the Cloud Architecture patterns TOC.
docs/patterns/cloud/backends-for-frontends.md Adds the BFF pattern overview and fluent usage snippet.
docs/guides/pattern-coverage.md Updates the pattern coverage matrix with Backends for Frontends.
docs/generators/toc.yml Adds the BFF generator page to the generators TOC.
docs/generators/index.md Adds BFF to the generators index table.
docs/generators/backends-for-frontends.md Documents the BFF generator API and diagnostics list.
docs/examples/toc.yml Adds the commerce BFF example to the examples TOC.
docs/examples/index.md Adds the commerce BFF example to the examples index list.
docs/examples/commerce-backends-for-frontends.md Documents how to use/import the commerce BFF example and endpoint mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +31
public bool Handled { get; }

public bool Failed => !Handled;

Comment on lines +74 to +87
if (selectors.Length == 0 || selectors.Length != handlers.Length || fallbacks.Length > 1)
{
context.ReportDiagnostic(Diagnostic.Create(MissingMembers, node.Identifier.GetLocation(), type.Name));
return;
}

var allNames = selectors.Select(static item => item.Name).Concat(handlers.Select(static item => item.Name)).ToArray();
var duplicate = allNames.GroupBy(static item => item, StringComparer.OrdinalIgnoreCase).FirstOrDefault(static group => group.Count() > 2);
if (duplicate is not null)
{
context.ReportDiagnostic(Diagnostic.Create(DuplicateFrontend, node.Identifier.GetLocation(), duplicate.Key));
return;
}

Comment on lines +74 to +79
if (selectors.Length == 0 || selectors.Length != handlers.Length || fallbacks.Length > 1)
{
context.ReportDiagnostic(Diagnostic.Create(MissingMembers, node.Identifier.GetLocation(), type.Name));
return;
}

@github-actions
Copy link
Copy Markdown
Contributor

Code Coverage

Summary
  Generated on: 05/22/2026 - 17:56:02
  Coverage date: 05/22/2026 - 17:53:59 - 05/22/2026 - 17:55:50
  Parser: MultiReport (9x Cobertura)
  Assemblies: 4
  Classes: 1385
  Files: 567
  Line coverage: 94.7%
  Covered lines: 37723
  Uncovered lines: 2107
  Coverable lines: 39830
  Total lines: 87459
  Branch coverage: 75.6% (10997 of 14546)
  Covered branches: 10997
  Total branches: 14546
  Method coverage: 96.2% (7407 of 7695)
  Full method coverage: 88.3% (6797 of 7695)
  Covered methods: 7407
  Fully covered methods: 6797
  Total methods: 7695

PatternKit.Core                                                                                                     95.9%
  PatternKit.Application.AntiCorruption.AntiCorruptionLayer<T1, T2>                                                 90.4%
  PatternKit.Application.AntiCorruption.AntiCorruptionResult<T>                                                      100%
  PatternKit.Application.AuditLog.AuditLogAppendResult<T>                                                           85.7%
  PatternKit.Application.AuditLog.InMemoryAuditLog<T1, T2>                                                          95.4%
  PatternKit.Application.DataMapping.DataMapper<T1, T2>                                                             94.6%
  PatternKit.Application.DataMapping.DataMapperError                                                                  90%
  PatternKit.Application.DataMapping.DataMapperResult<T>                                                            84.6%
  PatternKit.Application.DomainEvents.DomainEventDispatcher<T>                                                      95.4%
  PatternKit.Application.DomainEvents.DomainEventDispatchResult                                                      100%
  PatternKit.Application.EventSourcing.EventStoreAppendResult                                                        100%
  PatternKit.Application.EventSourcing.InMemoryEventStore<T1, T2>                                                   97.9%
  PatternKit.Application.EventSourcing.StoredEvent<T1, T2>                                                            80%
  PatternKit.Application.FeatureToggles.FeatureToggleDecision                                                       87.5%
  PatternKit.Application.FeatureToggles.FeatureToggleRule<T>                                                         100%
  PatternKit.Application.FeatureToggles.FeatureToggleSet<T>                                                         96.9%
  PatternKit.Application.IdentityMap.IdentityMap<T1, T2>                                                             100%
  PatternKit.Application.IdentityMap.IdentityMapResult<T>                                                           92.8%
  PatternKit.Application.MaterializedViews.MaterializedView<T1, T2>                                                 98.4%
  PatternKit.Application.Repository.InMemoryRepository<T1, T2>                                                      92.8%
  PatternKit.Application.Repository.RepositoryResult<T>                                                             93.3%
  PatternKit.Application.ServiceLayer.ServiceLayerOperation<T1, T2>                                                 96.7%
  PatternKit.Application.ServiceLayer.ServiceLayerResult<T>                                                         94.7%
  PatternKit.Application.ServiceLayer.ServiceLayerRule<T>                                                            100%
  PatternKit.Application.Specification.Specification<T>                                                              100%
  PatternKit.Application.Specification.SpecificationRegistry<T>                                                     93.3%
  PatternKit.Application.TableDataGateway.InMemoryTableDataGateway<T1, T2>                                            86%
  PatternKit.Application.TableDataGateway.TableGatewayResult<T>                                                     82.3%
  PatternKit.Application.TransactionScript.TransactionScript<T1, T2>                                                  97%
  PatternKit.Application.TransactionScript.TransactionScriptError                                                     90%
  PatternKit.Application.TransactionScript.TransactionScriptResult<T>                                                100%
  PatternKit.Application.UnitOfWork.UnitOfWork                                                                      90.9%
  PatternKit.Application.UnitOfWork.UnitOfWorkResult                                                                94.7%
  PatternKit.Application.UnitOfWork.UnitOfWorkRollbackResult                                                         100%
  PatternKit.Application.UnitOfWork.UnitOfWorkStep                                                                   100%
  PatternKit.Behavioral.Chain.ActionChain<T>                                                                         100%
  PatternKit.Behavioral.Chain.AsyncActionChain<T>                                                                    100%
  PatternKit.Behavioral.Chain.AsyncResultChain<T1, T2>                                                              97.7%
  PatternKit.Behavioral.Chain.ResultChain<T1, T2>                                                                    100%

@JerrettDavis JerrettDavis merged commit 0318b46 into main May 22, 2026
12 checks passed
@JerrettDavis JerrettDavis deleted the feature/backends-for-frontends-314 branch May 22, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Backends for Frontends pattern

2 participants