Read-only mirror of https://github.com/SFOE/emobility-backend — Bundesamt für Energie. Issues & pull requests at the source.
  • TypeScript 99%
  • JavaScript 0.6%
  • Shell 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-25 13:59:51 +00:00
.github docs: show the deployed version per environment in the README (#70) 2026-11-16 22:03:47 +01:00
scripts chore: remove obsolete test-token.txt file from scripts 2026-09-03 10:14:03 +02:00
src feat(monitoring): allow listed e-mail addresses on the monitoring API (#74) 2026-11-25 14:23:40 +01:00
swisstopo-s3-artifacts/test feat: add e-lkw calculation (#63) 2026-10-28 08:38:29 +01:00
tests feat(monitoring): allow listed e-mail addresses on the monitoring API (#74) 2026-11-25 14:23:40 +01:00
.gitignore feat: ensure unique Landing Zone batch keys via awsRequestId and improve SQS handling (#49) 2026-09-01 13:02:29 +02:00
.inspector-ignore feat: add inspector-scanner to deployment pipelines 2026-09-02 09:09:50 +02:00
.nvmrc feat: initial setup 2026-03-20 17:54:16 +01:00
.prettierignore chore: configure prettier and format files (#10) 2026-04-17 13:02:31 +02:00
.prettierrc chore: configure prettier and format files (#10) 2026-04-17 13:02:31 +02:00
.releaserc.json ci(release): release a patch for chore(deps) commits (#65) 2026-10-30 13:10:21 +01:00
CHANGELOG.md chore(release): 1.5.0 [skip ci] 2026-11-25 13:23:59 +00:00
CLAUDE.md refactor(tests): seperate guards tests in a own test file; add unit/integration tests for tariffs and locations module 2026-05-19 16:08:43 +02:00
eslint.config.js feat(lint): add curly brace rule for consistency (#20) 2026-05-06 15:50:43 +02:00
jest.integration.config.js refactor(config): setup dynamic aws resources (#34) 2026-05-19 14:43:56 +02:00
jest.unit.config.js refactor(config): setup dynamic aws resources (#34) 2026-05-19 14:43:56 +02:00
package.json chore: update AWS SDK dependencies to latest versions 2026-09-03 10:34:47 +02:00
production-readiness-open-issues.md feat: centralize and validate OCPI path parameters to ensure key safety (#53) 2026-09-08 10:39:55 +02:00
README.md chore: update deployed versions in README [skip ci] 2026-11-25 13:59:51 +00:00
translations-review.md feat: adjust feedback from flavio 2026-10-20 13:48:54 +02:00
tsconfig.json refactor(tests): PBFEITS-80 - seperatre test logic from business logic in a own directory; consolidate tsconfig and modernize TS module settings 2026-05-15 14:59:32 +02:00
yarn.lock chore: update AWS SDK dependencies to latest versions 2026-09-03 10:34:47 +02:00

eMobility Backend

OCPI backend of ich-tanke-strom (ITS 2.0), the Swiss national access point (NAP) for charging infrastructure data run by the Swiss Federal Office of Energy (BFE). AWS Lambda functions written in TypeScript behind an API Gateway HTTP API, with DynamoDB, S3 and SQS.

  • CPO-facing OCPI API (/ocpi/{version}/…, OCPI 2.2.1 and 2.3.0): charge point operators register via credentials and push locations (incl. EVSEs and connectors) and tariffs. Every push is stored as raw data and handed to the data lakehouse (emobility-data-pipelines). EVSE status is also written straight to DynamoDB.
  • Public read-only OCPI API (/ocpi/locations, /ocpi/tariffs, /ocpi/status, no authentication): serves the aggregated data to data consumers as OCPI 2.3.0.
  • Monitoring API (/monitoring/cpos, Cognito login, BFE staff only): per-CPO onboarding figures for BFE's E-Mobility Monitoring page (emobility-monitoring-web).
  • GeoJSON emitter: publishes the map data for swisstopo.

Infrastructure (Lambdas, API Gateway, DynamoDB tables, CloudFront/WAF) is defined in the prometheon-emobility-<env> Terraform repositories.

Deployed versions

Environment Version Since (UTC)
dev 1.5.0 2026-11-25 13:25
test 1.5.0 2026-11-25 13:27
prod 1.5.0 2026-11-25 13:59

Updated automatically by deployed-versions.yml after every deploy, from deploy.auto.tfvars in prometheon-emobility-<env>. A version there is rolled out by that repository's tofu apply, usually within a few minutes.

Architecture

CPO ──PUT/PATCH/DELETE /ocpi/{version}/…──▶ Lambda ──▶ S3 raw data ──▶ SQS ──▶ raw-data-loader ──▶ lakehouse landing zone
                                               └──▶ DynamoDB ocpi-evse-current-status (live EVSE status)

lakehouse (Glue, a few times a day) ──▶ DynamoDB ocpi-locations / ocpi-tariffs (finished OCPI 2.3.0 objects)
                                    └──▶ Gold JSON export (S3) ──▶ geojson-emitter (+ live status) ──▶ swisstopo GeoJSON

data consumer ──GET /ocpi/locations|tariffs|status──▶ CloudFront ──▶ Lambda ──▶ DynamoDB

Endpoints

CPO-facing (/ocpi/{version}/…, OCPI token via the Lambda authorizer):

Module Methods
versions GET /ocpi/versions, GET /ocpi/{version} (no token)
credentials POST, GET, PUT, DELETE
locations PUT, PATCH for location, EVSE and connector
tariffs PUT, DELETE

Public (no authentication, no version segment):

Route Data
GET /ocpi/locations?offset=&limit=&date_from= Published locations with EVSEs and connectors; limit 1–1000
GET /ocpi/locations/{country_code}/{party_id}/{location_id} One location, else 404 / 2003
GET /ocpi/tariffs?offset=&limit=&date_from= Valid (not deleted, not expired) tariffs; limit 1–1000
GET /ocpi/tariffs/{country_code}/{party_id}/{tariff_id} One tariff, else 404 / 2003
GET /ocpi/status?date_from=&limit= Live statuses received since date_from, oldest first; limit 1–5000 (default 5000), not paginated
GET /ocpi/status/{country_code}/{party_id}/{location_id}/evses/{evse_uid} {status, last_updated} of one EVSE

Lists use OCPI pagination: offset/limit, Link: <…>; rel="next", X-Total-Count, X-Limit. date_from filters on last_updated. The location and tariff objects are written by the Glue job; this repository only reads them. Their DynamoDB layout (GSI1 for offset paging, GSI2 for date_from) is documented in emobility-data-pipelines (docs/schemas.md). The consumer documentation is BFE's "Anleitung zum Datenbezug «Ich tanke Strom»".

Monitoring (CORS from the API Gateway):

Protected by an API Gateway JWT authorizer for the Cognito pool prometheon-prod-userpool (production eIAM, app clients emobility-monitoring-<env>). The handler additionally requires the group in MONITORING_REQUIRED_GROUP (bfe-all, BFE staff) in the access token's cognito:groups or an e-mail address from MONITORING_ALLOWED_EMAILS (comma-separated, the platform developers, who sign in with AGOV but are not BFE staff) in its email claim, and answers 403 otherwise. Without MONITORING_REQUIRED_GROUP it checks neither.

GET /monitoring/cpos returns, as OCPI data, every registered CPO (CPO roles in ocpi-credentials, without tokens or URLs) merged with the per-CPO figures the Glue job writes into ocpi-cpo-monitoring after each run: locations (total and published), EVSEs, tariffs, status updates (24 h and per day over 7 days), last data, pending quarantine. A party with figures but no credentials is listed with registered: false. The handler derives each CPO's status at request time, in this order: REGISTERED (no data), INACTIVE (latest data older than 48 h), FIRST_DATA (registered less than 14 days ago), MASTER_DATA_ONLY (no status update in 24 h), else ACTIVE. The response also holds the totals (summary), the previous run's totals (previous) and status_counts. The table layout is documented in emobility-data-pipelines (docs/schemas.md).

Project structure

src/
├── functions/                    # Lambda handlers (thin: validate → common → response)
│   ├── api/ocpi/                 # CPO-facing OCPI API + authorizer
│   ├── api/public/               # public read-only API (locations, tariffs, status)
│   ├── api/monitoring/           # GET /monitoring/cpos for the E-Mobility Monitoring page
│   ├── geojson-emitter/          # swisstopo GeoJSON publication
│   └── raw-data-loader/          # SQS → lakehouse landing zone
└── common/                       # shipped as Lambda layer, imported as /opt/nodejs/*
    ├── api/                      # OCPI response/error types
    ├── aws/                      # generic AWS clients and CRUD (DynamoDB, S3, SQS, …)
    ├── modules/<module>/         # module-specific OCPI types, DB access, transformations
    └── utils/                    # cross-module OCPI logic (guards, parsing, responses)
tests/
├── unit/                         # mirrors src/, dependencies mocked
├── integration/                  # against local AWS services (Ministack, needs Docker)
└── shared/                       # fixtures and test data

Conventions (layering, test scope) are described in CLAUDE.md.

Development

Requires Node.js 22 or newer (.nvmrc) and Yarn.

yarn install
yarn build              # TypeScript compile to dist/
yarn lint               # ESLint
yarn test:unit          # unit tests
yarn test:integration   # integration tests; starts Ministack via Testcontainers, Docker must run
yarn prettier --write <path>

yarn package builds the deployment artifacts: dist/emobility-backend.zip (Lambda functions), dist/common-layer.zip and dist/node-modules-layer.zip (Lambda layers).

Lambda configuration comes from environment variables set by Terraform, e.g. BASE_URL, RAW_DATA_BUCKET_NAME, INGESTION_QUEUE_URL, DATA_LAKE_HOUSE_LANDING_ZONE_BUCKET_NAME, CROSS_ACCOUNT_ROLE_LANDING_ZONE_ARN. DynamoDB table names are constants in src/common/aws/constants.ts.

Releases and deployment

Versions are created automatically by semantic-release from the commit messages on main:

  • PRs are squash-merged, so the PR title becomes the commit message and must be a Conventional Commit (checked by pr-title.yml).
  • feat: → minor; fix:, perf:, refactor:, revert:, chore(deps): → patch; feat!: or a BREAKING CHANGE: footer → major; docs:, ci:, other chore:, test:, style:, build: → no release.
  • release.yml tags the version (no v prefix, e.g. 1.2.0), creates a GitHub release with notes, commits the same notes to CHANGELOG.md (chore(release): … [skip ci]) and deploys it to dev, then test, automatically. Prod stays manual.
Workflow Trigger Purpose
Build & Test PRs and pushes to main Build, lint, unit tests
PR Title PRs Conventional Commit title
Release push to main semantic-release + CHANGELOG.md, then Publish & Deploy to dev, then test
Publish & Deploy Tag manual Promote a tag to an environment (prod; or redeploy dev/test)
Publish Tag / Deploy Tag manual, or called by the above Upload the artifacts to the environment's S3 artifact store / set backend_app_version in prometheon-emobility-<env>
Deploy Dev manual Deploy the current branch HEAD (by SHA) to dev for testing

Deploying means committing the new backend_app_version to the environment's Terraform repository, whose pipeline then applies it.