# energinet-datahub/greenforce-frontend architecture

> Architecture diagram of the GitHub repository energinet-datahub/greenforce-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/energinet-datahub/greenforce-frontend
- Repository: https://github.com/energinet-datahub/greenforce-frontend

## Overview

#### Purpose and deployable entry points
GreenForce is an Nx monorepo for the DataHub electricity-market frontend, its dedicated backend-for-frontend (BFF), shared domain libraries, and the Watt design system. The main runtime entry points are:
- Angular SPA: `apps/dh/app-dh/src/main.ts`, rooted by `apps/dh/app-dh/src/app/datahub-app.component.ts`.
- ASP.NET Core BFF: `apps/dh/api-dh/source/DataHub.WebApi/Program.cs`, built from `apps/dh/api-dh/DataHub.WebApi.sln`.
- Browser E2E application: `apps/dh/e2e-dh/playwright.config.ts`.

#### Frontend composition and routing
`app-dh` is intentionally thin; feature libraries hold business UI. Core shell routing and navigation compose domain shells and lazy feature routes:
- `libs/dh/core/shell/src/dh-core-shell.routes.ts`
- `libs/dh/metering-point/feature-process-overview/src/routes.ts`
- `libs/dh/wholesale/shell/src/dh-wholesale-shell.routes.ts`

Primary business surfaces include metering points/processes, market participants/administration, charges, wholesale calculations, reports, eSett exchange, conversations, notifications, and operational tooling.

#### Client data boundary
Frontend features use GraphQL documents and a shared Apollo-based access layer rather than calling subsystem APIs directly. The shared layer configures HTTP, SSE subscriptions, retries, scalar conversion, errors, and cache:
- `libs/dh/shared/data-access-graphql/src/dh-apollo.ts`
- `libs/dh/shared/data-access-graphql/src/dh-http-link.ts`
- `libs/dh/shared/data-access-graphql/src/dh-sse-link.ts`

Flow: Angular route/component → generated/typed GraphQL operation → Apollo links with authorization/error handling → DataHub BFF GraphQL endpoint. Subscriptions support live changes such as calculation and metering-point process updates.

#### Identity, authorization, and runtime configuration
The SPA loads API, app, and B2C settings at startup and uses MSAL/B2C plus an actor-scoped authorization model. It applies access tokens, selected-actor context, permissions, market-role guards, inactivity behavior, feature flags, and release toggles.
- `libs/dh/shared/environments/src/dh-environment.ts`
- `libs/dh/auth/feature-msal/src/dh-b2c-config.ts`
- `libs/dh/shared/feature-authorization/src/dh-authorization.interceptor.ts`
- `libs/dh/shared/feature-authorization/src/permission.guard.ts`

Environment JSON assets permit local, Docker, or overridden remote endpoints under `libs/dh/shared/assets/src/assets/configuration`.

#### BFF API and module boundary
The .NET 10 BFF presents GraphQL as its primary aggregation surface, with REST controllers retained for selected proxy/download/token endpoints. Registration and module discovery are centralized here:
- `apps/dh/api-dh/source/DataHub.WebApi/Registration/GraphQLRegistrationExtensions.cs`
- `apps/dh/api-dh/source/DataHub.WebApi/Registration/ModuleExtensions.cs`
- `apps/dh/api-dh/source/DataHub.WebApi/Controllers/TokenController.cs`

GraphQL modules map client-facing nodes, queries, mutations, types, authorization, and batching onto downstream data. Representative high-value modules:
- Electricity market/metering and measurements: `apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/ElectricityMarketModule.cs`
- Market participants, actors, users, permissions: `apps/dh/api-dh/source/DataHub.WebApi/Modules/MarketParticipant/MarketParticipantModule.cs`
- Charges and charge links: `apps/dh/api-dh/source/DataHub.WebApi/Modules/Charges/ChargesModule.cs`
- Orchestrated market processes and calculations: `apps/dh/api-dh/source/DataHub.WebApi/Modules/Processes/ProcessesModule.cs`
- Reports and settlements: `apps/dh/api-dh/source/DataHub.WebApi/Modules/SettlementReports/SettlementReportsModule.cs`

#### Downstream integration and cross-cutting behavior
The BFF is an adapter/aggregator over DataHub subsystems through typed HTTP clients, including Electricity Market, Market Participant, eSett Exchange, imbalance prices, actor conversations, notifications, and legacy DH2 bridging:
- `apps/dh/api-dh/source/DataHub.WebApi/Clients/ElectricityMarket/V1/ElectricityMarketClient.cs`
- `apps/dh/api-dh/source/DataHub.WebApi/Clients/MarketParticipant/V1/MarketParticipantClient.cs`
- `apps/dh/api-dh/source/DataHub.WebApi/Clients/ESettExchange/V1/ESettExchangeClient.cs`

It forwards authenticated calls via `apps/dh/api-dh/source/DataHub.WebApi/AuthorizedHttpClientFactory.cs`, exposes health checks, and applies revision/audit logging through `apps/dh/api-dh/source/DataHub.WebApi/Modules/RevisionLog/Middleware/RevisionLogMiddleware.cs`. Docker assets exist for both SPA (Nginx) and BFF: `apps/dh/app-dh/Dockerfile`, `apps/dh/api-dh/Dockerfile`.

#### Shared platform
Watt is the reusable Angular design-system package consumed by features (`libs/watt/package`). Frontend observability integrates Application Insights and Microsoft Clarity:
- `libs/dh/shared/util-application-insights/src/dh-application-insights.initializer.ts`
- `libs/dh/shared/feature-microsoft-clarity/src/dh-microsoft-clarity.initializer.ts`

Main entry points: [`libs/dh/core/shell/src/dh-core-shell.routes.ts`](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/core/shell/src/dh-core-shell.routes.ts) (Core shell routes), [`apps/dh/api-dh/source/DataHub.WebApi/Program.cs`](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Program.cs) (BFF host), [`libs/dh/shared/data-access-graphql/src/dh-apollo.ts`](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/data-access-graphql/src/dh-apollo.ts) (Apollo data access), [`apps/dh/app-dh/src/app/datahub-app.component.ts`](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/app-dh/src/app/datahub-app.component.ts) (DataHub app root)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_spa["Angular SPA"]
  node_spa_bootstrap["SPA bootstrap<br/>Angular entry<br/>[main.ts]"]
  node_app_root["DataHub app root<br/>Angular root"]
  node_shell_routes["Core shell routes<br/>route composition"]
  node_process_routes["Process overview<br/>lazy feature routes<br/>[routes.ts]"]
  node_wholesale_routes["Wholesale shell<br/>domain shell routes"]
  node_e2e["Browser E2E<br/>Playwright suite"]
end

subgraph group_client["Client platform"]
  node_environment["Runtime environment<br/>startup configuration<br/>[dh-environment.ts]"]
  node_identity_auth["B2C and authorization<br/>MSAL auth layer"]
  node_apollo["Apollo data access<br/>GraphQL client<br/>[dh-apollo.ts]"]
  node_sse_link["SSE subscriptions<br/>Apollo link<br/>[dh-sse-link.ts]"]
  node_watt["Watt design system<br/>shared UI package"]
  node_observability["Client observability<br/>telemetry initializers"]
end

subgraph group_bff["DataHub BFF"]
  node_bff_program["BFF host<br/>ASP.NET Core entry<br/>[Program.cs]"]
  node_graphql_registration["GraphQL registration<br/>API composition"]
  node_graphql_modules["Domain GraphQL modules<br/>schema modules"]
  node_token_rest["Token REST endpoint<br/>REST controller<br/>[TokenController.cs]"]
  node_authorized_clients["Authorized HTTP clients<br/>downstream adapter"]
  node_revision_log["Revision audit log<br/>BFF middleware"]
end

node_downstream{{"DataHub subsystems<br/>external service APIs"}}

node_spa_bootstrap -->|"boots"| node_app_root
node_app_root -->|"loads"| node_shell_routes
node_shell_routes -.->|"lazy route"| node_process_routes
node_shell_routes -.->|"domain route"| node_wholesale_routes
node_shell_routes -->|"renders with"| node_watt
node_spa_bootstrap -->|"loads settings"| node_environment
node_environment -->|"configures"| node_identity_auth
node_shell_routes -->|"guards routes"| node_identity_auth
node_identity_auth -->|"adds auth context"| node_apollo
node_process_routes -->|"GraphQL operations"| node_apollo
node_wholesale_routes -->|"GraphQL operations"| node_apollo
node_apollo -.->|"subscriptions"| node_sse_link
node_apollo -->|"GraphQL HTTP"| node_bff_program
node_sse_link -->|"live updates"| node_bff_program
node_bff_program -->|"configures"| node_graphql_registration
node_graphql_registration -->|"registers"| node_graphql_modules
node_bff_program -->|"serves"| node_token_rest
node_graphql_modules -->|"queries downstream"| node_authorized_clients
node_token_rest -->|"proxies"| node_authorized_clients
node_authorized_clients -->|"typed HTTP"| node_downstream
node_bff_program -->|"audits revisions"| node_revision_log
node_app_root -.->|"initializes"| node_observability
node_e2e -.->|"exercises"| node_app_root

click node_spa_bootstrap "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/app-dh/src/main.ts"
click node_app_root "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/app-dh/src/app/datahub-app.component.ts"
click node_shell_routes "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/core/shell/src/dh-core-shell.routes.ts"
click node_process_routes "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/metering-point/feature-process-overview/src/routes.ts"
click node_wholesale_routes "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/wholesale/shell/src/dh-wholesale-shell.routes.ts"
click node_e2e "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/e2e-dh/playwright.config.ts"
click node_environment "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/environments/src/dh-environment.ts"
click node_identity_auth "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/feature-authorization/src/dh-authorization.interceptor.ts"
click node_apollo "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/data-access-graphql/src/dh-apollo.ts"
click node_sse_link "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/data-access-graphql/src/dh-sse-link.ts"
click node_watt "https://github.com/energinet-datahub/greenforce-frontend/tree/main/libs/watt/package"
click node_observability "https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/util-application-insights/src/dh-application-insights.initializer.ts"
click node_bff_program "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Program.cs"
click node_graphql_registration "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Registration/GraphQLRegistrationExtensions.cs"
click node_graphql_modules "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/ElectricityMarketModule.cs"
click node_token_rest "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Controllers/TokenController.cs"
click node_authorized_clients "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/AuthorizedHttpClientFactory.cs"
click node_downstream "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Clients/ElectricityMarket/V1/ElectricityMarketClient.cs"
click node_revision_log "https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Modules/RevisionLog/Middleware/RevisionLogMiddleware.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_spa_bootstrap,node_app_root,node_shell_routes,node_process_routes,node_wholesale_routes,node_e2e toneBlue
class node_environment,node_identity_auth,node_apollo,node_sse_link,node_watt,node_observability toneAmber
class node_bff_program,node_graphql_registration,node_graphql_modules,node_token_rest,node_authorized_clients,node_revision_log toneMint
class node_downstream toneNeutral
```

## Components

### Angular SPA

Thin app shell composed from lazy domain libraries.

- [SPA bootstrap](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/app-dh/src/main.ts): Angular entry · `apps/dh/app-dh/src/main.ts`
- [DataHub app root](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/app-dh/src/app/datahub-app.component.ts): Angular root · `apps/dh/app-dh/src/app/datahub-app.component.ts`
- [Core shell routes](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/core/shell/src/dh-core-shell.routes.ts): route composition · Composes navigation, domain shells, and lazy features. · `libs/dh/core/shell/src/dh-core-shell.routes.ts`
- [Process overview](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/metering-point/feature-process-overview/src/routes.ts): lazy feature routes · `libs/dh/metering-point/feature-process-overview/src/routes.ts`
- [Wholesale shell](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/wholesale/shell/src/dh-wholesale-shell.routes.ts): domain shell routes · `libs/dh/wholesale/shell/src/dh-wholesale-shell.routes.ts`
- [Browser E2E](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/e2e-dh/playwright.config.ts): Playwright suite · `apps/dh/e2e-dh/playwright.config.ts`

### Client platform

Shared identity, data access, and observability services.

- [Runtime environment](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/environments/src/dh-environment.ts): startup configuration · Loads API, app, and B2C settings. · `libs/dh/shared/environments/src/dh-environment.ts`
- [B2C and authorization](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/feature-authorization/src/dh-authorization.interceptor.ts): MSAL auth layer · Applies tokens, actor context, permissions, and route guards. · `libs/dh/shared/feature-authorization/src/dh-authorization.interceptor.ts`
- [Apollo data access](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/data-access-graphql/src/dh-apollo.ts): GraphQL client · Configures HTTP, SSE, retries, scalars, errors, and cache. · `libs/dh/shared/data-access-graphql/src/dh-apollo.ts`
- [SSE subscriptions](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/data-access-graphql/src/dh-sse-link.ts): Apollo link · Delivers live calculation and process changes. · `libs/dh/shared/data-access-graphql/src/dh-sse-link.ts`
- [Watt design system](https://github.com/energinet-datahub/greenforce-frontend/tree/main/libs/watt/package): shared UI package · `libs/watt/package`
- [Client observability](https://github.com/energinet-datahub/greenforce-frontend/blob/main/libs/dh/shared/util-application-insights/src/dh-application-insights.initializer.ts): telemetry initializers · Application Insights and Microsoft Clarity integration. · `libs/dh/shared/util-application-insights/src/dh-application-insights.initializer.ts`

### DataHub BFF

ASP.NET Core aggregation boundary for DataHub subsystems.

- [BFF host](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Program.cs): ASP.NET Core entry · GraphQL-first API with selected REST endpoints. · `apps/dh/api-dh/source/DataHub.WebApi/Program.cs`
- [GraphQL registration](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Registration/GraphQLRegistrationExtensions.cs): API composition · Registers schema, modules, and GraphQL services. · `apps/dh/api-dh/source/DataHub.WebApi/Registration/GraphQLRegistrationExtensions.cs`
- [Domain GraphQL modules](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/ElectricityMarketModule.cs): schema modules · Electricity market, participants, charges, processes, and reports. · `apps/dh/api-dh/source/DataHub.WebApi/Modules/ElectricityMarket/ElectricityMarketModule.cs`
- [Token REST endpoint](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Controllers/TokenController.cs): REST controller · Retained proxy, download, and token API surface. · `apps/dh/api-dh/source/DataHub.WebApi/Controllers/TokenController.cs`
- [Authorized HTTP clients](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/AuthorizedHttpClientFactory.cs): downstream adapter · Forwards authenticated typed requests to DataHub services. · `apps/dh/api-dh/source/DataHub.WebApi/AuthorizedHttpClientFactory.cs`
- [Revision audit log](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Modules/RevisionLog/Middleware/RevisionLogMiddleware.cs): BFF middleware · `apps/dh/api-dh/source/DataHub.WebApi/Modules/RevisionLog/Middleware/RevisionLogMiddleware.cs`

### Other components

- [DataHub subsystems](https://github.com/energinet-datahub/greenforce-frontend/blob/main/apps/dh/api-dh/source/DataHub.WebApi/Clients/ElectricityMarket/V1/ElectricityMarketClient.cs): external service APIs · Electricity Market, Market Participant, eSett, conversations, notifications, and DH2. · `apps/dh/api-dh/source/DataHub.WebApi/Clients/ElectricityMarket/V1/ElectricityMarketClient.cs`

## Connections

- SPA bootstrap → DataHub app root: boots
- DataHub app root → Core shell routes: loads
- Core shell routes → Process overview: lazy route
- Core shell routes → Wholesale shell: domain route
- Core shell routes → Watt design system: renders with
- SPA bootstrap → Runtime environment: loads settings
- Runtime environment → B2C and authorization: configures
- Core shell routes → B2C and authorization: guards routes
- B2C and authorization → Apollo data access: adds auth context
- Process overview → Apollo data access: GraphQL operations
- Wholesale shell → Apollo data access: GraphQL operations
- Apollo data access → SSE subscriptions: subscriptions
- Apollo data access → BFF host: GraphQL HTTP
- SSE subscriptions → BFF host: live updates
- BFF host → GraphQL registration: configures
- GraphQL registration → Domain GraphQL modules: registers
- BFF host → Token REST endpoint: serves
- Domain GraphQL modules → Authorized HTTP clients: queries downstream
- Token REST endpoint → Authorized HTTP clients: proxies
- Authorized HTTP clients → DataHub subsystems: typed HTTP
- BFF host → Revision audit log: audits revisions
- DataHub app root → Client observability: initializes
- Browser E2E → DataHub app root: exercises
