Skip to content

Add Backends For Frontends (BFF) pattern (#300)#3543

Open
AnveshSrivastava wants to merge 2 commits into
iluwatar:masterfrom
AnveshSrivastava:backends-for-frontends-pattern
Open

Add Backends For Frontends (BFF) pattern (#300)#3543
AnveshSrivastava wants to merge 2 commits into
iluwatar:masterfrom
AnveshSrivastava:backends-for-frontends-pattern

Conversation

@AnveshSrivastava

Copy link
Copy Markdown

Summary

Closes #300

Implements the Backends For Frontends (BFF) pattern as a new module,
backends-for-frontends. Two client-specific gateways — MobileBff and
DesktopBff — sit in front of a shared set of downstream microservices
(AuthService, CartService, OrderService, SupplierService) and each
aggregates only the services its own client needs, reshaping the result into
a response tailored to that client:

  • MobileBff calls Auth + Cart + Order → returns a lean MobileDashboardResponse
    suited to a phone screen.
  • DesktopBff calls Auth + Order + Supplier → returns a richer
    DesktopDashboardResponse with back-office detail a mobile client never needs.

This satisfies the issue's acceptance criteria: distinct client-specific backends,
data aggregation from multiple downstream services per BFF, and an optimized,
purpose-built API for each client.

What's included

  • Domain models (Product, CartItem, User, Order, SupplierRecord)
  • Downstream service interfaces + in-memory implementations standing in for
    real microservices
  • ClientBff<T> contract + MobileBff / DesktopBff implementations
  • App.java demonstrating both BFFs against the same user
  • JUnit 5 tests for both BFFs and the demo entry point
  • Class diagram (etc/backends-for-frontends.png + .urm.puml), referenced
    from the README
  • README following the repo's standard pattern-page template

Verification

  • mvn -pl backends-for-frontends -am clean test — all tests passing
  • mvn checkstyle:check@validate -pl backends-for-frontends -am — 0 violations
  • mvn spotless:check -pl backends-for-frontends -B — clean
  • Coverage: 98% instructions, 100% methods, 100% classes (JaCoCo)
  • Full reactor build (mvn clean install, module excluded from unrelated flakes
    below) — green

Notes for reviewers

  • Two pre-existing, unrelated test failures were encountered while running the
    full reactor build and confirmed not caused by this change by reproducing
    them in isolation on a clean checkout:
    • rate-limiting-pattern's TokenBucketRateLimiterTest.shouldRefillTokensAfterTime
      is timing-flaky.
    • commander's test suite can hit OutOfMemoryError: unable to create native thread locally depending on OS thread limits, unrelated to this module.
  • While verifying Checkstyle compliance, I found that WhitespaceAround's
    allowEmptyConstructors/allowEmptyTypes properties are unset (default
    false) in the current Checkstyle config, which conflicts with Spotless/
    Google Java Format's formatting of empty {} bodies. This affects any record
    with a fully empty body — I counted at least 16 other existing modules with
    the same latent construct, which only avoid failing because Checkstyle isn't
    bound to the install lifecycle. I worked around it locally in this module's
    6 records by giving each a minimal documented compact constructor rather than
    a bare empty body, but didn't touch the shared Checkstyle config or any other
    module — happy to open a separate follow-up issue for that if it's useful.

Implements the BFF pattern with two client-specific gateways
(MobileBff, DesktopBff) aggregating shared downstream services
(AuthService, CartService, OrderService, SupplierService) into
client-tailored response shapes.

Closes iluwatar#300
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Analyzing changes in this PR...

This might take a few minutes, please wait

📥 Commits

Analyzing changes from base (2656d8e) to latest commit (3b1d5ca):

  • 3b1d5ca: Rename SupplierService lookup key to productName for clarity

The service is looked up by product name throughout the codebase, not
an actual product ID as the previous naming implied.

📁 Files being considered (2)

➕ backends-for-frontends/src/main/java/com/iluwatar/bff/service/SupplierService.java (1 hunk)
➕ backends-for-frontends/src/main/java/com/iluwatar/bff/service/impl/InMemorySupplierService.java (1 hunk)


autogenerated by presubmit.ai

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.84946% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.29%. Comparing base (74d2dbe) to head (3b1d5ca).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...iluwatar/bff/service/impl/InMemoryAuthService.java 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3543      +/-   ##
============================================
+ Coverage     83.24%   83.29%   +0.05%     
- Complexity     4025     4052      +27     
============================================
  Files          1060     1074      +14     
  Lines         14246    14339      +93     
  Branches        686      689       +3     
============================================
+ Hits          11859    11944      +85     
- Misses         2100     2107       +7     
- Partials        287      288       +1     

☔ View full report in Codecov by Harness.
📢 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.

The service is looked up by product name throughout the codebase, not
an actual product ID as the previous naming implied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backends for Frontends pattern

1 participant