@wazir-dev/cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (629) hide show
  1. package/AGENTS.md +111 -0
  2. package/CHANGELOG.md +14 -0
  3. package/CONTRIBUTING.md +101 -0
  4. package/LICENSE +21 -0
  5. package/README.md +314 -0
  6. package/assets/composition-engine.mmd +34 -0
  7. package/assets/demo-script.sh +17 -0
  8. package/assets/logo-dark.svg +14 -0
  9. package/assets/logo.svg +14 -0
  10. package/assets/pipeline.mmd +39 -0
  11. package/assets/record-demo.sh +51 -0
  12. package/docs/README.md +51 -0
  13. package/docs/adapters/context-mode.md +60 -0
  14. package/docs/concepts/architecture.md +87 -0
  15. package/docs/concepts/artifact-model.md +60 -0
  16. package/docs/concepts/composition-engine.md +36 -0
  17. package/docs/concepts/indexing-and-recall.md +160 -0
  18. package/docs/concepts/observability.md +41 -0
  19. package/docs/concepts/roles-and-workflows.md +59 -0
  20. package/docs/concepts/terminology-policy.md +27 -0
  21. package/docs/getting-started/01-installation.md +78 -0
  22. package/docs/getting-started/02-first-run.md +102 -0
  23. package/docs/getting-started/03-adding-to-project.md +15 -0
  24. package/docs/getting-started/04-host-setup.md +15 -0
  25. package/docs/guides/ci-integration.md +15 -0
  26. package/docs/guides/creating-skills.md +15 -0
  27. package/docs/guides/expertise-module-authoring.md +15 -0
  28. package/docs/guides/hook-development.md +15 -0
  29. package/docs/guides/memory-and-learnings.md +34 -0
  30. package/docs/guides/multi-host-export.md +15 -0
  31. package/docs/guides/troubleshooting.md +101 -0
  32. package/docs/guides/writing-custom-roles.md +15 -0
  33. package/docs/plans/2026-03-15-cli-pipeline-integration-design.md +592 -0
  34. package/docs/plans/2026-03-15-cli-pipeline-integration-plan.md +598 -0
  35. package/docs/plans/2026-03-15-docs-enforcement-plan.md +238 -0
  36. package/docs/readmes/INDEX.md +99 -0
  37. package/docs/readmes/features/expertise/README.md +171 -0
  38. package/docs/readmes/features/exports/README.md +222 -0
  39. package/docs/readmes/features/hooks/README.md +103 -0
  40. package/docs/readmes/features/hooks/loop-cap-guard.md +133 -0
  41. package/docs/readmes/features/hooks/post-tool-capture.md +121 -0
  42. package/docs/readmes/features/hooks/post-tool-lint.md +130 -0
  43. package/docs/readmes/features/hooks/pre-compact-summary.md +122 -0
  44. package/docs/readmes/features/hooks/pre-tool-capture-route.md +100 -0
  45. package/docs/readmes/features/hooks/protected-path-write-guard.md +128 -0
  46. package/docs/readmes/features/hooks/session-start.md +119 -0
  47. package/docs/readmes/features/hooks/stop-handoff-harvest.md +125 -0
  48. package/docs/readmes/features/roles/README.md +157 -0
  49. package/docs/readmes/features/roles/clarifier.md +152 -0
  50. package/docs/readmes/features/roles/content-author.md +190 -0
  51. package/docs/readmes/features/roles/designer.md +193 -0
  52. package/docs/readmes/features/roles/executor.md +184 -0
  53. package/docs/readmes/features/roles/learner.md +210 -0
  54. package/docs/readmes/features/roles/planner.md +182 -0
  55. package/docs/readmes/features/roles/researcher.md +164 -0
  56. package/docs/readmes/features/roles/reviewer.md +184 -0
  57. package/docs/readmes/features/roles/specifier.md +162 -0
  58. package/docs/readmes/features/roles/verifier.md +215 -0
  59. package/docs/readmes/features/schemas/README.md +178 -0
  60. package/docs/readmes/features/skills/README.md +63 -0
  61. package/docs/readmes/features/skills/brainstorming.md +96 -0
  62. package/docs/readmes/features/skills/debugging.md +148 -0
  63. package/docs/readmes/features/skills/design.md +120 -0
  64. package/docs/readmes/features/skills/prepare-next.md +109 -0
  65. package/docs/readmes/features/skills/run-audit.md +159 -0
  66. package/docs/readmes/features/skills/scan-project.md +109 -0
  67. package/docs/readmes/features/skills/self-audit.md +176 -0
  68. package/docs/readmes/features/skills/tdd.md +137 -0
  69. package/docs/readmes/features/skills/using-skills.md +92 -0
  70. package/docs/readmes/features/skills/verification.md +120 -0
  71. package/docs/readmes/features/skills/writing-plans.md +104 -0
  72. package/docs/readmes/features/tooling/README.md +320 -0
  73. package/docs/readmes/features/workflows/README.md +186 -0
  74. package/docs/readmes/features/workflows/author.md +181 -0
  75. package/docs/readmes/features/workflows/clarify.md +154 -0
  76. package/docs/readmes/features/workflows/design-review.md +171 -0
  77. package/docs/readmes/features/workflows/design.md +169 -0
  78. package/docs/readmes/features/workflows/discover.md +162 -0
  79. package/docs/readmes/features/workflows/execute.md +173 -0
  80. package/docs/readmes/features/workflows/learn.md +167 -0
  81. package/docs/readmes/features/workflows/plan-review.md +165 -0
  82. package/docs/readmes/features/workflows/plan.md +170 -0
  83. package/docs/readmes/features/workflows/prepare-next.md +167 -0
  84. package/docs/readmes/features/workflows/review.md +169 -0
  85. package/docs/readmes/features/workflows/run-audit.md +191 -0
  86. package/docs/readmes/features/workflows/spec-challenge.md +159 -0
  87. package/docs/readmes/features/workflows/specify.md +160 -0
  88. package/docs/readmes/features/workflows/verify.md +177 -0
  89. package/docs/readmes/packages/README.md +50 -0
  90. package/docs/readmes/packages/ajv.md +117 -0
  91. package/docs/readmes/packages/context-mode.md +118 -0
  92. package/docs/readmes/packages/gray-matter.md +116 -0
  93. package/docs/readmes/packages/node-test.md +137 -0
  94. package/docs/readmes/packages/yaml.md +112 -0
  95. package/docs/reference/configuration-reference.md +159 -0
  96. package/docs/reference/expertise-index.md +52 -0
  97. package/docs/reference/git-flow.md +43 -0
  98. package/docs/reference/hooks.md +87 -0
  99. package/docs/reference/host-exports.md +50 -0
  100. package/docs/reference/launch-checklist.md +172 -0
  101. package/docs/reference/marketplace-listings.md +76 -0
  102. package/docs/reference/release-process.md +34 -0
  103. package/docs/reference/roles-reference.md +77 -0
  104. package/docs/reference/skills.md +33 -0
  105. package/docs/reference/templates.md +29 -0
  106. package/docs/reference/tooling-cli.md +94 -0
  107. package/docs/truth-claims.yaml +222 -0
  108. package/expertise/PROGRESS.md +63 -0
  109. package/expertise/README.md +18 -0
  110. package/expertise/antipatterns/PROGRESS.md +56 -0
  111. package/expertise/antipatterns/backend/api-design-antipatterns.md +1271 -0
  112. package/expertise/antipatterns/backend/auth-antipatterns.md +1195 -0
  113. package/expertise/antipatterns/backend/caching-antipatterns.md +622 -0
  114. package/expertise/antipatterns/backend/database-antipatterns.md +1038 -0
  115. package/expertise/antipatterns/backend/index.md +24 -0
  116. package/expertise/antipatterns/backend/microservices-antipatterns.md +850 -0
  117. package/expertise/antipatterns/code/architecture-antipatterns.md +919 -0
  118. package/expertise/antipatterns/code/async-antipatterns.md +622 -0
  119. package/expertise/antipatterns/code/code-smells.md +1186 -0
  120. package/expertise/antipatterns/code/dependency-antipatterns.md +1209 -0
  121. package/expertise/antipatterns/code/error-handling-antipatterns.md +1360 -0
  122. package/expertise/antipatterns/code/index.md +27 -0
  123. package/expertise/antipatterns/code/naming-and-abstraction.md +1118 -0
  124. package/expertise/antipatterns/code/state-management-antipatterns.md +1076 -0
  125. package/expertise/antipatterns/code/testing-antipatterns.md +1053 -0
  126. package/expertise/antipatterns/design/accessibility-antipatterns.md +1136 -0
  127. package/expertise/antipatterns/design/dark-patterns.md +1121 -0
  128. package/expertise/antipatterns/design/index.md +22 -0
  129. package/expertise/antipatterns/design/ui-antipatterns.md +1202 -0
  130. package/expertise/antipatterns/design/ux-antipatterns.md +680 -0
  131. package/expertise/antipatterns/frontend/css-layout-antipatterns.md +691 -0
  132. package/expertise/antipatterns/frontend/flutter-antipatterns.md +1827 -0
  133. package/expertise/antipatterns/frontend/index.md +23 -0
  134. package/expertise/antipatterns/frontend/mobile-antipatterns.md +573 -0
  135. package/expertise/antipatterns/frontend/react-antipatterns.md +1128 -0
  136. package/expertise/antipatterns/frontend/spa-antipatterns.md +1235 -0
  137. package/expertise/antipatterns/index.md +31 -0
  138. package/expertise/antipatterns/performance/index.md +20 -0
  139. package/expertise/antipatterns/performance/performance-antipatterns.md +1013 -0
  140. package/expertise/antipatterns/performance/premature-optimization.md +623 -0
  141. package/expertise/antipatterns/performance/scaling-antipatterns.md +785 -0
  142. package/expertise/antipatterns/process/ai-coding-antipatterns.md +853 -0
  143. package/expertise/antipatterns/process/code-review-antipatterns.md +656 -0
  144. package/expertise/antipatterns/process/deployment-antipatterns.md +920 -0
  145. package/expertise/antipatterns/process/index.md +23 -0
  146. package/expertise/antipatterns/process/technical-debt-antipatterns.md +647 -0
  147. package/expertise/antipatterns/security/index.md +20 -0
  148. package/expertise/antipatterns/security/secrets-antipatterns.md +849 -0
  149. package/expertise/antipatterns/security/security-theater.md +843 -0
  150. package/expertise/antipatterns/security/vulnerability-patterns.md +801 -0
  151. package/expertise/architecture/PROGRESS.md +70 -0
  152. package/expertise/architecture/data/caching-architecture.md +671 -0
  153. package/expertise/architecture/data/data-consistency.md +574 -0
  154. package/expertise/architecture/data/data-modeling.md +536 -0
  155. package/expertise/architecture/data/event-streams-and-queues.md +634 -0
  156. package/expertise/architecture/data/index.md +25 -0
  157. package/expertise/architecture/data/search-architecture.md +663 -0
  158. package/expertise/architecture/data/sql-vs-nosql.md +708 -0
  159. package/expertise/architecture/decisions/architecture-decision-records.md +640 -0
  160. package/expertise/architecture/decisions/build-vs-buy.md +616 -0
  161. package/expertise/architecture/decisions/index.md +23 -0
  162. package/expertise/architecture/decisions/monolith-to-microservices.md +790 -0
  163. package/expertise/architecture/decisions/technology-selection.md +616 -0
  164. package/expertise/architecture/distributed/cap-theorem-and-tradeoffs.md +800 -0
  165. package/expertise/architecture/distributed/circuit-breaker-bulkhead.md +741 -0
  166. package/expertise/architecture/distributed/consensus-and-coordination.md +796 -0
  167. package/expertise/architecture/distributed/distributed-systems-fundamentals.md +564 -0
  168. package/expertise/architecture/distributed/idempotency-and-retry.md +796 -0
  169. package/expertise/architecture/distributed/index.md +25 -0
  170. package/expertise/architecture/distributed/saga-pattern.md +797 -0
  171. package/expertise/architecture/foundations/architectural-thinking.md +460 -0
  172. package/expertise/architecture/foundations/coupling-and-cohesion.md +770 -0
  173. package/expertise/architecture/foundations/design-principles-solid.md +649 -0
  174. package/expertise/architecture/foundations/domain-driven-design.md +719 -0
  175. package/expertise/architecture/foundations/index.md +25 -0
  176. package/expertise/architecture/foundations/separation-of-concerns.md +472 -0
  177. package/expertise/architecture/foundations/twelve-factor-app.md +797 -0
  178. package/expertise/architecture/index.md +34 -0
  179. package/expertise/architecture/integration/api-design-graphql.md +638 -0
  180. package/expertise/architecture/integration/api-design-grpc.md +804 -0
  181. package/expertise/architecture/integration/api-design-rest.md +892 -0
  182. package/expertise/architecture/integration/index.md +25 -0
  183. package/expertise/architecture/integration/third-party-integration.md +795 -0
  184. package/expertise/architecture/integration/webhooks-and-callbacks.md +1152 -0
  185. package/expertise/architecture/integration/websockets-realtime.md +791 -0
  186. package/expertise/architecture/mobile-architecture/index.md +22 -0
  187. package/expertise/architecture/mobile-architecture/mobile-app-architecture.md +780 -0
  188. package/expertise/architecture/mobile-architecture/mobile-backend-for-frontend.md +670 -0
  189. package/expertise/architecture/mobile-architecture/offline-first.md +719 -0
  190. package/expertise/architecture/mobile-architecture/push-and-sync.md +782 -0
  191. package/expertise/architecture/patterns/cqrs-event-sourcing.md +717 -0
  192. package/expertise/architecture/patterns/event-driven.md +797 -0
  193. package/expertise/architecture/patterns/hexagonal-clean-architecture.md +870 -0
  194. package/expertise/architecture/patterns/index.md +27 -0
  195. package/expertise/architecture/patterns/layered-architecture.md +736 -0
  196. package/expertise/architecture/patterns/microservices.md +753 -0
  197. package/expertise/architecture/patterns/modular-monolith.md +692 -0
  198. package/expertise/architecture/patterns/monolith.md +626 -0
  199. package/expertise/architecture/patterns/plugin-architecture.md +735 -0
  200. package/expertise/architecture/patterns/serverless.md +780 -0
  201. package/expertise/architecture/scaling/database-scaling.md +615 -0
  202. package/expertise/architecture/scaling/feature-flags-and-rollouts.md +757 -0
  203. package/expertise/architecture/scaling/horizontal-vs-vertical.md +606 -0
  204. package/expertise/architecture/scaling/index.md +24 -0
  205. package/expertise/architecture/scaling/multi-tenancy.md +800 -0
  206. package/expertise/architecture/scaling/stateless-design.md +787 -0
  207. package/expertise/backend/embedded-firmware.md +625 -0
  208. package/expertise/backend/go.md +853 -0
  209. package/expertise/backend/index.md +24 -0
  210. package/expertise/backend/java-spring.md +448 -0
  211. package/expertise/backend/node-typescript.md +625 -0
  212. package/expertise/backend/python-fastapi.md +724 -0
  213. package/expertise/backend/rust.md +458 -0
  214. package/expertise/backend/solidity.md +711 -0
  215. package/expertise/composition-map.yaml +443 -0
  216. package/expertise/content/foundations/content-modeling.md +395 -0
  217. package/expertise/content/foundations/editorial-standards.md +449 -0
  218. package/expertise/content/foundations/index.md +24 -0
  219. package/expertise/content/foundations/microcopy.md +455 -0
  220. package/expertise/content/foundations/terminology-governance.md +509 -0
  221. package/expertise/content/index.md +34 -0
  222. package/expertise/content/patterns/accessibility-copy.md +518 -0
  223. package/expertise/content/patterns/index.md +24 -0
  224. package/expertise/content/patterns/notification-content.md +433 -0
  225. package/expertise/content/patterns/sample-content.md +486 -0
  226. package/expertise/content/patterns/state-copy.md +439 -0
  227. package/expertise/design/PROGRESS.md +58 -0
  228. package/expertise/design/disciplines/dark-mode-theming.md +577 -0
  229. package/expertise/design/disciplines/design-systems.md +595 -0
  230. package/expertise/design/disciplines/index.md +25 -0
  231. package/expertise/design/disciplines/information-architecture.md +800 -0
  232. package/expertise/design/disciplines/interaction-design.md +788 -0
  233. package/expertise/design/disciplines/responsive-design.md +552 -0
  234. package/expertise/design/disciplines/usability-testing.md +516 -0
  235. package/expertise/design/disciplines/user-research.md +792 -0
  236. package/expertise/design/foundations/accessibility-design.md +796 -0
  237. package/expertise/design/foundations/color-theory.md +797 -0
  238. package/expertise/design/foundations/iconography.md +795 -0
  239. package/expertise/design/foundations/index.md +26 -0
  240. package/expertise/design/foundations/motion-and-animation.md +653 -0
  241. package/expertise/design/foundations/rtl-design.md +585 -0
  242. package/expertise/design/foundations/spacing-and-layout.md +607 -0
  243. package/expertise/design/foundations/typography.md +800 -0
  244. package/expertise/design/foundations/visual-hierarchy.md +761 -0
  245. package/expertise/design/index.md +32 -0
  246. package/expertise/design/patterns/authentication-flows.md +474 -0
  247. package/expertise/design/patterns/content-consumption.md +789 -0
  248. package/expertise/design/patterns/data-display.md +618 -0
  249. package/expertise/design/patterns/e-commerce.md +1494 -0
  250. package/expertise/design/patterns/feedback-and-states.md +642 -0
  251. package/expertise/design/patterns/forms-and-input.md +819 -0
  252. package/expertise/design/patterns/gamification.md +801 -0
  253. package/expertise/design/patterns/index.md +31 -0
  254. package/expertise/design/patterns/microinteractions.md +449 -0
  255. package/expertise/design/patterns/navigation.md +800 -0
  256. package/expertise/design/patterns/notifications.md +705 -0
  257. package/expertise/design/patterns/onboarding.md +700 -0
  258. package/expertise/design/patterns/search-and-filter.md +601 -0
  259. package/expertise/design/patterns/settings-and-preferences.md +768 -0
  260. package/expertise/design/patterns/social-and-community.md +748 -0
  261. package/expertise/design/platforms/desktop-native.md +612 -0
  262. package/expertise/design/platforms/index.md +25 -0
  263. package/expertise/design/platforms/mobile-android.md +825 -0
  264. package/expertise/design/platforms/mobile-cross-platform.md +983 -0
  265. package/expertise/design/platforms/mobile-ios.md +699 -0
  266. package/expertise/design/platforms/tablet.md +794 -0
  267. package/expertise/design/platforms/web-dashboard.md +790 -0
  268. package/expertise/design/platforms/web-responsive.md +550 -0
  269. package/expertise/design/psychology/behavioral-nudges.md +449 -0
  270. package/expertise/design/psychology/cognitive-load.md +1191 -0
  271. package/expertise/design/psychology/error-psychology.md +778 -0
  272. package/expertise/design/psychology/index.md +22 -0
  273. package/expertise/design/psychology/persuasive-design.md +736 -0
  274. package/expertise/design/psychology/user-mental-models.md +623 -0
  275. package/expertise/design/tooling/open-pencil.md +266 -0
  276. package/expertise/frontend/angular.md +1073 -0
  277. package/expertise/frontend/desktop-electron.md +546 -0
  278. package/expertise/frontend/flutter.md +782 -0
  279. package/expertise/frontend/index.md +27 -0
  280. package/expertise/frontend/native-android.md +409 -0
  281. package/expertise/frontend/native-ios.md +490 -0
  282. package/expertise/frontend/react-native.md +1160 -0
  283. package/expertise/frontend/react.md +808 -0
  284. package/expertise/frontend/vue.md +1089 -0
  285. package/expertise/humanize/domain-rules-code.md +79 -0
  286. package/expertise/humanize/domain-rules-content.md +67 -0
  287. package/expertise/humanize/domain-rules-technical-docs.md +56 -0
  288. package/expertise/humanize/index.md +35 -0
  289. package/expertise/humanize/self-audit-checklist.md +87 -0
  290. package/expertise/humanize/sentence-patterns.md +218 -0
  291. package/expertise/humanize/vocabulary-blacklist.md +105 -0
  292. package/expertise/i18n/PROGRESS.md +65 -0
  293. package/expertise/i18n/advanced/accessibility-and-i18n.md +28 -0
  294. package/expertise/i18n/advanced/bidirectional-text-algorithm.md +38 -0
  295. package/expertise/i18n/advanced/complex-scripts.md +30 -0
  296. package/expertise/i18n/advanced/performance-and-i18n.md +27 -0
  297. package/expertise/i18n/advanced/testing-i18n.md +28 -0
  298. package/expertise/i18n/content/content-adaptation.md +23 -0
  299. package/expertise/i18n/content/locale-specific-formatting.md +23 -0
  300. package/expertise/i18n/content/machine-translation-integration.md +28 -0
  301. package/expertise/i18n/content/translation-management.md +29 -0
  302. package/expertise/i18n/foundations/date-time-calendars.md +67 -0
  303. package/expertise/i18n/foundations/i18n-architecture.md +272 -0
  304. package/expertise/i18n/foundations/locale-and-language-tags.md +79 -0
  305. package/expertise/i18n/foundations/numbers-currency-units.md +61 -0
  306. package/expertise/i18n/foundations/pluralization-and-gender.md +109 -0
  307. package/expertise/i18n/foundations/string-externalization.md +236 -0
  308. package/expertise/i18n/foundations/text-direction-bidi.md +241 -0
  309. package/expertise/i18n/foundations/unicode-and-encoding.md +86 -0
  310. package/expertise/i18n/index.md +38 -0
  311. package/expertise/i18n/platform/backend-i18n.md +31 -0
  312. package/expertise/i18n/platform/flutter-i18n.md +148 -0
  313. package/expertise/i18n/platform/native-android-i18n.md +36 -0
  314. package/expertise/i18n/platform/native-ios-i18n.md +36 -0
  315. package/expertise/i18n/platform/react-i18n.md +103 -0
  316. package/expertise/i18n/platform/web-css-i18n.md +81 -0
  317. package/expertise/i18n/rtl/arabic-specific.md +175 -0
  318. package/expertise/i18n/rtl/hebrew-specific.md +149 -0
  319. package/expertise/i18n/rtl/rtl-animations-and-transitions.md +111 -0
  320. package/expertise/i18n/rtl/rtl-forms-and-input.md +161 -0
  321. package/expertise/i18n/rtl/rtl-fundamentals.md +211 -0
  322. package/expertise/i18n/rtl/rtl-icons-and-images.md +181 -0
  323. package/expertise/i18n/rtl/rtl-layout-mirroring.md +252 -0
  324. package/expertise/i18n/rtl/rtl-navigation-and-gestures.md +107 -0
  325. package/expertise/i18n/rtl/rtl-testing-and-qa.md +147 -0
  326. package/expertise/i18n/rtl/rtl-typography.md +160 -0
  327. package/expertise/index.md +113 -0
  328. package/expertise/index.yaml +216 -0
  329. package/expertise/infrastructure/cloud-aws.md +597 -0
  330. package/expertise/infrastructure/cloud-gcp.md +599 -0
  331. package/expertise/infrastructure/cybersecurity.md +816 -0
  332. package/expertise/infrastructure/database-mongodb.md +447 -0
  333. package/expertise/infrastructure/database-postgres.md +400 -0
  334. package/expertise/infrastructure/devops-cicd.md +787 -0
  335. package/expertise/infrastructure/index.md +27 -0
  336. package/expertise/performance/PROGRESS.md +50 -0
  337. package/expertise/performance/backend/api-latency.md +1204 -0
  338. package/expertise/performance/backend/background-jobs.md +506 -0
  339. package/expertise/performance/backend/connection-pooling.md +1209 -0
  340. package/expertise/performance/backend/database-query-optimization.md +515 -0
  341. package/expertise/performance/backend/index.md +23 -0
  342. package/expertise/performance/backend/rate-limiting-and-throttling.md +971 -0
  343. package/expertise/performance/foundations/algorithmic-complexity.md +954 -0
  344. package/expertise/performance/foundations/caching-strategies.md +489 -0
  345. package/expertise/performance/foundations/concurrency-and-parallelism.md +847 -0
  346. package/expertise/performance/foundations/index.md +24 -0
  347. package/expertise/performance/foundations/measuring-and-profiling.md +440 -0
  348. package/expertise/performance/foundations/memory-management.md +964 -0
  349. package/expertise/performance/foundations/performance-budgets.md +1314 -0
  350. package/expertise/performance/index.md +31 -0
  351. package/expertise/performance/infrastructure/auto-scaling.md +1059 -0
  352. package/expertise/performance/infrastructure/cdn-and-edge.md +1081 -0
  353. package/expertise/performance/infrastructure/index.md +22 -0
  354. package/expertise/performance/infrastructure/load-balancing.md +1081 -0
  355. package/expertise/performance/infrastructure/observability.md +1079 -0
  356. package/expertise/performance/mobile/index.md +23 -0
  357. package/expertise/performance/mobile/mobile-animations.md +544 -0
  358. package/expertise/performance/mobile/mobile-memory-battery.md +416 -0
  359. package/expertise/performance/mobile/mobile-network.md +452 -0
  360. package/expertise/performance/mobile/mobile-rendering.md +599 -0
  361. package/expertise/performance/mobile/mobile-startup-time.md +505 -0
  362. package/expertise/performance/platform-specific/flutter-performance.md +647 -0
  363. package/expertise/performance/platform-specific/index.md +22 -0
  364. package/expertise/performance/platform-specific/node-performance.md +1307 -0
  365. package/expertise/performance/platform-specific/postgres-performance.md +1366 -0
  366. package/expertise/performance/platform-specific/react-performance.md +1403 -0
  367. package/expertise/performance/web/bundle-optimization.md +1239 -0
  368. package/expertise/performance/web/image-and-media.md +636 -0
  369. package/expertise/performance/web/index.md +24 -0
  370. package/expertise/performance/web/network-optimization.md +1133 -0
  371. package/expertise/performance/web/rendering-performance.md +1098 -0
  372. package/expertise/performance/web/ssr-and-hydration.md +918 -0
  373. package/expertise/performance/web/web-vitals.md +1374 -0
  374. package/expertise/quality/accessibility.md +985 -0
  375. package/expertise/quality/evidence-based-verification.md +499 -0
  376. package/expertise/quality/index.md +24 -0
  377. package/expertise/quality/ml-model-audit.md +614 -0
  378. package/expertise/quality/performance.md +600 -0
  379. package/expertise/quality/testing-api.md +891 -0
  380. package/expertise/quality/testing-mobile.md +496 -0
  381. package/expertise/quality/testing-web.md +849 -0
  382. package/expertise/security/PROGRESS.md +54 -0
  383. package/expertise/security/agentic-identity.md +540 -0
  384. package/expertise/security/compliance-frameworks.md +601 -0
  385. package/expertise/security/data/data-encryption.md +364 -0
  386. package/expertise/security/data/data-privacy-gdpr.md +692 -0
  387. package/expertise/security/data/database-security.md +1171 -0
  388. package/expertise/security/data/index.md +22 -0
  389. package/expertise/security/data/pii-handling.md +531 -0
  390. package/expertise/security/foundations/authentication.md +1041 -0
  391. package/expertise/security/foundations/authorization.md +603 -0
  392. package/expertise/security/foundations/cryptography.md +1001 -0
  393. package/expertise/security/foundations/index.md +25 -0
  394. package/expertise/security/foundations/owasp-top-10.md +1354 -0
  395. package/expertise/security/foundations/secrets-management.md +1217 -0
  396. package/expertise/security/foundations/secure-sdlc.md +700 -0
  397. package/expertise/security/foundations/supply-chain-security.md +698 -0
  398. package/expertise/security/index.md +31 -0
  399. package/expertise/security/infrastructure/cloud-security-aws.md +1296 -0
  400. package/expertise/security/infrastructure/cloud-security-gcp.md +1376 -0
  401. package/expertise/security/infrastructure/container-security.md +721 -0
  402. package/expertise/security/infrastructure/incident-response.md +1295 -0
  403. package/expertise/security/infrastructure/index.md +24 -0
  404. package/expertise/security/infrastructure/logging-and-monitoring.md +1618 -0
  405. package/expertise/security/infrastructure/network-security.md +1337 -0
  406. package/expertise/security/mobile/index.md +23 -0
  407. package/expertise/security/mobile/mobile-android-security.md +1218 -0
  408. package/expertise/security/mobile/mobile-binary-protection.md +1229 -0
  409. package/expertise/security/mobile/mobile-data-storage.md +1265 -0
  410. package/expertise/security/mobile/mobile-ios-security.md +1401 -0
  411. package/expertise/security/mobile/mobile-network-security.md +1520 -0
  412. package/expertise/security/smart-contract-security.md +594 -0
  413. package/expertise/security/testing/index.md +22 -0
  414. package/expertise/security/testing/penetration-testing.md +1258 -0
  415. package/expertise/security/testing/security-code-review.md +1765 -0
  416. package/expertise/security/testing/threat-modeling.md +1074 -0
  417. package/expertise/security/testing/vulnerability-scanning.md +1062 -0
  418. package/expertise/security/web/api-security.md +586 -0
  419. package/expertise/security/web/cors-and-headers.md +433 -0
  420. package/expertise/security/web/csrf.md +562 -0
  421. package/expertise/security/web/file-upload.md +1477 -0
  422. package/expertise/security/web/index.md +25 -0
  423. package/expertise/security/web/injection.md +1375 -0
  424. package/expertise/security/web/session-management.md +1101 -0
  425. package/expertise/security/web/xss.md +1158 -0
  426. package/exports/README.md +17 -0
  427. package/exports/hosts/claude/.claude/agents/clarifier.md +42 -0
  428. package/exports/hosts/claude/.claude/agents/content-author.md +63 -0
  429. package/exports/hosts/claude/.claude/agents/designer.md +55 -0
  430. package/exports/hosts/claude/.claude/agents/executor.md +55 -0
  431. package/exports/hosts/claude/.claude/agents/learner.md +51 -0
  432. package/exports/hosts/claude/.claude/agents/planner.md +53 -0
  433. package/exports/hosts/claude/.claude/agents/researcher.md +43 -0
  434. package/exports/hosts/claude/.claude/agents/reviewer.md +54 -0
  435. package/exports/hosts/claude/.claude/agents/specifier.md +47 -0
  436. package/exports/hosts/claude/.claude/agents/verifier.md +71 -0
  437. package/exports/hosts/claude/.claude/commands/author.md +42 -0
  438. package/exports/hosts/claude/.claude/commands/clarify.md +38 -0
  439. package/exports/hosts/claude/.claude/commands/design-review.md +46 -0
  440. package/exports/hosts/claude/.claude/commands/design.md +44 -0
  441. package/exports/hosts/claude/.claude/commands/discover.md +37 -0
  442. package/exports/hosts/claude/.claude/commands/execute.md +48 -0
  443. package/exports/hosts/claude/.claude/commands/learn.md +38 -0
  444. package/exports/hosts/claude/.claude/commands/plan-review.md +42 -0
  445. package/exports/hosts/claude/.claude/commands/plan.md +39 -0
  446. package/exports/hosts/claude/.claude/commands/prepare-next.md +37 -0
  447. package/exports/hosts/claude/.claude/commands/review.md +40 -0
  448. package/exports/hosts/claude/.claude/commands/run-audit.md +41 -0
  449. package/exports/hosts/claude/.claude/commands/spec-challenge.md +41 -0
  450. package/exports/hosts/claude/.claude/commands/specify.md +38 -0
  451. package/exports/hosts/claude/.claude/commands/verify.md +37 -0
  452. package/exports/hosts/claude/.claude/settings.json +34 -0
  453. package/exports/hosts/claude/CLAUDE.md +19 -0
  454. package/exports/hosts/claude/export.manifest.json +38 -0
  455. package/exports/hosts/claude/host-package.json +67 -0
  456. package/exports/hosts/codex/AGENTS.md +19 -0
  457. package/exports/hosts/codex/export.manifest.json +38 -0
  458. package/exports/hosts/codex/host-package.json +41 -0
  459. package/exports/hosts/cursor/.cursor/hooks.json +16 -0
  460. package/exports/hosts/cursor/.cursor/rules/wazir-core.mdc +19 -0
  461. package/exports/hosts/cursor/export.manifest.json +38 -0
  462. package/exports/hosts/cursor/host-package.json +42 -0
  463. package/exports/hosts/gemini/GEMINI.md +19 -0
  464. package/exports/hosts/gemini/export.manifest.json +38 -0
  465. package/exports/hosts/gemini/host-package.json +41 -0
  466. package/hooks/README.md +18 -0
  467. package/hooks/definitions/loop_cap_guard.yaml +21 -0
  468. package/hooks/definitions/post_tool_capture.yaml +24 -0
  469. package/hooks/definitions/pre_compact_summary.yaml +19 -0
  470. package/hooks/definitions/pre_tool_capture_route.yaml +19 -0
  471. package/hooks/definitions/protected_path_write_guard.yaml +19 -0
  472. package/hooks/definitions/session_start.yaml +19 -0
  473. package/hooks/definitions/stop_handoff_harvest.yaml +20 -0
  474. package/hooks/loop-cap-guard +17 -0
  475. package/hooks/post-tool-lint +36 -0
  476. package/hooks/protected-path-write-guard +17 -0
  477. package/hooks/session-start +41 -0
  478. package/llms-full.txt +2355 -0
  479. package/llms.txt +43 -0
  480. package/package.json +79 -0
  481. package/roles/README.md +20 -0
  482. package/roles/clarifier.md +42 -0
  483. package/roles/content-author.md +63 -0
  484. package/roles/designer.md +55 -0
  485. package/roles/executor.md +55 -0
  486. package/roles/learner.md +51 -0
  487. package/roles/planner.md +53 -0
  488. package/roles/researcher.md +43 -0
  489. package/roles/reviewer.md +54 -0
  490. package/roles/specifier.md +47 -0
  491. package/roles/verifier.md +71 -0
  492. package/schemas/README.md +24 -0
  493. package/schemas/accepted-learning.schema.json +20 -0
  494. package/schemas/author-artifact.schema.json +156 -0
  495. package/schemas/clarification.schema.json +19 -0
  496. package/schemas/design-artifact.schema.json +80 -0
  497. package/schemas/docs-claim.schema.json +18 -0
  498. package/schemas/export-manifest.schema.json +20 -0
  499. package/schemas/hook.schema.json +67 -0
  500. package/schemas/host-export-package.schema.json +18 -0
  501. package/schemas/implementation-plan.schema.json +19 -0
  502. package/schemas/proposed-learning.schema.json +19 -0
  503. package/schemas/research.schema.json +18 -0
  504. package/schemas/review.schema.json +29 -0
  505. package/schemas/run-manifest.schema.json +18 -0
  506. package/schemas/spec-challenge.schema.json +18 -0
  507. package/schemas/spec.schema.json +20 -0
  508. package/schemas/usage.schema.json +102 -0
  509. package/schemas/verification-proof.schema.json +29 -0
  510. package/schemas/wazir-manifest.schema.json +173 -0
  511. package/skills/README.md +40 -0
  512. package/skills/brainstorming/SKILL.md +77 -0
  513. package/skills/debugging/SKILL.md +50 -0
  514. package/skills/design/SKILL.md +61 -0
  515. package/skills/dispatching-parallel-agents/SKILL.md +128 -0
  516. package/skills/executing-plans/SKILL.md +70 -0
  517. package/skills/finishing-a-development-branch/SKILL.md +169 -0
  518. package/skills/humanize/SKILL.md +123 -0
  519. package/skills/init-pipeline/SKILL.md +124 -0
  520. package/skills/prepare-next/SKILL.md +20 -0
  521. package/skills/receiving-code-review/SKILL.md +123 -0
  522. package/skills/requesting-code-review/SKILL.md +105 -0
  523. package/skills/requesting-code-review/code-reviewer.md +108 -0
  524. package/skills/run-audit/SKILL.md +197 -0
  525. package/skills/scan-project/SKILL.md +41 -0
  526. package/skills/self-audit/SKILL.md +153 -0
  527. package/skills/subagent-driven-development/SKILL.md +154 -0
  528. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
  529. package/skills/subagent-driven-development/implementer-prompt.md +102 -0
  530. package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
  531. package/skills/tdd/SKILL.md +23 -0
  532. package/skills/using-git-worktrees/SKILL.md +163 -0
  533. package/skills/using-skills/SKILL.md +95 -0
  534. package/skills/verification/SKILL.md +22 -0
  535. package/skills/wazir/SKILL.md +463 -0
  536. package/skills/writing-plans/SKILL.md +30 -0
  537. package/skills/writing-skills/SKILL.md +157 -0
  538. package/skills/writing-skills/anthropic-best-practices.md +122 -0
  539. package/skills/writing-skills/persuasion-principles.md +50 -0
  540. package/templates/README.md +20 -0
  541. package/templates/artifacts/README.md +10 -0
  542. package/templates/artifacts/accepted-learning.md +19 -0
  543. package/templates/artifacts/accepted-learning.template.json +12 -0
  544. package/templates/artifacts/author.md +74 -0
  545. package/templates/artifacts/author.template.json +19 -0
  546. package/templates/artifacts/clarification.md +21 -0
  547. package/templates/artifacts/clarification.template.json +12 -0
  548. package/templates/artifacts/execute-notes.md +19 -0
  549. package/templates/artifacts/implementation-plan.md +21 -0
  550. package/templates/artifacts/implementation-plan.template.json +11 -0
  551. package/templates/artifacts/learning-proposal.md +19 -0
  552. package/templates/artifacts/next-run-handoff.md +21 -0
  553. package/templates/artifacts/plan-review.md +19 -0
  554. package/templates/artifacts/proposed-learning.template.json +12 -0
  555. package/templates/artifacts/research.md +21 -0
  556. package/templates/artifacts/research.template.json +12 -0
  557. package/templates/artifacts/review-findings.md +19 -0
  558. package/templates/artifacts/review.template.json +11 -0
  559. package/templates/artifacts/run-manifest.template.json +8 -0
  560. package/templates/artifacts/spec-challenge.md +19 -0
  561. package/templates/artifacts/spec-challenge.template.json +11 -0
  562. package/templates/artifacts/spec.md +21 -0
  563. package/templates/artifacts/spec.template.json +12 -0
  564. package/templates/artifacts/verification-proof.md +19 -0
  565. package/templates/artifacts/verification-proof.template.json +11 -0
  566. package/templates/examples/accepted-learning.example.json +14 -0
  567. package/templates/examples/author.example.json +152 -0
  568. package/templates/examples/clarification.example.json +15 -0
  569. package/templates/examples/docs-claim.example.json +8 -0
  570. package/templates/examples/export-manifest.example.json +7 -0
  571. package/templates/examples/host-export-package.example.json +11 -0
  572. package/templates/examples/implementation-plan.example.json +17 -0
  573. package/templates/examples/proposed-learning.example.json +13 -0
  574. package/templates/examples/research.example.json +15 -0
  575. package/templates/examples/research.example.md +6 -0
  576. package/templates/examples/review.example.json +17 -0
  577. package/templates/examples/run-manifest.example.json +9 -0
  578. package/templates/examples/spec-challenge.example.json +14 -0
  579. package/templates/examples/spec.example.json +21 -0
  580. package/templates/examples/verification-proof.example.json +21 -0
  581. package/templates/examples/wazir-manifest.example.yaml +65 -0
  582. package/templates/task-definition-schema.md +99 -0
  583. package/tooling/README.md +20 -0
  584. package/tooling/src/adapters/context-mode.js +50 -0
  585. package/tooling/src/capture/command.js +376 -0
  586. package/tooling/src/capture/store.js +99 -0
  587. package/tooling/src/capture/usage.js +270 -0
  588. package/tooling/src/checks/branches.js +50 -0
  589. package/tooling/src/checks/brand-truth.js +110 -0
  590. package/tooling/src/checks/changelog.js +231 -0
  591. package/tooling/src/checks/command-registry.js +36 -0
  592. package/tooling/src/checks/commits.js +102 -0
  593. package/tooling/src/checks/docs-drift.js +103 -0
  594. package/tooling/src/checks/docs-truth.js +201 -0
  595. package/tooling/src/checks/runtime-surface.js +156 -0
  596. package/tooling/src/cli.js +116 -0
  597. package/tooling/src/command-options.js +56 -0
  598. package/tooling/src/commands/validate.js +320 -0
  599. package/tooling/src/doctor/command.js +91 -0
  600. package/tooling/src/export/command.js +77 -0
  601. package/tooling/src/export/compiler.js +498 -0
  602. package/tooling/src/guards/loop-cap-guard.js +52 -0
  603. package/tooling/src/guards/protected-path-write-guard.js +67 -0
  604. package/tooling/src/index/command.js +152 -0
  605. package/tooling/src/index/storage.js +1061 -0
  606. package/tooling/src/index/summarizers.js +261 -0
  607. package/tooling/src/loaders.js +18 -0
  608. package/tooling/src/project-root.js +22 -0
  609. package/tooling/src/recall/command.js +225 -0
  610. package/tooling/src/schema-validator.js +30 -0
  611. package/tooling/src/state-root.js +40 -0
  612. package/tooling/src/status/command.js +71 -0
  613. package/wazir.manifest.yaml +135 -0
  614. package/workflows/README.md +19 -0
  615. package/workflows/author.md +42 -0
  616. package/workflows/clarify.md +38 -0
  617. package/workflows/design-review.md +46 -0
  618. package/workflows/design.md +44 -0
  619. package/workflows/discover.md +37 -0
  620. package/workflows/execute.md +48 -0
  621. package/workflows/learn.md +38 -0
  622. package/workflows/plan-review.md +42 -0
  623. package/workflows/plan.md +39 -0
  624. package/workflows/prepare-next.md +37 -0
  625. package/workflows/review.md +40 -0
  626. package/workflows/run-audit.md +41 -0
  627. package/workflows/spec-challenge.md +41 -0
  628. package/workflows/specify.md +38 -0
  629. package/workflows/verify.md +37 -0
@@ -0,0 +1,670 @@
1
+ # Mobile Backend for Frontend (BFF) — Architecture Expertise Module
2
+
3
+ > The Backend for Frontend pattern creates a dedicated backend service per client type (mobile, web, third-party) that aggregates, transforms, and optimizes API calls for that specific client's needs. This eliminates over-fetching, reduces mobile network calls, and gives frontend teams ownership of their API layer.
4
+
5
+ > **Category:** Mobile Architecture
6
+ > **Complexity:** Moderate
7
+ > **Applies when:** Multiple client types (mobile, web, desktop) consuming the same backend services but needing different data shapes, aggregations, or response sizes
8
+
9
+ ---
10
+
11
+ ## What This Is (and What It Isn't)
12
+
13
+ ### The Core Idea
14
+
15
+ The Backend for Frontend (BFF) pattern places a dedicated server-side component between a specific frontend application and the downstream backend services (microservices, databases, third-party APIs). Each client type — mobile, web, smart TV, third-party partner — gets its own BFF. The BFF aggregates calls to multiple backend services, reshapes the response to exactly what that frontend needs, and handles client-specific concerns like authentication token formats, caching headers, and payload compression.
16
+
17
+ The term was coined by Phil Calcado at SoundCloud in 2015 and popularized by Sam Newman in his work on microservices patterns. The pattern emerged from a real engineering problem: SoundCloud's monolithic API was serving web clients, iOS, Android, and partner integrations through a single endpoint. Every change to satisfy one client's needs risked breaking another. The BFF pattern resolved this by giving each client type its own backend facade.
18
+
19
+ ### How It Works at a Structural Level
20
+
21
+ ```
22
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
23
+ │ iOS App │ │ Android App │ │ Web SPA │
24
+ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
25
+ │ │ │
26
+ ▼ ▼ ▼
27
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
28
+ │ Mobile BFF │ │ Mobile BFF │ │ Web BFF │
29
+ │ (shared) │ │ (shared) │ │ │
30
+ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
31
+ │ │ │
32
+ └────────┬────────┘─────────┬───────┘
33
+ │ │
34
+ ┌────────▼──────┐ ┌───────▼────────┐
35
+ │ User Service │ │ Product Service │ ...N services
36
+ └───────────────┘ └────────────────┘
37
+ ```
38
+
39
+ The mobile BFF receives a single request from the app, fans out to however many backend services are needed, assembles the response into the exact shape the mobile screen requires, and returns it. The mobile app makes one network call instead of five. The web BFF does the same thing but returns a richer payload suited to desktop rendering, perhaps including additional metadata that a mobile screen would never display.
40
+
41
+ ### What a BFF Is NOT
42
+
43
+ **Not an API Gateway.** An API gateway is a single entry point for all clients. It handles cross-cutting concerns — rate limiting, authentication verification, TLS termination, request routing — but it does not contain client-specific business logic or response shaping. A BFF contains client-specific aggregation logic and is owned by the frontend team, not the platform team. In practice, many architectures use both: the API gateway handles infrastructure concerns, and BFFs sit behind it handling client-specific orchestration.
44
+
45
+ **Not GraphQL (though GraphQL can implement a BFF).** GraphQL is a query language that lets clients request exactly the data they need. This solves over-fetching at the query level. A BFF solves it at the service level — aggregating multiple backend calls, handling error scenarios, implementing caching strategies, and performing server-side transformations. GraphQL can serve as the interface layer of a BFF, but a BFF without GraphQL (using REST) is perfectly valid, and GraphQL without a BFF (directly querying microservices) is a different architecture entirely.
46
+
47
+ **Not a proxy.** A proxy forwards requests unchanged. A BFF transforms, aggregates, and optimizes. If your "BFF" just passes requests through to a single backend service, you do not have a BFF — you have a proxy adding latency.
48
+
49
+ **Not a general-purpose backend.** The moment a BFF starts serving multiple unrelated client types, it stops being a BFF and becomes a general-purpose API. This is the most common way the pattern degrades.
50
+
51
+ ---
52
+
53
+ ## When to Use It
54
+
55
+ ### The Qualifying Conditions
56
+
57
+ Apply the BFF pattern when **two or more** of these conditions hold:
58
+
59
+ **Multiple client types with divergent needs.** You have a mobile app that needs compact payloads (100KB responses, not 2MB), a web app that needs rich data structures with embedded metadata, and perhaps a TV app that needs a completely different content hierarchy. A single API cannot serve all three well without becoming bloated with conditional logic, optional fields, and client-sniffing heuristics.
60
+
61
+ **Mobile network constraints demand payload optimization.** Mobile devices operate on unreliable networks with high latency and limited bandwidth. Every unnecessary field in an API response costs battery and time. A BFF strips responses to exactly what the mobile screen needs. Netflix's mobile BFF, for example, returns artwork URLs sized for mobile screens, not the full resolution variants that the TV app requires.
62
+
63
+ **Multiple backend services must be aggregated per screen.** A single mobile screen — say, a product detail page — needs data from the product service, the pricing service, the inventory service, the reviews service, and the recommendations service. Without a BFF, the mobile app makes five sequential or parallel HTTP calls over cellular, each with its own latency, error handling, and retry logic. With a BFF, one call to the server handles all five fan-outs over the fast datacenter network.
64
+
65
+ **Frontend teams need API autonomy.** When the mobile team must file tickets with the backend team for every API change, velocity drops. A BFF owned by the mobile team lets them shape their API contract independently. They add fields, remove fields, and adjust response structures without coordinating across team boundaries.
66
+
67
+ **Backend service contracts are unstable or evolving.** When downstream microservices are being refactored, versioned, or replaced, a BFF acts as an anti-corruption layer. The mobile app's contract with the BFF stays stable while the BFF adapts to changing backend contracts internally.
68
+
69
+ ### Real-World Contexts Where This Pays Off
70
+
71
+ **Netflix** completed a year-long project rearchitecting their Android backend from a centralized API model to a dedicated BFF. The Android team took ownership of their backend service, enabling them to iterate on the API independently. Their BFF uses the Falcor data model and query protocol, allowing the app to query a list of paths in each HTTP request and receive specially formatted JSON (jsonGraph) used for client-side caching and UI hydration. The BFF aggregates data from separate backend microservices — the artwork service, video metadata service, personalization service — into a single response shaped for the Android rendering pipeline. Each platform (Android, iOS, smart TV, web) has its own BFF with its own optimization profile.
72
+
73
+ **SoundCloud** pioneered the BFF pattern in 2013 when their monolithic API could no longer serve the divergent needs of their web player, iOS app, Android app, and partner integrations. They created one BFF per client type, allowing each team to optimize for its platform's constraints. The iOS and Android listener apps shared a single "mobile listener BFF" since their data needs were similar, while the web player and the creator tools each had their own BFFs. This approach let SoundCloud scale from one development team to multiple autonomous teams without API coordination bottlenecks.
74
+
75
+ **Spotify** uses BFFs to serve different data shapes across their web player, mobile apps, desktop client, and smart speaker integrations. The mobile BFF delivers compact payloads optimized for streaming metadata and offline sync, while the desktop BFF delivers richer payloads suitable for the full desktop experience. Each client type's BFF is tuned for its specific performance characteristics.
76
+
77
+ **Uber** employs BFFs to separate the rider app's backend from the driver app's backend. Each BFF handles ride requests, driver matching, and real-time tracking differently — the rider BFF focuses on estimated arrival and pricing, while the driver BFF focuses on navigation, earnings, and ride queue management. This separation allows each app's backend to evolve independently even though they share underlying microservices.
78
+
79
+ **IKEA** adopted a vertical-slice architecture with BFF characteristics when they replaced their monolithic IKEA Retail Web (IRW) system with a microfrontends architecture. Each product team owns a vertical slice including its own backend-for-frontend layer. The platform now serves 48 countries with 50+ product teams, handling billions of sessions annually. The BFF approach enables each team to optimize its slice independently without cross-team API coordination.
80
+
81
+ ---
82
+
83
+ ## When NOT to Use It
84
+
85
+ This section is intentionally long because the BFF pattern is frequently applied where it adds cost without proportional benefit.
86
+
87
+ ### Disqualifying Conditions
88
+
89
+ **Single client type.** If you only have one frontend — a web app, or a single mobile app — there is no "frontend divergence" to solve. A well-designed API serving one client does not benefit from an intermediary BFF layer. You are adding a network hop, a deployment unit, and operational complexity for zero architectural benefit. Wait until a second client type with genuinely different needs emerges.
90
+
91
+ **Simple backend with few services.** If your backend is a single service (monolith or modular monolith) that already returns well-shaped responses, a BFF is pure overhead. The aggregation benefit only materializes when there are multiple downstream services to fan out to. If every mobile screen maps to one backend endpoint, there is nothing to aggregate.
92
+
93
+ **API Gateway with transformation capabilities suffices.** Modern API gateways (Kong, AWS API Gateway, Apigee) support response transformation, field filtering, and request aggregation at the gateway level. If your "BFF logic" is limited to removing a few fields from responses and combining two endpoints, a gateway transformation policy achieves the same result without a separate service.
94
+
95
+ **Team does not own or cannot deploy the BFF.** The BFF pattern's organizational benefit depends on the frontend team owning the BFF. If the BFF is owned by a separate "API team" that the mobile team must file tickets with, you have simply moved the coordination bottleneck from the backend team to the BFF team. The organizational structure must match the architectural pattern.
96
+
97
+ **GraphQL already solves the data-shaping problem.** If your backend exposes a well-designed GraphQL API that lets clients request exactly the fields and relationships they need, and your clients do not need complex multi-service aggregation (because GraphQL resolvers handle it), then adding a BFF on top of GraphQL introduces redundant complexity. As Phil Calcado noted, if your organization uses GraphQL with frontend-specific resolvers, BFF services might not add value.
98
+
99
+ **Insufficient operational maturity.** Each BFF is a service that must be deployed, monitored, scaled, secured, and maintained. If your team struggles to operate the services they already have, adding more services makes things worse, not better. The BFF pattern is appropriate for organizations that have solved service deployment, monitoring, and incident response — not for those still building that capability.
100
+
101
+ ### Real-World Cautionary Examples
102
+
103
+ **SoundCloud's BFF proliferation.** SoundCloud themselves discovered the dark side of their pioneering pattern. Over time, business logic migrated into BFFs that should have stayed in backend services. Authorization logic diverged across BFFs. Shared data-fetching code was duplicated rather than centralized. SoundCloud eventually introduced Value-Added Services (domain-oriented services based on DDD principles) to pull business logic back out of BFFs and centralize it where it belonged. The BFFs were reduced to thin orchestration layers. This evolution took years and significant engineering effort.
104
+
105
+ **The "one BFF per screen" trap.** Some teams interpret BFF as "one backend endpoint per mobile screen." This leads to dozens of screen-specific endpoints that cannot be reused, share no logic, and become a maintenance nightmare. A BFF should serve a client type, not a screen. It should offer a coherent API surface that multiple screens within the same app can consume.
106
+
107
+ **The shared-library distributed monolith.** A team creates BFFs for web, iOS, and Android, but centralizes authentication, logging, caching, and core business logic into a shared library that all three BFFs depend on. The shared library becomes a coordination bottleneck — any change requires synchronized deployment across all BFFs. The BFFs are independently deployed in theory but coupled in practice. This is a distributed monolith wearing a BFF costume.
108
+
109
+ ---
110
+
111
+ ## How It Works
112
+
113
+ ### BFF Per Client Type
114
+
115
+ The fundamental structural decision is granularity: how many BFFs, and what does each one serve?
116
+
117
+ **One BFF per platform family** is the most common and generally safest approach. A "mobile BFF" serves both iOS and Android (since their data needs are usually identical), and a "web BFF" serves the browser client. This is SoundCloud's original model and Netflix's current model.
118
+
119
+ **One BFF per platform** is justified when iOS and Android have genuinely different data needs — different screen sizes producing different data requirements, platform-specific features like widgets or watch complications that need specialized endpoints, or significantly different release cadences that benefit from independent API evolution.
120
+
121
+ **One BFF per user experience** is the most granular model. SoundCloud's "listener BFF" and "creator BFF" separated by user role, not by platform. This makes sense when the same platform serves fundamentally different use cases with different data needs.
122
+
123
+ ### Aggregation of Backend Calls
124
+
125
+ The BFF's primary technical function is call aggregation. Here is the typical flow:
126
+
127
+ ```
128
+ Mobile App Mobile BFF Backend Services
129
+ │ │ │
130
+ │ GET /home-feed │ │
131
+ │─────────────────────────────▶│ │
132
+ │ │ GET /users/123/profile │
133
+ │ │─────────────────────────────▶│
134
+ │ │ GET /recommendations/123 │
135
+ │ │─────────────────────────────▶│
136
+ │ │ GET /notifications/count │
137
+ │ │─────────────────────────────▶│
138
+ │ │ │
139
+ │ │◀─── all 3 responses ────────│
140
+ │ │ │
141
+ │ │ [aggregate, transform, │
142
+ │ │ strip unnecessary fields, │
143
+ │ │ resize image URLs] │
144
+ │ │ │
145
+ │ ◀── single optimized ──────│ │
146
+ │ response (40KB) │ │
147
+ ```
148
+
149
+ The BFF decides which backend calls can be parallelized (user profile + recommendations + notification count) versus which must be sequential (if recommendations depend on user preferences loaded from the profile call). It handles partial failures gracefully — if the notification count service is down, it returns the rest of the data with a null notification count rather than failing the entire request.
150
+
151
+ ### Response Shaping
152
+
153
+ Response shaping is where the BFF delivers its most visible value for mobile clients:
154
+
155
+ **Field filtering.** The user service returns 47 fields including internal audit data, admin flags, and legacy compatibility fields. The mobile BFF returns 12 fields — the ones the mobile UI actually renders.
156
+
157
+ **Image URL transformation.** The product service returns a base image URL. The mobile BFF transforms it to include mobile-appropriate dimensions (`?w=320&h=240&format=webp`) while the web BFF requests full-resolution variants.
158
+
159
+ **Denormalization.** Backend services return normalized data with foreign key references. The BFF denormalizes — embedding the author's display name directly in each comment object instead of returning a separate author ID that would require another client-side lookup.
160
+
161
+ **Pagination tuning.** The mobile BFF returns 10 items per page (sized for a mobile screen). The web BFF returns 50 items per page (sized for a desktop viewport with virtual scrolling).
162
+
163
+ **Localization assembly.** The BFF assembles localized content from the i18n service and embeds it in responses so the mobile app does not need a separate localization lookup per string.
164
+
165
+ ### Authentication Proxying
166
+
167
+ The BFF acts as an authentication intermediary:
168
+
169
+ 1. The mobile app authenticates with the identity provider (OAuth2, OIDC) and receives a user-facing access token.
170
+ 2. The mobile app sends this token to the BFF on every request.
171
+ 3. The BFF validates the token, then uses a service-to-service credential (mTLS certificate, internal JWT, API key) to call downstream services.
172
+ 4. The mobile app never needs to know about internal service authentication schemes.
173
+
174
+ This simplifies the mobile app's auth logic and prevents internal service credentials from being exposed on the device. If a backend service migrates from API key auth to mTLS, only the BFF changes — the mobile app's authentication flow remains identical.
175
+
176
+ ### Caching Strategy
177
+
178
+ BFF-level caching is particularly valuable for mobile because it reduces payload size and network calls:
179
+
180
+ **Response-level caching.** The BFF caches assembled responses for a short TTL (30-60 seconds for feeds, 5-10 minutes for relatively static data like user profiles). Mobile clients hitting the BFF within the TTL window get instant responses without any downstream calls.
181
+
182
+ **Backend response caching.** The BFF caches individual backend service responses. If the user profile is needed by both the home feed endpoint and the settings endpoint, it is fetched once and reused.
183
+
184
+ **ETags and conditional requests.** The BFF generates ETags for assembled responses. Mobile apps send `If-None-Match` headers, and the BFF returns `304 Not Modified` with zero body when nothing has changed — saving bandwidth on metered connections.
185
+
186
+ **Cache invalidation via events.** The BFF subscribes to backend service events (via message queue or webhook) and invalidates specific cache entries when underlying data changes, rather than relying on TTL expiry alone.
187
+
188
+ ### Error Handling and Graceful Degradation
189
+
190
+ This is where a BFF provides disproportionate value for mobile clients:
191
+
192
+ **Partial response assembly.** When one of five backend services times out, the BFF returns the data it has with explicit null markers for the failed section, along with metadata indicating which sections are stale or missing. The mobile app renders what it can and shows a subtle "tap to retry" indicator for the missing section.
193
+
194
+ **Circuit breaking.** The BFF implements circuit breakers per downstream service. If the recommendations service has been failing for 30 seconds, the BFF stops calling it entirely (open circuit), returns cached recommendations or an empty section, and periodically probes the service to detect recovery.
195
+
196
+ **Timeout budgets.** The BFF allocates a total timeout budget per request (e.g., 2 seconds). If the mobile app sends a request and the BFF has called 3 of 5 backend services after 1.8 seconds, it cancels the remaining 2 calls and returns a partial response rather than exceeding the mobile app's patience threshold.
197
+
198
+ **Error translation.** Backend services return implementation-specific error codes and stack traces. The BFF translates these into mobile-friendly error payloads with user-facing messages, error categories (network, auth, validation, server), and retry guidance (retryable: true/false, retryAfterSeconds: 30).
199
+
200
+ ---
201
+
202
+ ## Trade-Offs Matrix
203
+
204
+ | Dimension | Without BFF | With BFF | Verdict |
205
+ |---|---|---|---|
206
+ | **Network calls per screen** | 3-10 calls from mobile over cellular | 1 call from mobile, fan-out in datacenter | BFF wins decisively on mobile |
207
+ | **Payload size** | Full backend responses with unused fields (200KB+) | Stripped to mobile-needed fields (40KB) | BFF wins, especially on metered connections |
208
+ | **Team autonomy** | Mobile team depends on backend API changes | Mobile team owns their API contract | BFF enables faster mobile iteration |
209
+ | **Operational complexity** | Fewer services to deploy and monitor | Additional service(s) to deploy, scale, monitor | BFF adds operational cost |
210
+ | **Latency (happy path)** | Direct client-to-service (1 hop) | Client-to-BFF-to-services (2+ hops) | BFF adds ~5-20ms but saves multiple round trips |
211
+ | **Error handling** | Mobile app handles partial failures across N calls | BFF aggregates errors, returns graceful fallbacks | BFF centralizes error logic server-side |
212
+ | **Code duplication risk** | N/A | Business logic may leak into multiple BFFs | BFF requires discipline to stay thin |
213
+ | **Caching** | Client-side only, limited by device storage | Server-side + client-side, shared across users | BFF enables more effective caching |
214
+ | **API versioning** | Backend must version for all clients simultaneously | Each BFF versions independently per client type | BFF simplifies versioning |
215
+ | **Testing surface** | Test mobile app against backend directly | Test mobile app against BFF + BFF against backends | BFF increases total test surface |
216
+ | **Deployment coupling** | Mobile release independent of backend | BFF changes may need coordinated deploy | BFF adds deployment coordination |
217
+ | **Security surface** | Mobile app holds service credentials | BFF holds service credentials, mobile holds user token only | BFF reduces credential exposure on device |
218
+
219
+ ---
220
+
221
+ ## Evolution Path
222
+
223
+ ### Stage 1: Direct Client-to-Service
224
+
225
+ The mobile app calls backend services directly. This works when there are 1-3 backend services, one client type, and a small team. No BFF is needed.
226
+
227
+ ### Stage 2: API Gateway with Lightweight Transformation
228
+
229
+ As the number of backend services grows to 5-10 and a second client type appears, an API gateway handles routing, auth, and simple response filtering. Gateway-level transformations (field removal, response merging) handle basic client-specific needs. This delays the need for a full BFF.
230
+
231
+ ### Stage 3: Dedicated BFF Per Client Family
232
+
233
+ When gateway transformations become complex, when different client types need fundamentally different response structures, or when the mobile team's velocity is blocked by API coordination, introduce dedicated BFFs. Start with two: mobile and web. The mobile team owns the mobile BFF. The web team owns the web BFF. Both sit behind the existing API gateway.
234
+
235
+ ### Stage 4: BFF with GraphQL Interface
236
+
237
+ As the number of mobile screens grows and data requirements become more varied, the BFF may expose a GraphQL interface instead of REST. This lets the mobile app request exactly the fields each screen needs without the BFF needing a dedicated endpoint per screen. The BFF's GraphQL resolvers still aggregate from backend REST/gRPC services. Apollo Federation or schema stitching may connect multiple BFFs into a unified graph.
238
+
239
+ ### Stage 5: Edge BFF / Server-Driven UI
240
+
241
+ At massive scale (Netflix, Spotify), the BFF evolves toward server-driven UI — the BFF returns not just data but layout instructions, component hierarchies, and rendering metadata. The mobile app becomes a thin rendering shell. This enables A/B testing, personalization, and feature rollout without app store releases. Netflix's Falcor-based BFF and their server-driven UI experiments exemplify this stage.
242
+
243
+ ### Stage 6: BFF Consolidation and Domain Gateways
244
+
245
+ After operating multiple BFFs for years, organizations often find that business logic has leaked into BFFs, duplicated across them. SoundCloud's evolution is instructive: they introduced Domain Gateways (Value-Added Services based on DDD) that recentralize business logic, reducing BFFs to thin client-specific orchestration layers. This is a maturity step, not a failure of the BFF pattern — it is the natural refactoring that occurs when teams recognize the boundary between "client-specific shaping" and "business logic."
246
+
247
+ ---
248
+
249
+ ## Failure Modes
250
+
251
+ ### 1. The Bloated BFF (Business Logic Migration)
252
+
253
+ **What happens:** Business rules gradually migrate from backend services into the BFF. Pricing calculations, eligibility checks, authorization logic — developers add them to the BFF because "it is faster than waiting for the backend team." Over months, the BFF becomes a second monolith containing critical business logic that should live in domain services.
254
+
255
+ **How to detect:** If modifying a business rule requires changing the BFF rather than a backend service, business logic has leaked. If the BFF has database connections, it has almost certainly absorbed business logic.
256
+
257
+ **How to prevent:** Enforce a rule: the BFF performs aggregation, transformation, and shaping. It never performs calculations, state mutations, or authorization decisions. Those belong in backend services. Code reviews should flag any business logic in BFF PRs.
258
+
259
+ ### 2. The Shared-Library Distributed Monolith
260
+
261
+ **What happens:** Multiple BFFs share a common library for authentication, logging, data access, and utility functions. The shared library grows to contain most of the actual logic. Updating the library requires coordinated deployment of all BFFs. A bug in the library takes down all client types simultaneously.
262
+
263
+ **How to detect:** If you cannot deploy one BFF without redeploying others, you have a distributed monolith. If a shared library change requires integration testing across all BFFs, coupling is too high.
264
+
265
+ **How to prevent:** Shared libraries should contain only truly cross-cutting, stable utilities (logging format, metrics emission). Domain logic, service clients, and data transformation should be duplicated across BFFs or extracted into backend services. Accept small duplication as the price of independence.
266
+
267
+ ### 3. Cascading Failures (Fan-Out Amplification)
268
+
269
+ **What happens:** A single mobile request triggers the BFF to call 8 backend services. One service responds slowly (30-second timeout instead of 200ms). The BFF thread/connection pool is blocked waiting. Under load, all BFF threads are consumed waiting for the slow service. The BFF becomes unresponsive for all requests, even those that do not need the slow service. The mobile app experiences a total outage.
270
+
271
+ **How to detect:** Monitor P99 latency per downstream service call from the BFF. If any single backend service can cause BFF-wide latency spikes, fan-out amplification is present.
272
+
273
+ **How to prevent:** Circuit breakers per downstream service. Timeout budgets per request. Bulkheading — isolating thread/connection pools per downstream service so one slow service cannot exhaust resources needed by others. Return partial responses when a non-critical service is slow.
274
+
275
+ ### 4. The "One BFF Per Screen" Fragmentation
276
+
277
+ **What happens:** Developers interpret BFF as "create an endpoint for each mobile screen." The mobile app has 40 screens, so the BFF has 40 endpoints with no shared logic, no consistent error handling, and no reusable data-fetching patterns. Adding a new screen requires a new BFF endpoint.
278
+
279
+ **How to detect:** If the number of BFF endpoints grows linearly with the number of mobile screens, and endpoints share no code, you have screen-level fragmentation.
280
+
281
+ **How to prevent:** Design BFF endpoints around resources and capabilities, not screens. A `/user/home-feed` endpoint can serve both the home screen and the "pull to refresh" action. A `/product/:id/details` endpoint can serve the product detail screen, the quick-view modal, and the comparison view. The mobile app composes screens from these resource-oriented endpoints.
282
+
283
+ ### 5. BFF as a Bottleneck for Unrelated Changes
284
+
285
+ **What happens:** The mobile BFF serves both the e-commerce flow and the social features of the app. A change to the social feed endpoint requires deploying the entire BFF, which includes the checkout flow. A bug in the social feed deployment breaks checkout. The blast radius of every BFF deployment is the entire mobile experience.
286
+
287
+ **How to detect:** If the BFF deployment failure rate increases with the number of features it serves, and failures in one feature area impact unrelated features, the BFF has become a bottleneck.
288
+
289
+ **How to prevent:** Consider splitting BFFs by domain when they grow beyond a certain complexity. A "commerce BFF" and a "social BFF" have independent deployment and failure domains. Alternatively, use feature flags and canary deployments to limit blast radius.
290
+
291
+ ### 6. Stale Cache Serving Incorrect Data
292
+
293
+ **What happens:** The BFF caches aggressively to reduce backend load. A user updates their profile, but the cached profile in the BFF still serves the old data for 5 minutes. The user sees stale data after making a change and assumes the update failed.
294
+
295
+ **How to detect:** User reports of "changes not appearing" after mutations. Discrepancies between what the user just submitted and what the app displays.
296
+
297
+ **How to prevent:** Cache-busting on writes — when the BFF processes a mutation (POST/PUT/DELETE), it invalidates related cache entries immediately. For user-specific data, use event-driven cache invalidation. For the requesting user specifically, bypass cache on reads that immediately follow writes (read-after-write consistency).
298
+
299
+ ---
300
+
301
+ ## Technology Landscape
302
+
303
+ ### Node.js / Express
304
+
305
+ The most common BFF runtime. JavaScript/TypeScript on both frontend and BFF means the mobile team (if using React Native) or the web team can write BFF code in their primary language. Express is minimal and well-understood. Downsides: single-threaded event loop means CPU-intensive transformations (large JSON reshaping, image URL generation) can block other requests. Mitigate with worker threads or offloading to a streaming JSON library.
306
+
307
+ ```javascript
308
+ // Express BFF — home feed aggregation
309
+ app.get('/api/mobile/home-feed', authenticate, async (req, res) => {
310
+ const userId = req.user.id;
311
+
312
+ const [profile, recommendations, notifications] = await Promise.allSettled([
313
+ userService.getProfile(userId),
314
+ recommendationService.getForUser(userId),
315
+ notificationService.getUnreadCount(userId),
316
+ ]);
317
+
318
+ res.json({
319
+ user: profile.status === 'fulfilled'
320
+ ? shapeForMobile(profile.value)
321
+ : null,
322
+ recommendations: recommendations.status === 'fulfilled'
323
+ ? recommendations.value.slice(0, 10).map(stripToMobileFields)
324
+ : [],
325
+ notificationCount: notifications.status === 'fulfilled'
326
+ ? notifications.value.count
327
+ : null,
328
+ _meta: {
329
+ partial: [profile, recommendations, notifications].some(
330
+ r => r.status === 'rejected'
331
+ ),
332
+ },
333
+ });
334
+ });
335
+ ```
336
+
337
+ ### NestJS
338
+
339
+ A structured TypeScript framework built on Express (or Fastify). NestJS provides dependency injection, modular architecture, and built-in support for microservice communication (gRPC, NATS, RabbitMQ). For teams that want more structure than raw Express — controller/service separation, interceptors for logging/caching, guards for authentication — NestJS is a strong BFF choice. The `nestjs-bff` open-source boilerplate provides a production-ready starting point with auth, logging, and MongoDB integration out of the box.
340
+
341
+ ### GraphQL as BFF Interface
342
+
343
+ Instead of REST endpoints, the BFF exposes a GraphQL schema. The mobile app sends GraphQL queries requesting exactly the fields each screen needs. The BFF's resolvers aggregate from backend services.
344
+
345
+ Advantages: eliminates the need for screen-specific endpoints. The mobile app can request different field sets for the same entity on different screens without BFF changes. Introspection provides self-documentation.
346
+
347
+ Disadvantages: adds query parsing and validation overhead. Complexity shifts from "too many endpoints" to "query optimization and N+1 prevention." Requires DataLoader patterns to batch backend calls. Caching is harder than REST (no HTTP caching by URL).
348
+
349
+ Apollo Server, Mercurius (Fastify-based), and AWS AppSync are common GraphQL BFF implementations. Apollo Federation allows composing multiple BFF schemas into a unified graph accessible through a single endpoint.
350
+
351
+ ```graphql
352
+ # GraphQL BFF schema — mobile-optimized
353
+ type Query {
354
+ homeFeed: HomeFeed!
355
+ product(id: ID!): Product
356
+ }
357
+
358
+ type HomeFeed {
359
+ user: UserSummary
360
+ recommendations: [ProductCard!]!
361
+ notificationCount: Int
362
+ }
363
+
364
+ # Mobile-specific type — only fields the mobile UI renders
365
+ type ProductCard {
366
+ id: ID!
367
+ title: String!
368
+ price: Money!
369
+ thumbnailUrl: String! # Pre-sized for mobile
370
+ rating: Float
371
+ }
372
+ ```
373
+
374
+ ### Edge Functions / Serverless BFF
375
+
376
+ Cloudflare Workers, AWS Lambda@Edge, Vercel Edge Functions, and Deno Deploy allow running BFF logic at the network edge — geographically close to the user. This reduces latency for mobile users by eliminating the round-trip to a centralized BFF server.
377
+
378
+ Trade-offs: cold start latency (Lambda can add 100-500ms on cold starts, though provisioned concurrency mitigates this), limited execution time, constrained runtime (no long-lived connections, limited memory), and vendor lock-in. Best suited for BFFs that perform lightweight aggregation with low computational overhead. Not appropriate for BFFs with complex orchestration, stateful circuit breakers, or high-throughput requirements.
379
+
380
+ ### Go / Rust for High-Throughput BFFs
381
+
382
+ When the BFF must handle extreme throughput (100K+ requests/second) or when the aggregation involves significant CPU work (large payload transformation, encryption, compression), Go or Rust BFFs outperform Node.js. Netflix uses Java/Kotlin for some of their BFFs due to JVM ecosystem maturity. Trade-off: the BFF is no longer in the frontend team's primary language, which can reduce the ownership benefit of the pattern.
383
+
384
+ ### Kotlin / Spring Boot (JVM)
385
+
386
+ For organizations with strong JVM expertise, Spring Cloud Gateway combined with Spring WebFlux provides a reactive, non-blocking BFF framework. Kotlin's coroutines make async aggregation readable. The JVM ecosystem provides mature circuit breakers (Resilience4j), distributed tracing (Micrometer + Zipkin), and service discovery (Eureka, Consul). This is common in enterprises with existing Spring infrastructure.
387
+
388
+ ---
389
+
390
+ ## Decision Tree
391
+
392
+ ```
393
+ START: Do you have multiple client types (mobile, web, TV, partner)?
394
+
395
+ ├─ NO ──▶ Do you need to aggregate many backend service calls?
396
+ │ │
397
+ │ ├─ NO ──▶ STOP. You do not need a BFF.
398
+ │ │ Use direct API calls or an API gateway.
399
+ │ │
400
+ │ └─ YES ─▶ Consider an API gateway with aggregation
401
+ │ or a thin orchestration layer. A full BFF
402
+ │ is likely overkill for a single client.
403
+
404
+ └─ YES ─▶ Do different clients need significantly different
405
+ data shapes, payload sizes, or response structures?
406
+
407
+ ├─ NO ──▶ Does GraphQL solve your data-shaping needs?
408
+ │ │
409
+ │ ├─ YES ──▶ Use GraphQL without BFF.
410
+ │ │ Clients query what they need.
411
+ │ │
412
+ │ └─ NO ───▶ Consider API gateway with
413
+ │ per-client transformation rules.
414
+
415
+ └─ YES ─▶ Can your team operate additional services?
416
+ (deploy, monitor, on-call, scale)
417
+
418
+ ├─ NO ──▶ Build operational maturity first.
419
+ │ A BFF you cannot operate is worse
420
+ │ than no BFF.
421
+
422
+ └─ YES ─▶ Does the frontend team have
423
+ backend development skills?
424
+
425
+ ├─ NO ──▶ Invest in team skills
426
+ │ or pair with backend
427
+ │ engineers. BFF ownership
428
+ │ by the frontend team is
429
+ │ critical to the pattern.
430
+
431
+ └─ YES ─▶ IMPLEMENT BFF.
432
+ Start with one BFF per
433
+ client family (mobile, web).
434
+ Keep BFFs thin — aggregation
435
+ and shaping only, no
436
+ business logic.
437
+ ```
438
+
439
+ ---
440
+
441
+ ## Implementation Sketch
442
+
443
+ ### Project Structure (Node.js/TypeScript BFF)
444
+
445
+ ```
446
+ mobile-bff/
447
+ ├── src/
448
+ │ ├── controllers/ # Route handlers per feature area
449
+ │ │ ├── home-feed.ts
450
+ │ │ ├── product.ts
451
+ │ │ ├── user.ts
452
+ │ │ └── search.ts
453
+ │ ├── services/ # Backend service clients
454
+ │ │ ├── user-service.ts
455
+ │ │ ├── product-service.ts
456
+ │ │ ├── recommendation-service.ts
457
+ │ │ └── notification-service.ts
458
+ │ ├── transformers/ # Response shaping per entity
459
+ │ │ ├── user-transformer.ts
460
+ │ │ ├── product-transformer.ts
461
+ │ │ └── image-transformer.ts
462
+ │ ├── middleware/
463
+ │ │ ├── auth.ts # Token validation
464
+ │ │ ├── cache.ts # Response caching
465
+ │ │ ├── error-handler.ts # Centralized error translation
466
+ │ │ └── request-id.ts # Correlation ID propagation
467
+ │ ├── resilience/
468
+ │ │ ├── circuit-breaker.ts
469
+ │ │ ├── timeout.ts
470
+ │ │ └── retry.ts
471
+ │ └── app.ts
472
+ ├── test/
473
+ │ ├── controllers/ # BFF endpoint tests (mocked backends)
474
+ │ ├── transformers/ # Response shaping unit tests
475
+ │ └── integration/ # BFF + real/stubbed backends
476
+ ├── Dockerfile
477
+ ├── package.json
478
+ └── tsconfig.json
479
+ ```
480
+
481
+ ### Key Implementation Patterns
482
+
483
+ **Parallel aggregation with partial failure handling:**
484
+
485
+ ```typescript
486
+ // services/aggregator.ts
487
+ interface AggregationResult<T> {
488
+ data: T | null;
489
+ source: string;
490
+ status: 'ok' | 'timeout' | 'error' | 'circuit-open';
491
+ latencyMs: number;
492
+ }
493
+
494
+ async function aggregateWithResilience<T>(
495
+ calls: Array<{ name: string; fn: () => Promise<T> }>,
496
+ budgetMs: number = 2000
497
+ ): Promise<AggregationResult<T>[]> {
498
+ const deadline = Date.now() + budgetMs;
499
+
500
+ return Promise.all(
501
+ calls.map(async ({ name, fn }) => {
502
+ const start = Date.now();
503
+ const remaining = deadline - start;
504
+
505
+ if (remaining <= 0) {
506
+ return { data: null, source: name, status: 'timeout' as const, latencyMs: 0 };
507
+ }
508
+
509
+ try {
510
+ const data = await Promise.race([
511
+ fn(),
512
+ new Promise<never>((_, reject) =>
513
+ setTimeout(() => reject(new Error('budget-exceeded')), remaining)
514
+ ),
515
+ ]);
516
+ return { data, source: name, status: 'ok' as const, latencyMs: Date.now() - start };
517
+ } catch (err) {
518
+ return {
519
+ data: null,
520
+ source: name,
521
+ status: err.message === 'budget-exceeded' ? 'timeout' as const : 'error' as const,
522
+ latencyMs: Date.now() - start,
523
+ };
524
+ }
525
+ })
526
+ );
527
+ }
528
+ ```
529
+
530
+ **Response transformer (strip to mobile-needed fields):**
531
+
532
+ ```typescript
533
+ // transformers/product-transformer.ts
534
+ interface BackendProduct {
535
+ id: string;
536
+ title: string;
537
+ description: string;
538
+ longDescription: string;
539
+ internalSku: string;
540
+ warehouseLocation: string;
541
+ images: Array<{ url: string; width: number; height: number; format: string }>;
542
+ pricing: { base: number; discount: number; currency: string; taxRate: number };
543
+ metadata: Record<string, unknown>;
544
+ auditLog: Array<{ timestamp: string; action: string }>;
545
+ // ... 30+ more fields
546
+ }
547
+
548
+ interface MobileProduct {
549
+ id: string;
550
+ title: string;
551
+ description: string;
552
+ thumbnailUrl: string;
553
+ price: string;
554
+ originalPrice: string | null;
555
+ }
556
+
557
+ function toMobileProduct(backend: BackendProduct): MobileProduct {
558
+ const bestImage = backend.images.find(i => i.width >= 320) ?? backend.images[0];
559
+ const discountedPrice = backend.pricing.base - backend.pricing.discount;
560
+
561
+ return {
562
+ id: backend.id,
563
+ title: backend.title,
564
+ description: backend.description.slice(0, 200),
565
+ thumbnailUrl: `${bestImage.url}?w=320&h=240&format=webp`,
566
+ price: formatCurrency(discountedPrice, backend.pricing.currency),
567
+ originalPrice: backend.pricing.discount > 0
568
+ ? formatCurrency(backend.pricing.base, backend.pricing.currency)
569
+ : null,
570
+ };
571
+ }
572
+ ```
573
+
574
+ **Circuit breaker integration:**
575
+
576
+ ```typescript
577
+ // resilience/circuit-breaker.ts
578
+ import CircuitBreaker from 'opossum';
579
+
580
+ const defaultOptions = {
581
+ timeout: 3000, // Trip after 3s
582
+ errorThresholdPercentage: 50, // Trip after 50% failures
583
+ resetTimeout: 30000, // Try again after 30s
584
+ volumeThreshold: 10, // Minimum calls before tripping
585
+ };
586
+
587
+ // One circuit breaker per downstream service
588
+ const breakers = new Map<string, CircuitBreaker>();
589
+
590
+ function getBreaker(serviceName: string): CircuitBreaker {
591
+ if (!breakers.has(serviceName)) {
592
+ const breaker = new CircuitBreaker(
593
+ async (fn: () => Promise<unknown>) => fn(),
594
+ { ...defaultOptions, name: serviceName }
595
+ );
596
+
597
+ breaker.on('open', () => {
598
+ logger.warn(`Circuit OPEN for ${serviceName}`);
599
+ metrics.increment(`circuit_breaker.open`, { service: serviceName });
600
+ });
601
+
602
+ breaker.on('halfOpen', () => {
603
+ logger.info(`Circuit HALF-OPEN for ${serviceName}, probing...`);
604
+ });
605
+
606
+ breaker.on('close', () => {
607
+ logger.info(`Circuit CLOSED for ${serviceName}, recovered`);
608
+ });
609
+
610
+ breakers.set(serviceName, breaker);
611
+ }
612
+ return breakers.get(serviceName)!;
613
+ }
614
+
615
+ // Usage in service client
616
+ async function callWithBreaker<T>(
617
+ serviceName: string,
618
+ fn: () => Promise<T>
619
+ ): Promise<T> {
620
+ return getBreaker(serviceName).fire(fn) as Promise<T>;
621
+ }
622
+ ```
623
+
624
+ ---
625
+
626
+ ## Testing Strategy
627
+
628
+ ### Unit Tests: Transformers
629
+
630
+ Test that response shaping produces the correct mobile-optimized output. These tests are fast, have no network dependencies, and validate the core value proposition of the BFF — that backend responses are correctly transformed for mobile consumption.
631
+
632
+ ### Integration Tests: BFF Endpoints with Stubbed Backends
633
+
634
+ Use WireMock, MSW (Mock Service Worker), or Nock to stub backend services. Test the full BFF request lifecycle: authentication, aggregation, transformation, caching, and error handling. Verify that partial backend failures produce graceful degraded responses rather than 500 errors.
635
+
636
+ ### Contract Tests: BFF-to-Backend Contracts
637
+
638
+ Use Pact or similar consumer-driven contract testing. The BFF (consumer) defines the API contract it expects from each backend service (provider). Backend services validate that they satisfy the contract. This prevents backend changes from silently breaking the BFF without requiring full end-to-end tests.
639
+
640
+ ### Load Tests: Fan-Out Behavior Under Stress
641
+
642
+ BFFs amplify load — one mobile request becomes N backend requests. Load test the BFF with realistic concurrency to verify that circuit breakers trip correctly, connection pools do not exhaust, and response times degrade gracefully rather than catastrophically.
643
+
644
+ ---
645
+
646
+ ## Monitoring and Observability
647
+
648
+ A BFF must be instrumented more heavily than a typical service because it is the aggregation point — it sees the full picture of backend health from the mobile client's perspective.
649
+
650
+ **Key metrics to track:**
651
+
652
+ - **Aggregation latency breakdown:** Time spent in each downstream call, not just total response time. This reveals which backend service is the bottleneck.
653
+ - **Partial response rate:** Percentage of responses returned with one or more sections missing due to backend failure. A rising partial response rate is an early warning.
654
+ - **Cache hit ratio:** Per endpoint and per backend service. Low cache hit rates suggest cache TTLs are too short or cache keys are too specific.
655
+ - **Circuit breaker state transitions:** Track when circuits open, close, and half-open. Frequent state changes indicate an unstable downstream service.
656
+ - **Payload size distribution:** Track response sizes to detect payload bloat. If average mobile response size creeps from 40KB to 200KB, the BFF is accumulating unnecessary data.
657
+ - **Error budget per downstream service:** Track error rates per backend service as seen from the BFF. This is often more accurate than the service's own health metrics because it includes network issues between the BFF and the service.
658
+
659
+ **Distributed tracing** is non-negotiable. Every BFF request should generate a trace that fans out to show each downstream call, its latency, and its result. Tools: Jaeger, Zipkin, AWS X-Ray, Datadog APM. Without distributed tracing, debugging a slow BFF response requires correlating logs across N+1 services manually.
660
+
661
+ ---
662
+
663
+ ## Cross-References
664
+
665
+ - **[mobile-app-architecture](../mobile-architecture/):** BFF is one layer in the broader mobile architecture stack. Understanding mobile app architecture patterns (MVC, MVVM, Clean Architecture) clarifies what the BFF replaces on the client side (network layer aggregation, response mapping).
666
+ - **[api-design-rest](../integration/):** BFF endpoints should follow REST design principles for their external interface, even though they aggregate from non-REST backends internally.
667
+ - **[api-design-graphql](../integration/):** GraphQL can serve as the BFF's interface layer. Understanding GraphQL's strengths and weaknesses informs whether to use REST or GraphQL for the BFF's external API.
668
+ - **[microservices](../patterns/):** The BFF pattern exists because of microservices. Without multiple backend services to aggregate, there is no need for a BFF. Understanding microservice decomposition patterns clarifies what the BFF is aggregating.
669
+ - **[api-gateway](../integration/):** API Gateway and BFF are complementary, not competing patterns. Understanding where API Gateway responsibilities end and BFF responsibilities begin is critical to avoiding duplication.
670
+ - **[circuit-breaker](../patterns/):** Circuit breaking is a core resilience pattern within BFF implementations. The BFF is the most natural place to implement circuit breakers for mobile clients.