U
UTMStack
Frontend Architecture

This document outlines the core frontend architecture of the application, focusing on the root Angular module configuration, the application initialization lifecycle, and the visualization factory pattern used for rendering charts.

[Unknown component: div]

Core Module Configuration

The AppModule serves as the root module of the application, bootstrapping the core components and registering global providers, interceptors, and third-party libraries.

Global UI Configuration

The module constructor enforces several global UI behaviors for NgBootstrap components to ensure consistent user experience across the application:

export class AppModule {
  constructor(private dpConfig: NgbDatepickerConfig, private config: NgbModalConfig, private tooltipConfig: NgbTooltipConfig) {
    // Restrict datepicker to 100 years in the past
    this.dpConfig.minDate = {year: moment().year() - 100, month: 1, day: 1};
    // Prevent modals from closing when clicking outside
    config.backdrop = 'static';
    // Append tooltips to the body to prevent z-index and overflow clipping issues
    this.tooltipConfig.container = 'body';
  }
}

Appending tooltips to the body is crucial in complex layouts (like dashboards with overflow properties) to prevent the tooltip from being clipped by its parent container.

Application Initialization Flow

Before the Angular application fully renders, it must verify API connectivity and load essential configuration data. This is handled via Angular's APP_INITIALIZER token, which executes the initTimezoneFormat factory function.

Initialization Sequence

The initializer subscribes to apiChecker.isOnlineApi$ and uses the first(val => val === true) operator. The application will pause bootstrapping until a successful connection to the backend API is established.

Once the API is reachable, timezoneService.loadTimezoneAndFormat() fetches the user's or system's timezone settings to ensure all dates and charts render correctly.

Finally, appVersionService.loadVersionInfo() retrieves the current backend version to ensure frontend-backend compatibility before resolving the initialization Promise.

If the API remains unreachable, the APP_INITIALIZER promise will not resolve, and the application will not load. Ensure fallback UI or error handling is managed at the ApiServiceCheckerService level.

HTTP Request Lifecycle

The application relies on a robust chain of HTTP interceptors to handle authentication, error management, and request state globally.

Chart Factory Implementation

To handle the diverse visualization requirements of the dashboard, the application implements a Factory Design Pattern for chart generation. This abstracts the complexity of ECharts configuration away from the components.

Architecture

The ChartFactory Class

The ChartFactory implements the Factory interface and routes incoming data to the appropriate chart builder class based on the ChartTypeEnum.

import {ChartTypeEnum} from '../../../enums/chart-type.enum';
import {VisualizationType} from '../../types/visualization.type';
import {ChartOption} from './chart-option';
import {Gauge, Heatmap, LineBar, Pie, ScatterMap, TagCloud} from './charts/*';
import {Factory} from './factory';

export class ChartFactory implements Factory {
  createChart(type?: string, data?: any[], visualization?: VisualizationType, toExport?: boolean): ChartOption {
    switch (type) {
      case ChartTypeEnum.PIE_CHART:
        return new Pie().buildChart(data, visualization, toExport);
      case ChartTypeEnum.GAUGE_CHART:
        return new Gauge().buildChart(data, visualization);
      case ChartTypeEnum.TAG_CLOUD_CHART:
        return new TagCloud().buildChart(data, visualization);
      case ChartTypeEnum.LINE_CHART:
      case ChartTypeEnum.AREA_LINE_CHART:
      case ChartTypeEnum.BAR_CHART:
      case ChartTypeEnum.BAR_HORIZONTAL_CHART:
        // LineBar handles multiple Cartesian coordinate charts
        return new LineBar().buildChart(data, visualization, toExport);
      case ChartTypeEnum.MARKER_CHART:
        return new ScatterMap().buildChart(data, visualization);
      case ChartTypeEnum.HEATMAP_CHART:
        return new Heatmap().buildChart(data, visualization);
    }
  }
}

The LineBar class is highly versatile and handles standard line charts, area charts, vertical bar charts, and horizontal bar charts by dynamically adjusting the ECharts X/Y axis configurations.

The toExport boolean flag alters the generated ChartOption for rendering in headless environments or PDF exports. When set to true, the factory typically disables animations, tooltips, and interactive elements to ensure the chart renders statically and predictably for capture.

ECharts configuration objects (ChartOption) can be massive and complex. By using a Factory pattern, we decouple the Angular components from the ECharts API. Components simply pass raw data and a VisualizationType configuration, and the factory handles the heavy lifting of mapping that data to the specific ECharts series and axis formats.

UTMStack
UTMStack © 2026 All rights reserved