Service Design Specification

BFF Service Documentation Version: 1.0.3


Scope

This document provides a comprehensive architectural overview of the BFF Service, a Backend-for-Frontend layer designed to unify access to backend ElasticSearch indices and event-driven aggregation logic. The service offers a full REST API suite and listens to Kafka topics to synchronize enriched views.

This document is intended for:

For endpoint-level specifications, refer to the REST API Guide. For listener-level behavior, refer to the Event API Guide.


Service Settings


API Routes Overview

The BFF service exposes a dynamic REST API interface that provides full access to ElasticSearch indices. These include list, count, filter, and schema-based interactions for both stored and virtual views.

For full documentation of REST routes, including supported methods and examples, refer to the REST API Guide.


Kafka Event Listeners

The BFF service listens to ElasticSearch-related Kafka topics to maintain enriched and denormalized indices. These listeners trigger view aggregation functions upon receiving create, update, or delete events for primary and related entities.

For detailed behavior, payloads, and listener-to-function mappings, refer to the Event Guide.


Aggregation Strategy

Each view is either:

For each stored view:

Final document is saved to: <project_codename>_<view.newIndexName>


Middleware

Error Handling

Request Validation

Async Wrapper


Elasticsearch Utilities


Cron Repair Logic

Runs periodically to ensure data integrity:


Environment Variables

Variable Description
HTTP_PORT Service port
KAFKA_BROKER Kafka broker host
ELASTIC_URL Elasticsearch base URL
CORS_ORIGIN Allowed frontend origin (optional)
NODE_ENV Environment (dev, prod)
SERVICE_URL Used for injected API face config
SERVICE_SHORT_NAME Used in injected auth URL

App Lifecycle

  1. Loads env: .env, .prod.env, etc.

  2. Bootstraps Express app with:

    • CORS setup
    • JSON + cookie parsers
    • Dynamic routes
    • Swagger and API Face
  3. Starts:

    • Kafka listeners
    • Cron repair jobs
    • Full enrichment pipelines
  4. Handles SIGINT to close server cleanly


Testing Strategy

Unit Tests

Integration Tests

Load Tests (Optional)