backend-for-frontend is a architecture project structured to implement the Backend-for-Frontend (BFF) pattern. This architecture is designed to support separate backends for different frontend clients (web, mobile, etc.), ensuring tailored responses and performance optimization.
This monorepo manages:
- Web frontend (
frontend/web) - Mobile frontend (
frontend/mobileApp) - Web BFF (
backend/web-bff) - Mobile BFF (
backend/mobile-bff) - Shared services (
backend/shared)
The project leverages Makefile for build and dependency management and utilizes yarn workspaces for dependency handling.
- BFF Architecture: Separate backend layers for Web and Mobile clients.
- Frontend Clients: React.js for web and React Native for mobile.
- Shared Services: Common utilities shared between BFFs.
- Isolated Dependency Management: Each project manages its own dependencies via
yarnandMakefile. - Concurrent Development: Ability to run multiple services simultaneously using
concurrently. - Makefile Automation: Simplified commands for managing all services.
π¦ backend
β£ π _data
β β π db.json # JSON file for mock data
β£ π mobile-bff # BFF tailored for the mobile client
β£ π web-bff # BFF tailored for the web client
β£ π shared # Shared backend code (e.g., validation, error handling)
β π package.json # Backend dependencies
π¦ frontend
β£ π mobileApp # React Native application
β β£ π app
β β β£ π Components # UI components (following atomic design principles)
β β β£ π Screens # Login, RecipeList, RecipeDetail
β β β£ π Context # Global states (e.g., AuthContext)
β β β π Navigation # React Navigation setup
β£ π web # React (web) application
β β£ π Components # Atomic components
β β£ π Pages # Login, RecipeList, RecipeDetail
β β£ π Context # Web global states
β β π index.tsx # Entry point for the React application
β π package.json # Frontend dependencies
π¦ node_modules # Project dependencies
π Makefile # Automation scripts
π package.json # Root dependencies
π README.md # Project documentation
π yarn.lock # Dependency version locking
Make sure the following are installed:
- Node.js (>= 18.x)
- Yarn (1.22.x)
- Make (for running commands)
Project Clone:
git clone https://github.com/jsdeveloperr/backend-for-frontend-architecture.git
cd backend-for-frontend-architectureRun the following command to install dependencies for all projects:
yarn install:allThis executes:
make installwhich installs dependencies for each subproject (web, mobile, shared, etc.).
To clean all node_modules and reset the project:
yarn clean:allThis runs:
make cleanTo clean the yarn cache:
yarn cache:cleanyarn start:backendThis runs:
make start-backendsIt starts:
sharedweb-bffmobile-bff
yarn start:frontendThis runs:
make start-frontendsIt starts:
webmobile
React Native Debugging with Android
When running the mobile application on an Android device or emulator, API requests might fail due to localhost connectivity issues. To resolve this, you need to set up adb reverse commands.
Run the following commands:
adb reverse tcp:5000 tcp:5000 # Map Shared BFF API
adb reverse tcp:3001 tcp:3001 # Map Mobile BFF API| Service | Command |
|---|---|
| Web Frontend | yarn start:web |
| Mobile Frontend | yarn start:mobile |
| Web BFF Backend | yarn start:wbff |
| Mobile BFF Backend | yarn start:mbff |
| Shared Services | yarn start:shared |
| Command | Description |
|---|---|
yarn clean:all |
Cleans all node_modules and resets project |
yarn cache:clean |
Cleans the yarn cache |
For advanced users, all functionality is centralized in the Makefile. Below are the available commands:
| Command | Description |
|---|---|
make install |
Installs dependencies for all projects |
make clean |
Cleans all node_modules directories |
make cache-clean |
Cleans yarn cache |
make start-web |
Starts the web frontend |
make start-mobile |
Starts the mobile frontend |
make start-shared |
Starts the shared services |
make start-backend-web-bff |
Starts the Web BFF backend |
make start-backend-mobile-bff |
Starts the Mobile BFF backend |
make start-backends |
Starts all backend services |
make start-frontends |
Starts all frontend services |
-
concurrently not found- Run
yarn add concurrently -Din the root directory.
- Run
-
Missing
node_modules- Ensure
yarn install:allwas executed.
- Ensure
-
React Native Build Errors
- Ensure the correct setup for React Native by running:
npx react-native doctor
- Ensure the correct setup for React Native by running:
-
Port Conflicts
- Make sure no other process is using the default ports (e.g., 3000, 5000).
- Add Docker support for easier environment setup.
- Implement CI/CD pipelines.
- Enable remote caching for builds with TurboRepo.
We welcome contributions! Feel free to submit issues or pull requests to improve this project.
This project is licensed under the MIT License.
