Architecture

emob architecture: sans-I/O Rust crates for Eichrecht, OCPP, OCPI and billing; eleven daemons connected by APIs and signed CloudEvents.

Eleven services share one estate configuration. Six keep signed journals that an independent witness can check. Stations connect to csmsd, empd authorises charging, billd invoices and roamd exchanges roaming records. The fifth journal belongs to poid, which records public-feed delivery. A native agreement binds a bill-to account to the accepted price at one point. The active card can be replaced under that agreement. The provider journals the agreement and the CSMS checks the current offer before online charging or reservation. The operator desk reads those services over their APIs and forwards each card change to the provider under the signed-in operator’s grant. emob does not implement the charging protocols itself: it builds on separate protocol libraries (OCPP, OCPI, OICP, ISO 15118, EEBUS, OCMF) and adds the business rules on top.

The stateless customer portal forwards the customer session to each owner. empd authenticates local identities and encrypts each customer’s grant records under a separate key. Its current key store lives outside the operational backup. billd rechecks those grants for each page and document. Customer access

Two roles: charge point operator and mobility service provider

A German charging business usually plays two roles. As CPO (charge point operator) it runs the stations; as EMP/eMSP (e-mobility service provider) it holds the driver’s contract and decides whether their card can charge. The billing service closes the CPO’s partner month and separately issues the eMSP’s retail invoices to drivers and fleet payers. The law gives each role different duties, so emob models both.

flowchart TB
    CS["Charging station"] <-->|"OCPP 1.6, 2.0.1 or 2.1"| CSMS["csmsd"]
    CSMS <-->|"Authorise charging"| EMP["empd"]
    CSMS -->|"Verified charging record"| ROAM["roamd"]
    CSMS -->|"Verified charging record"| BILL["billd"]
    ROAM <-->|"OCPI"| PARTNER["Roaming partner"]
    BILL -->|"Invoice event"| ERP["Billing recipient"]
    CSMS -->|"Public registry and observations"| POI["poid"]
    POI -->|"Static table"| NAP["Mobilithek"]
    POI -->|"Status and price updates"| NAP
    DRIVER["Driver"] -->|"Point or provider price"| CSMS
    DESK -->|"Review and allocate payments"| CASH["accountingd"]
    CASH -->|"Read issued retail facts"| BILL
    PORTAL["portald"] -->|"Customer session and agreements"| EMP
    PORTAL -->|"Scoped history and original UBL"| BILL
    DESK["deskd"] -->|"Read operator evidence"| CSMS & BILL & POI
    DESK -->|"Enrol and manage cards"| EMP

The public-feed worker sends to registered offers when configured. The OICP adapter is available as a library. A Hubject connection requires a partner integration.

When an operator’s own EMP charges at its own stations, the session goes through the same model as a roaming session — same validation, pricing and evidence — so adding partners changes the transport, never the arithmetic.

Workspace layout: domain crates, the service shell and daemons

LayerWhereDoes I/O?
Domain cratesUnder crates/emob-*No — sans-I/O, no clock, no floats
Service shellcrates/emob-serviceYes — HTTP, config, journals, shutdown
Daemonsservices/* (eleven binaries)Yes — sockets, clock, files
Protocol kitsseparate crates on crates.iothe wire formats

Domain crates ✅

CrateHolds
emob-coreIdentifiers (EVSE id, eMAID, party id) that compare canonically and print verbatim; exact energy and money; the 15-minute settlement grid; charge-point, provider and company profiles; the obligation calendar; Crossing, the account of what a translation lost
emob-eichrechtGerman calibration law over OCMF records: the key registry, the chain check, the evidence record, and the transparency file a driver checks the bill with
emob-sessionAuthorisation paths, meter series, the session state machine, and the quarter-hour split that conserves energy exactly
emob-cdrThe charge detail record with its price, idempotent acceptance, and pre-flight validation
emob-tariffRating with tiers and VAT breakdown, the price display derived from the same tariff, the AFIR shape check, validity windows
emob-ocppThe OCPP seam: signed meter values out of transaction events, and the tariff onto OCPP 2.1’s Tariff and Cost messages
emob-poiThe location register and the DATEX II feed for the national access point
emob-roamCDRs, tariffs and locations onto OCPI 2.3.0 / 2.2.1 and OICP, each translation returning an account of what it cost; routing by the contract id’s issuer
emob-pncPlug & Charge from the platform’s side: which ecosystem a contract certificate belongs to, revocation, and the eMAID read from the certificate
emob-eebusThe § 14a wire: a grid operator’s EEBUS setpoint as an exact decimal, and the failsafe states of the Limitation of Power Consumption use case
emob-smartWhich charge points § 14a reaches, the guaranteed minimum power, and allocation under a grid limit
emob-billingEN 16931 invoices with per-line rounding, VAT treatment derived from the parties, SEPA direct debits, and postings by role
emob-thgThe greenhouse-gas quota (THG-Quote): eligibility conditions and notifications built only from signed energy
emob-simA deterministic simulated fleet whose stations sign genuine OCMF, with seeded faults

Daemons

DaemonResponsibility
csmsdConnects OCPP 1.6J, 2.0.1 and 2.1 stations, verifies signed readings, settles sessions and serves driver receipts.
empdAuthorizes charging cards, records driver agreements and payer assignments, and manages customer sessions and access grants.
billdCloses retail and partner billing periods, issues invoices and corrections, and retains the original UBL.
roamdExchanges OCPI credentials and charge detail records with the configured roaming parties.
deskdRuns Heute for operators to investigate sessions, manage stations and cards, grant customer access and review invoices. Witnesses signed journal heads.
accountingdReplays retail issues and credits, books local statement entries and owns the receivables balance and named allocations.
portaldShows customers their assigned agreements, receipts and payer invoices in German or English.
tarifdPublishes the estate’s versioned charging tariffs and driver price documents.
poidPublishes the public point register and static and dynamic DATEX II offers, and records receiver acknowledgements.
sitedApplies § 14a site setpoints and the configured failsafe when the grid operator goes silent.
agentdRuns read-only evidence, tariff and compliance specialists.

The edges between them:

From → toHow
station → csmsdOCPP over wss://; Basic against an Argon2id hash, or a client certificate
csmsd → empdPOST /v1/authorize with the service token; a timeout answers Invalid (fail closed)
csmsd → billd, roamdthe outbox: each settled session as a de.emob.cdr.issued CloudEvent, signed per Standard Webhooks, POST /v1/deliveries, retried until a 2xx, journalled
roamd ↔ partnerOCPI 2.3.0 credentials, CDRs
deskd → csmsd, billd, roamdthe bounded operator read models, GET /v1/<daemon>/today
deskd → accountingd → billdThe finance operator’s bearer authorizes an on-demand read of issued documents. Each service checks the explicit finance grant.
billd → empdA withdrawal credit checks the approved decision and billing disposition before the issuer commits a numbered credit.
portald → accountingd → billdA live payer session authorizes one invoice balance. Billing supplies current issued and credited amounts. Accounting supplies applied cash.
portald → empd, billdcustomer session and current agreement or payer grants on every read
deskd → empdprivate card and agreement lookup with a reader, enrolment and card changes with the signed-in writer
deskd → csmsd, billd, roamd, empd and configured accountingdSigned journal heads at GET /v1/<daemon>/head, every 30 s. An independent witness can also track poid.
deskd → billdaccount/month review for staff, issue with a named writer and retail UBL download with a finance grant
billd → operator systemeach issued partner invoice as a de.emob.invoice.issued CloudEvent carrying the UBL or CII file, signed, retried until answered
csmsd, billd → subscriberseligible events without private retail attribution to each [[subscribers]] entry whose types take them, each signed with its own secret, retried until a 2xx, journalled

Between emob and anything else there are two ways in or out: an HTTP API or a CloudEvent. emob emits two event types, both in its own namespace — de.emob.cdr.issued (subject cdr/<key>) and de.emob.invoice.issued (subject invoice/<number>) — and reads no other system’s types; where two systems meet, an adapter renames.

Every daemon serves /health/live, /health/ready and /about, and its read model behind the operator token. emob demo runs the daemons’ own daemon::run functions in one process — the same code path as their main, configured rather than forked — and deskd takes its clock as a parameter, so the demo can play a morning at 60×. See Run the estate.

1495 tests cover the workspace.

An end-to-end test drives the full chain: OCMF records signed with a real key at test time, verified, matched against a session, split into quarter hours, built into a CDR, priced from those quarter hours, validated as a partner would, accepted once and exported as a transparency file — with the displayed price asserted equal to the charged one. It also proves the failures: a changed digit, a deleted record, a substitute reading, an unregistered station and an unsynchronised clock each stop the right part of the chain with a named reason. Two further tests take the same session through OCPI 2.3.0, OCPI 2.2.1 and self-roaming at the same money, and close a month into an invoice, a pain.008 file and balanced postings.

Sans-I/O domain crates: why the rules never touch a clock

The domain crates never read a clock, open a socket or touch the filesystem. Every instant is an argument and the key registry is passed in already loaded.

The reason is disputes. Eichrecht gives a customer years to question a bill, and the answer is to replay the verification exactly as it ran — same records, same keys, same instant. A replay that consults the ambient world is no longer a replay. just purity and check-graph fail the build if a domain crate, or any of its dependencies, reaches for a clock, a socket or a database.

The same crates hold no binary floating point (no-floats): every quantity is or becomes money, and f64 cannot represent 0.10.

The Crossing: every translation reports what it cost

Translating a record into another company’s format is where roaming money goes missing: a silent conversion makes a lossy decision, and weeks later two companies hold two numbers for one session. So every translation returns a Crossing — the translated value and notes, addressed by JSON Pointer into the recipient’s document, saying what was assumed or lost.

Three seams use it: OCPI and OICP in emob-roam, DATEX II in emob-poi, and the OCPP 2.1 tariff in emob-ocpp. An example: OCPI states durations in hours, and most durations have no exact decimal in hours (an hour has 3600 seconds, and 3600 has two factors of three). Twenty minutes becomes 0.3333 h, and the note says that the cost beside it was computed from whole seconds.

Where a note would not be enough, the translation refuses. A V2G discharge has no signed representation in an OCPI CDR, so it would arrive as an ordinary draw and settle backwards; an unrated record cannot cross because 0.00 means free of charge. Details are on the roaming page.

The daemon shell: emob-service

emob-service is the shared shell every daemon builds on: settings, telemetry, health probes, graceful shutdown, a journal, CloudEvents, webhook signatures, and an authority model for OCPI parties.

Authority: a valid token is not access to someone else’s records

A roaming node holds several companies’ sessions in one process. Its worst failure is serving party A’s CDRs to party B in answer to a perfectly valid credential. A reverse proxy cannot catch that, because it does not know who owns a record. So a Principal answers three separate questions — who, what, and whose records:

let peer = Principal::peer(theirs, Role::Emsp, Capabilities::of([caps::CDR_READ]));

peer.may_act_for(caps::CDR_READ, &theirs);   // true
peer.may_act_for(caps::CDR_READ, &ours);     // false — someone else's record
peer.may_act_for(caps::CDR_WRITE, &theirs);  // false — reading is not writing

attenuate derives a narrower principal and returns nothing rather than widening. Misconfiguration fails closed: an empty grant permits nothing, an empty readiness set is not ready, and a webhook verifier without a secret rejects.

Optional Cedar policies

For conditions a capability list cannot express — “CDRs, until the trial ends” — the optional policy feature adds Cedar policies. It is off by default because it adds many dependencies and only the roaming node needs it.

@id("nl-tnm-trial")
permit (
  principal == emob::Party::"NL*TNM",
  action in [emob::Action::"emob.cdr.read", emob::Action::"emob.tariff.read"],
  resource
)
when { resource.owner == principal }
unless { context.at > datetime("2027-01-01T00:00:00Z") };

Readiness and shutdown

Readiness is a set of named dependencies, and a 503 lists which are missing, so an orchestrator never routes stations to a CSMS whose key registry has not loaded. Liveness is separate, because restarting a CSMS drops every station’s connection. Shutdown first stops reporting ready, then drains, so a stopping CSMS does not lose the final transaction message that carries the signed meter record.

The journal: state that survives a restart ✅

The domain crates are stateless. The daemons hold the rules about history: an invoice number is used only once [UStG §14(4) Nr. 4]; a CDR is sealed once the eMSP has it [OCPI 2.3.0 §mod_cdrs]; a card is blocked; a contract has run up these sessions. Held only in memory, each of these answers wrongly after a restart.

emob_service::journal stores them. A daemon appends the facts it decided, in order, and rebuilds its state on startup by folding them. Because every instant and key is an argument, the fold gives the same answer every time.

Six services replay their journals on startup. csmsd, billd, roamd, empd and accountingd seal private record bodies with AES-256-GCM under per-service keys. The hash chain covers the sealed bytes and can be verified without decrypting them. poid signs the head of its public register journal. Each journal has one writer.

Deployment

One Dockerfile builds all eleven daemons and the emob command line, selected by a build argument, on a distroless/cc runtime (no shell, no package manager). docker-bake.hcl builds them all; compose.yaml starts them on one machine with a named volume per journal. Every default bind address is loopback, so nothing is reachable until you configure it, and csmsd refuses a non-loopback OCPP bind without TLS. Release images are ghcr.io/hupe1980/emob-<daemon>:<version> plus ghcr.io/hupe1980/emob (which just demo runs where there is no Rust toolchain), linux/amd64 only, with build provenance. See Run the estate.

The OCPP seam and csmsd

OCPP carries two kinds of meter value and only one is billable. The numeric ones (meterStop, SampledValue.value) tell you whether every event arrived; the signed OCMF data set is what you may bill. The Open Charge Alliance’s own example carries meterStop: 108814 — the meter’s lifetime register in Wh — beside a signed value of 0.636 kWh for the transaction.

emob-ocpp makes the separation structural: its input types have no numeric meter value field, so nothing from the protocol’s numbers can reach a CDR. It is a crate of its own so that emob-core, emob-session, emob-eichrecht, emob-tariff and emob-cdr build without any OCPP in their dependency tree; it depends on emob-tariff, never the reverse.

csmsd is deliberately thin. It runs two ledgers side by side: ocpp-kit’s operational ledger (did every message arrive? was this a retry?) and the Eichrecht chain (what may be billed?). The operational verdict is read, so a station’s retried stop message is not treated as a second session. A station must be provisioned before it is admitted — an unknown identity in the WebSocket URL is answered 404 [OCPP 2.0.1 Part 4 §3.1.1] — and its public key comes from type approval, never from the station itself. An integration test runs a real ocpp-kit station against csmsd over a TCP WebSocket and bills the OCA example at 0.636 kWh. See The OCPP seam.

Advisory agents: agentd proposes, it cannot move money

The libraries answer questions about one thing. An operator’s morning question is about a population: four hundred refused sessions may be four hundred tickets or one faulty meter.

[evidence-triage] BQ27400330016: the meter was in state Substitute at record 2,
                  which may not be billed
                  (3800.000 kWh at risk across 380) — a device fault rather than
                  a dispute: raise it with the station vendor…

agentd’s three specialists — evidence triage, a tariff sweep and a compliance sweep that judges upcoming duties against today’s estate — are deterministic functions on agentplane; none calls a language model. “Advisory only” is structural: nothing in the workspace consumes their output type, and a specialist’s principal is derived with attenuate, so it cannot hold a write capability. Each specialist is started by its read capability, and the runtime acts as the advisory principal’s delegation chain: agentplane refuses at admission a run whose capability is outside it. agentplane records each run in a hash-chained log that can be replayed.

Testing with a simulated fleet

emob-sim runs a reference day: virtual stations that sign genuine OCMF with real ECDSA keys, run through the real verifier, split, rating engine and ledger. Eight faults are seeded — a substitute reading, a dropped record, a tampered byte, an unsynchronised clock, an export register billed as a draw, a TX=X exception, an unregistered station, and a tariff the post may not offer — and the run asserts each is exercised.

The key assertion is that energy reconciles: every kilowatt-hour a meter moved either reached a settled record or was refused with a reason. Half the posts are 22 kW and half 150 kW, because a per-minute-only tariff is lawful on the first and not on the second [AFIR Art. 5(4)]. The fleet run is what showed that evidence which is present but failed must be refused, not just evidence that is absent.

Protocol kits emob builds on

emob does not implement charging protocols; it depends on these libraries:

LibraryVersionWhat emob uses
ocmf0.2Parsing and verifying OCMF records without disturbing the signed bytes; the S.A.F.E. transparency container
ocpp-kit0.8OCPP 1.6J / 2.0.1 / 2.1 messages, transport and the CSMS ledger
ocpi-kit0.5OCPI 2.1.1 / 2.2.1 / 2.3.0 models, version translation and the client. Not its tariff engine: one pricing engine means one answer
oicp-kit0.1Hubject OICP, CPO and EMP sides
datex20.3DATEX II for the AFIR feed to the Mobilithek
iso151180.9Certificate path validation for Plug & Charge
eebus0.14SHIP and SPINE for § 14a; used without its runtime, so emob-eebus stays sans-I/O
en16931, en16931-formats0.10The European e-invoice model, validation, UBL and CII
sepa0.10SEPA direct debit (pain.008)
doubleentry0.9Bookkeeping in billd
agentplane0.61The run journal for agentd

All workspace members require Rust 1.96. Run just msrv to check the locked dependency graph at that floor.

Why the dependencies point the way they do

Roaming protocols

WirePartnerViaState
OCPI 2.3.0 (2.2.1 translated at the edge)peers, most hubsocpi-kit✅ library and roamd
OICP 2.3Hubjectoicp-kit✅ library (outbound documents) · ⏳ roamd transport
eMIPGIREVE legacy—not supported; GIREVE speaks OCPI
OCHPe-clearing.net—not supported; the specification froze in 2016

The rules that hold across every wire:

§ 14a: controllable charge points

[EnWG §14a] lets a grid operator reduce the draw of controllable devices, and [BK6-22-300 Ziff. 2.4.1] excludes publicly accessible charge points — so § 14a reaches depots, workplaces and fleet yards, not the public fast charger. emob-smart allocates power so the grid limit cannot be exceeded (allocate is the only way to get an Allocation, and it takes the limit), and keeps the minimum power the operator is owed. See § 14a and the grid.

Build guards

just guards runs checks the compiler cannot:

GuardPrevents
no-floatsbinary floating point anywhere money is computed
check-citationsa regulatory citation in code or docs that names no known document
check-manifestsa cargo publish that fails after the version is spent
purity / check-grapha domain crate reaching a clock, socket or database, directly or through a dependency
check-constructorsa type with a validating constructor that derives Deserialize, which would let wire data bypass the validation
check-reacha public function nothing calls — a rule nobody enforces
check-apidocumentation naming an API that no longer exists
check-prosea user-facing string with a hole from a lost line continuation
check-wirea date serialised in a format partners cannot read instead of RFC 3339
check-conceptsa count stated in documentation that does not match its source, and malformed Markdown tables
check-actionsa GitHub Action not pinned by commit SHA, a base image not pinned by digest, a workflow without declared permissions:

Related: Getting started · The Eichrecht chain · Roaming · threat model

The replacement interface guide maps the authorization, tariff, event and MCP contracts to their owners and probes.