Charging Station Management System for ChargeHub: a Java / Spring Boot backend that talks to charge points over OCPP 1.6J and will replace the simulated data source of the ChargeHub dashboard.
A charge point connects over OCPP 1.6J and is registered when it boots. The central system stores every charging station with its connectors, keeps their status up to date and marks a station offline when it goes silent. It authorizes id tags and records charging sessions with their meter values, also when they arrive late, twice or out of order.
- Done:
- Foundations: multi-module build, CI, quality gates, local infrastructure, database baseline, architecture tests.
- OCPP 1.6J protocol layer: OCPP-J codec, validation against the official JSON schemas, the WebSocket endpoint, outbound calls matched with their answers, and an answer to every incoming call.
- Charge point simulator: many charge points that boot, send heartbeats, report connector status and reconnect like real ones. On purpose they can drop connections, repeat calls, report
Faultedconnectors and run with a skewed clock. The central system's integration tests use it as a fixture. - Charging stations: registered on BootNotification and stored in PostgreSQL, with persistence kept apart from the domain model (ADR 0014). Connector status follows the OCPP 1.6 transitions: a report that breaks them, or that is older than the last one, changes nothing and is counted and logged, while the charge point still gets its answer (ADR 0013). A station that stays silent for three heartbeat intervals is marked offline by a scheduled job that runs on one instance at a time (ADR 0015).
- Authorization and charging sessions: id tags with their status, Authorize, StartTransaction, MeterValues and StopTransaction. Transaction ids come from the database, and a message sent again is recognised by its content and stored once (ADR 0016). Each start, stop and reading keeps the time of the charge point and the time it was received, and a session whose clock drifts is flagged (ADR 0017). Energy registers that go backwards are found when the readings are read (ADR 0018).
- Offline transactions: a simulated charge point that loses its connection goes on charging and sends its transaction messages in order after the next boot. The compose demo charges with demo id tags that only a
demoprofile adds (ADR 0019).
- Next: tariffs and charge detail records.
- OCPP 1.6J Core Profile and Remote Trigger
- Charge point registry, live connector status, offline detection
- idTag authorization, charging sessions and meter values, including offline transactions
- Tariffs (energy, time, fixed fee, time-of-day) and charge detail records with VAT
- Payment with pre-authorization and capture (Stripe test mode)
- Versioned REST API and server-sent events for the ChargeHub dashboard
A modular monolith on Spring Modulith (ADR 0002), split into Gradle modules (ADR 0004):
| Module | Purpose |
|---|---|
ocpp-protocol |
OCPP-J codec, official OCPP 1.6 JSON schemas and validation, outbound call matching, typed messages; free of Spring |
csms-app |
Spring Boot application. Spring Modulith modules: ocpp (WebSocket endpoint, connections, call routing), station (charging stations, connector status, offline detection), authorization (id tags, Authorize) and session (transactions, meter values) |
charge-point-simulator |
Simulated charge points that speak OCPP only, through ocpp-protocol (ADR 0010), one virtual thread each (ADR 0011) |
Module boundaries are enforced by tests: Spring Modulith verification and ArchUnit rules fail the build when one module reaches into another's internals.
All decisions: docs/adr.
Java 25 (virtual threads) · Spring Boot 4.1 · Spring Modulith 2.1 · PostgreSQL 18 with Flyway · Jackson 3 · Keycloak 26 · Gradle 9 (Kotlin DSL) · JUnit, AssertJ, Testcontainers, ArchUnit, jqwik
Every pull request runs ./gradlew build and starts the Docker Compose stack in CI. The build fails on:
- formatting drift (Spotless, google-java-format)
- Error Prone findings and nullness violations (NullAway with JSpecify
@NullMarkedpackages) - architecture violations (Spring Modulith, ArchUnit)
- Jackson version drift between modules (ADR 0006)
- coverage below 80% of lines or branches in
ocpp-protocoland in domain packages (JaCoCo) - a change to any of the official OCPP schemas, which are kept byte for byte as published
CodeQL scans the code and SonarQube Cloud analyses every pull request. Test and coverage (JaCoCo) reports are uploaded as CI artifacts on every run, including failed ones.
The central system and 100 simulated charge points, built from the repository. The first build downloads every dependency and takes several minutes.
cp deploy/.env.example deploy/.env # then set the passwords
docker compose -f deploy/docker-compose.yml --profile sim up -d --build
deploy/check-simulated-charge-points.sh # all 100 accepted, none reconnecting for a minute
deploy/check-demo-sessions.sh # every charge point charged, with meter valuesThe charge points also charge: each one presents its own id tag, DEMO-0001 for SIM-0001, and runs one short session after the other, sending meter values while it charges. The central system knows these tags because compose runs it with the demo profile, which adds them to the database. The normal migrations never do (ADR 0019). CI runs both checks on every change.
The same charge points can misbehave on purpose: with the chaos profile their connections drop at random, some calls arrive twice, connectors go to Faulted for a while and clocks run off by a few minutes (charge-point-simulator/src/main/resources/application-chaos.yaml). A charge point that loses its connection while charging goes on charging, keeps its transaction messages and sends them in order after the next boot (chargehub.simulator.sessions.offline-transactions, off by default).
docker compose -f deploy/docker-compose.yml --profile chaos up -d --buildRequirements: JDK 25, Docker.
cp deploy/.env.example deploy/.env # then set the passwords
docker compose -f deploy/docker-compose.yml up -d
./gradlew buildPostgreSQL listens on 127.0.0.1:5432, Keycloak on 127.0.0.1:8180.
Run the application with readable logs (the database password comes from deploy/.env):
set -a && . deploy/.env && set +a
SPRING_PROFILES_ACTIVE=dev ./gradlew :csms-app:bootRunOr run it as a container, built from the repository with Docker alone (ADR 0012). The first build downloads every dependency and takes several minutes:
docker compose -f deploy/docker-compose.yml --profile app up -d --buildA charge point connects to ws://localhost:8080/ocpp/{chargePointId} with the WebSocket subprotocol ocpp1.6. The id may contain letters, digits and ._:-, up to 48 characters.
With the application running, start 100 simulated charge points in a second terminal:
./gradlew :charge-point-simulator:bootRun --args="--chargehub.simulator.charge-points.count=100"Their ids are SIM-0001 to SIM-0100 (chargehub.simulator.charge-points.id-prefix), and they connect over the first 5 seconds (chargehub.simulator.charge-points.start-spread). Each one connects to ws://localhost:8080/ocpp (chargehub.simulator.central-system), boots and sends heartbeats at the interval the central system answers with. When the connection is lost it connects again, waiting longer after each failed attempt (chargehub.simulator.reconnect.*).
Given id tags, the charge points also charge, one session after the other:
./gradlew :charge-point-simulator:bootRun --args="--chargehub.simulator.sessions.id-tags=TAG-A,TAG-B"The tags go to the charge points in turn, and the central system accepts only the tags it knows. A tag cannot charge at two charge points at the same time, so for many charge points --chargehub.simulator.sessions.id-tag-prefix=DEMO- gives each one a tag of its own: SIM-0001 presents DEMO-0001. Each session authorizes the tag, starts a transaction, charges at 11 kW for 5 minutes and stops, with a pause of 1 minute before the next one (chargehub.simulator.sessions.power-watts, .duration, .idle-time). While charging it sends its energy register every minute (.meter-value-interval). The status of the connector follows the session, and its energy register only goes up.
- Meter values are kept in one table with an index per session and time, not in monthly partitions. At the volume this project runs, the index is enough; partitions would add a job that creates them ahead of time, for a gain that shows only with years of readings.
- OCPP 2.0.1: the protocol sits behind its own module, so it can be added later (ADR 0003)
- Full OCPI roaming
- Signed meter values (Eichrecht)
- Kubernetes and Kafka
The OCPP 1.6 JSON schemas in ocpp-protocol are published by the Open Charge Alliance under CC BY-ND 4.0 and are included unchanged; see their NOTICE.