BFF ServiceData View
BFF Service

DataView (BFF Service Ontology)

Definition of the DataView ontology element in the BFF Service, including stored and dynamic views, aggregates, and statistical projections.

MPO Version: 1.3.0

A DataView defines an aggregated projection of data for the BFF service in Mindbricks. It serves as a unified structure that collects and combines information from multiple microservices. DataViews can be configured as either stored or dynamic. Stored DataViews persist their results in Elasticsearch and are optimal for queries requiring filtering, sorting, or cross-service joins. Dynamic DataViews are assembled at runtime during the request cycle and are suitable for lightweight, user-specific, or real-time scenarios. Both types aim to simplify frontend development by consolidating distributed data into a single, queryable view.

interface DataView = {
  viewBasics : ViewBasics;
  aggregates : ViewAggregate[];
  stats : ViewStat[];
}
FieldDescription
viewBasicsBasic metadata and configuration for the DataView, including its name, storage strategy, source object, and selected properties. This section determines the fundamental structure and behavior of the view.
aggregatesA list of aggregate definitions that perform data joins from related objects, similar to SQL joins. These are used to enrich the DataView with related datasets, such as joining orders into a customer view.
statsA list of statistical calculations performed within the view to enrich it with precomputed analytics.

ViewBasics

MPO Version: 1.3.0

Configuration for a DataView's identity and structure. It specifies whether the view is stored (in Elasticsearch) or dynamic (evaluated at runtime), the name of the view, the main source object it is built upon, and the list of core properties to retrieve from the main object.

interface ViewBasics = {
  name : String;
  isStored : Boolean;
  mainObject : DataObjectName;
  properties : PropRefer[];
}
FieldDescription
nameA unique name for the DataView. Avoid using a name that matches any existing data object to prevent conflicts. Prefer descriptive names like 'UserDetailsView' that clearly indicate the view's purpose.
isStoredA boolean value that indicates whether the view is persisted in Elasticsearch. Set this to true for performance-optimized, filterable views. Set to false for dynamic, real-time data aggregations executed per request.
mainObjectThe primary data object or existing view that the DataView is structured around. This object serves as the root of the aggregation.
propertiesAn array of property names from the main object that should be included in the view's result.

ViewAggregate

MPO Version: 1.3.0

Defines an aggregate (join) within a DataView that links related objects to the main object, similar to SQL-style joins. Aggregates are resolved at the Elasticsearch layer using replicated microservice data. Each aggregate pulls in one or more records from a child object based on matching keys and optional conditions, then embeds them under the specified property name in the final view output.

interface ViewAggregate = {
  name : String;
  childObject : DataObjectName;
  parentKey : PropRefer;
  childKey : PropRefer;
  oneToMany : Boolean;
  condition : MScript;
  properties : PropRefer[];
  checkIn : MScript;
}
FieldDescription
nameThe property name under which the joined data will be added in the DataView. This is typically a descriptive alias for the child object, like 'userRoles' or 'companyInfo'.
childObjectThe name of the data object being joined (child object). This is the source of the aggregated data.
parentKeyThe key field from the main object used to perform the join. Often this is a foreign key like 'companyId' or 'userId'.
childKeyThe key field from the child object that is matched against the parent key. Typically this would be the child's primary identifier or a linking field.
oneToManySpecifies whether the relationship is one-to-many (true) or one-to-one (false). If true, the result will be an array of records from the child object.
conditionAn MScript condition evaluated on the main object to decide whether this aggregation should be executed.
propertiesThe list of property names to extract from the child object. Only these fields will be included in the aggregated result.
checkInAn MScript condition evaluated on each child record to determine whether it should be included in the final aggregation result.

ViewStat

MPO Version: 1.3.0

Defines a statistical aggregation for a DataView. Unlike ViewAggregates that collect related records, ViewStats compute mathematical summaries such as sum, count, average, min, and max over grouped data. These groupings, or 'buckets', are constructed based on parent-child relationships between objects. This is conceptually similar to Elasticsearch's bucket-based aggregations. Each ViewStat joins the main object with a target object (child) using a foreign key relationship and computes one or more aggregates using the defined conditions. It's ideal for summarizing numerical data across associations, such as counting user orders or summing revenue per company.

interface ViewStat = {
  name : String;
  childObject : DataObjectName;
  parentKey : PropRefer;
  childKey : PropRefer;
  select : MScript;
  aggList : AggregateItem[];
}
FieldDescription
nameThe name of the statistic in the DataView result. This will appear as a property in the view (e.g., 'totalRevenue', 'userOrderCount').
childObjectThe name of the target object to aggregate data from (e.g., orders, sessions, transactions). Can also be a previously defined view.
parentKeyThe key from the main object that groups the stat results. Acts as the bucket owner (e.g., userId if calculating per user).
childKeyThe foreign key in the target object used to relate it back to the main object. Typically a reference like 'userId' or 'companyId'.
selectAn optional MScript filter applied before bucketing. Use this to narrow the child data (e.g., only 'canceled' orders in the last month).
aggListThe list of AggregateItems to apply on the grouped buckets. Each defines a numeric operation like sum, count, average. If empty, a default count is applied.

AggregateItem

MPO Version: 1.3.0

Defines a single mathematical operation to apply to a group of records within a ViewStat. Supports standard operations like sum, average, min, max, and count. Each AggregateItem targets a specific field in the child object and may apply additional filters. It is particularly useful when multiple grouped metrics are required from the same set of joined records, such as 'count of failed orders' vs. 'sum of successful order values'.

interface AggregateItem = {
  name : String;
  aggType : AggTypes;
  aggField : PropRefer;
  dataType : DataTypes;
  filterValue : MScript;
}
FieldDescription
nameThe identifier of the computed metric (e.g., 'orderCount', 'totalAmount'). Appears as a key in the result object.
aggTypeThe aggregation operation to perform.
aggFieldThe field of the target object used in the aggregation (e.g., 'amount', 'id'). For count operations, typically use 'id'.
dataTypeThe expected data type of the result (e.g., 'Integer', 'Float'). Often reflects the type of the aggField but may differ (e.g., averaging integers produces floats).
filterValueOptional MScript condition to filter records inside the bucket before applying the operation. Allows multiple filtered aggregations on the same group (e.g., 'totalCanceledAmount', 'totalCompletedAmount').

AggTypes

Specifies the type of aggregation to perform.

const AggTypes = {
  value_count: "value_count",
  sum: "sum",
  avg: "avg",
  min: "min",
  max: "max",
};
EnumDescription
value_countCount the number of records.
sumSum the values of the records.
avgAverage the values of the records.
minFind the minimum value of the records.
maxFind the maximum value of the records.
Was this page helpful?
Built with Documentation.AI

Last updated today