feat: add Backends for Frontends pattern#324
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results783 tests 783 ✅ 28s ⏱️ Results for commit eec4eab. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
BackendsForFrontendsGeneratorand 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.
| public bool Handled { get; } | ||
|
|
||
| public bool Failed => !Handled; | ||
|
|
| 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; | ||
| } | ||
|
|
| if (selectors.Length == 0 || selectors.Length != handlers.Length || fallbacks.Length > 1) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(MissingMembers, node.Identifier.GetLocation(), type.Name)); | ||
| return; | ||
| } | ||
|
|
Code Coverage |
Summary
Closes #314.
Validation
BackendsForFrontendsGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseBackendsForFrontendsGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseBackendsForFrontendsGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseNote: 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.