BFF Sample Structure
This is a complete sample structure for a graphql based Backend-For-Frontend.
Contents
- NPM Scripts
build
: generate a production ready bundle;clean
: clean autogenerated files from previous builds;start
: start the application using production bundle;start:dev
: start the application using development server;
- Typescript Config Tweaks
- Path Alias: Good defaults (based on project structure), jest configs linked to tsconfig and compile time transform (no need to runtime substituion approach);
- ts-patch for transform plugins;
- strict mode enabled (no
:any
hell, after all you're using typescript, do it right!)
- Resiliency Practices
- cockatiel policies for cache, timeout, retry, bulkhead and circuit breaker strategies;
- redis configuration;
- health check with lightship, with environment variables validation on startup;
- Telemetry
- request logger middleware;
- extensible logger configuration with Winston based on structured logging techniques (no more random log messages);
- GraphQL and APIs
- Complete apollo server configuration;
- Explicit express integration;
- Miscelaneous
- mock server for third party APIs;
- docker compose file with database and redis services;
- Dockerfile for development and production;
- Dependency Injection (powered by inversifyJS)
- C4 Model
.env
automatic load (powered by dotenv)- eslint and prettier configs
Setup
For all the following cases, you must have a valid .env
file.
Start production server
git clone git@github.com/jrmmendes:bff-structure
yarn
yarn build
yarn start
Start development server
yarn
yarn start:dev
Run unit tests
yarn test
Start dockerized application
docker-compose up bff redis <other services of interest>