Run the operator services
Start the services, configure credentials, and inspect their HTTP APIs, events and error codes.
Each domain service owns a PostgreSQL schema and exposes an HTTP API. The customer gateway composes account views on demand. The Desk reads those APIs, and signed events carry contract changes between services.
| Service | Port | Owns | You can replace it with |
|---|---|---|---|
| contractd | 9401 | Customers, billing accounts, contracts, subscriptions, identifiers; the renewal and ending passes; the renewal notice | Your CRM or order system |
| billd | 9402 | Price books, usage, the open bill, sealed bills and their documents, Stornorechnungen and staged booking commands | Another billing engine |
| usaged | 9403 | Outbound voice classification, switch receipts, itemisation and its retention | Your mediation platform |
| accountingd | 9404 | Invoice balances, bank receipts and journal | Your ERP |
| chargingd | 9405 | Network quota, settlement and session evidence | Your charging function |
| portald | 9406 | Customer API, combined overview and mailbox | A compatible customer gateway |
| agentd (optional) | 9408 | Read-only investigations and their local run journal | An operator assistant |
Commands and queries are REST. Facts cross as CloudEvents over Standard Webhooks: contractd delivers each event, signed and in order, to billd's /inbox; billd reads the resource's current state from contractd and bills from its own copy. A late fact is corrected by the next bill, never by re-opening a sealed one.
Run them
just demo # Docker Compose: the estate from one image, a year of bills, the Desk on :9400
just dev # Local services and the Desk on port 5179, with PostgreSQL in Docker
just seed # a year of bills into just dev
just listen # every event as it happens
just conformance contractd http://127.0.0.1:9401Compose binds the Desk to loopback on port 9400 and the headless customer API on 9406. The service binaries in the Compose demo support the healthcheck command for container probes.
Use GET /health/live for liveness and GET /health/ready for readiness. A domain service returns 503 when its database is unavailable. Its GET /health endpoint reports service-specific status.
Service configuration:
| Variable | Meaning |
|---|---|
TELCO_LISTEN | Default 127.0.0.1:9401 (contractd), 127.0.0.1:9402 (billd), 127.0.0.1:9403 (usaged), 127.0.0.1:9404 (accountingd), 127.0.0.1:9405 (chargingd), 127.0.0.1:9406 (portald). agentd reads AGENTD_LISTEN (default 127.0.0.1:9408) |
TELCO_DATABASE_URL | The runtime role's connection: contractd_app, billd_app, usaged_app, accountingd_app or chargingd_app, DML on its own schema only |
TELCO_MIGRATION_URL | The owner's connection (contractd_owner, billd_owner, usaged_owner, accountingd_owner, chargingd_owner). When set, the schema is applied and the runtime role granted |
TELCO_RUNTIME_ROLE | Defaults to the service name plus _app |
TELCO_API_KEYS / TELCO_API_KEYS_FILE | Named keys, ;- or line-separated: name role secret [patterns]. Use secrets of at least 16 characters. Optional patterns limit visible events. See Keys and roles |
TELCO_WEBHOOK_KEY | The master key webhook secrets are derived from (≥ 32 bytes); webhooks need it |
TELCO_CLOCK | system (the Europe/Berlin date) or test:YYYY-MM-DD |
TELCO_ENVIRONMENT | production (the default: refuses a test clock and plain-http links), development or test. usaged requires named API credentials in every environment |
TELCO_PASS_INTERVAL_SECS | Default 3600 |
TELCO_OPERATOR | Required. A TOML file with the operator every document names (example); a field § 62 TKG or § 14 UStG requires that is missing stops the start |
TELCO_PUBLIC_PLANS | Exact pinned tariffs served by billd’s anonymous /mcp/public checker, comma-separated. Empty by default. |
TELCO_MCP | on enables the authenticated read tools and billd’s scoped proposal tools. Defaults to off. |
contractd also reads:
| Variable | Meaning |
|---|---|
TELCO_RENEWAL_NOTICE_LEAD_DAYS | Default 30 |
TELCO_SUBSCRIBERS | Where events go: billd=https://billd.example/inbox,crm=… |
TELCO_SUBSCRIBER_<NAME>_SECRET (or …_SECRET_FILE) | The signing secret per subscriber: whsec_ + base64, or at least 32 bytes |
TELCO_SUBSCRIBER_<NAME>_TYPES | Optional type patterns, e.g. de.telco.contract.* |
billd also reads:
| Variable | Meaning |
|---|---|
TELCO_SOURCE_URL | Where contract facts are read: contractd, or what stands in its place |
TELCO_SOURCE_TOKEN (or …_FILE) | billd's own token for those reads |
TELCO_INBOX_SECRETS (or …_FILE) | The secrets a delivery may be signed with, comma-separated (rotation: list old and new) |
TELCO_PRICEBOOKS | A directory of price-book directories; a plan assignment pins id@version |
TELCO_ACCOUNTING_URL | Accounting service or ERP base URL |
TELCO_BOOKING_TOKEN (or …_FILE) | Dedicated booking credential for that service |
usaged reads TELCO_VOICE_PLAN, TELCO_BILLD_URL and TELCO_MEDIATION_TOKEN. For subscriber itemisation it also reads TELCO_EVN_PROTECTED_FILE. Configure switch intake · Configure itemisation
For the standalone OpenAPI contract and mailbox read receipts, see Build on the customer portal API. For customer sign-in, scoped service credentials, the cancellation form and verification links, see Host the fibre customer portal.
For chargingd peer URLs, named network clients, quota and operator routes, see Online charging.
accountingd configuration and operations are described in Reconcile bank payments.
| Variable | Meaning |
|---|---|
TELCO_LEDGER_ID | The ledger's id (default telco.local/books); the ledger lives in schema ledger |
Outside development, every URL must be https (loopback excepted). Each service checks its configuration before starting and lists every problem at once, never a secret.
Guarantees
- Each domain service owns its data. One schema and one role pair per domain service; a runtime role has no right on the other's schema, so a cross-service query is a permission error, not a convention.
- One transaction per change. Every state change commits with an append-only fact and its event, or none of them does — the event is the outbox.
- History is append-only. Facts, events, bills, their charges and files, and the inbox refuse UPDATE and DELETE, even to the owner.
- Nothing lost, nothing applied twice. A subscriber's cursor moves only after a 2xx; billd takes each event id once, in the transaction of its effect.
- No full IBAN in billd. contractd's reads serve it masked; billd stores and prints only
DE…3000. - No overlaps. The database refuses overlapping plan assignments and an identifier held twice, also when two requests race.
- One clock. Business dates come from the injected clock; a guard refuses
now()/current_datein the services' SQL.
Replace a service
Domain services publish their HTTP operations in OpenAPI. Event producers also publish a catalogue with each event’s meaning and source. To stand where contractd stands, a CRM:
- emits the contract facts —
de.telco.customer.*,de.telco.billing-account.*,de.telco.contract.*,de.telco.subscription.*— as signed CloudEvents to billd's/inbox, subjectcontract/{id}and so on; - serves four reads billd calls with its own token:
GET /customers/{id},/billing-accounts/{id}(IBAN masked),/contracts/{id},/subscriptions/{id}(with the plan assignments).
Then hold it to the boundary:
just conformance contractd https://crm.example --ids <customer>,<account>,<contract>,<subscription>
just conformance billd https://billd.example --secret "$TELCO_INBOX_SECRET"Every check prints ✓ or ✗ with what was expected. The reference services pass the same kit in just test-db. To skip a service altogether, embed the crates (telco-core, telco-render, telco-events) and call the domain directly.
Delivery and the inbox
A delivery is POST <subscriber> with content-type: application/cloudevents+json and the headers webhook-id (the event id), webhook-timestamp and webhook-signature (v1, + base64 HMAC-SHA256 of {id}.{timestamp}.{body}).
| The receiver answers | contractd does |
|---|---|
| 2xx | Moves the cursor past the event |
| 410 | Pauses the subscriber (health shows it) |
| anything else, or no answer | Stops that subscriber and retries after 1 s, doubling to 5 min |
Events reach a subscriber in sequence order; a type filter skips but still moves on. contractd's GET /health shows each subscriber's pending events, attempts and last error.
billd's POST /inbox refuses a body over 64 KiB, then a signature that does not verify or a timestamp more than five minutes off (401 inbox.unauthenticated) — before reading or writing anything. A subject other than customer|billing-account|contract| subscription + / + a UUID is taken as ignored and never requested. It answers {"outcome": "applied" | "ignored" | "gone" | "duplicate"}, or 503 inbox.source-unavailable when the source cannot be read, so the sender tries again.
The test clock
Advance the test clocks in service order. Set contractd first with PUT /clock. Its response reports the events it delivered and lists any subscribers still behind. Set accountingd next to reevaluate prepaid month boundaries. Advance chargingd to expire outstanding grants. Advance billd to seal invoices with the delivered facts, then usaged for traffic-data retention. Zeitreise, telco demo and just demo-signup advance all five clocks.
API
Private routes require Authorization: Bearer <key>. Each domain service documents its public and signed-ingress routes. portald publishes its contract at /api/v1/portal/openapi.yaml. Bodies refuse unknown fields. Each service's OpenAPI 3.1 document is services/<service>/openapi.yaml; a test keeps it equal to the router's route table and to every problem code the service can return.
Keys and roles
Each caller has its own named key, so the log, the webhooks and a revocation name who:
TELCO_API_KEYS="desk operator $DESK_KEY; crm integration $CRM_KEY contract,customer; bi read $BI_KEY"| Role | May |
|---|---|
operator | The Desk, carrier order registration and oversight, every webhook, the test clock, credit notes and sealed rating case exports |
integration | Read, and the business operations an integration performs (sign-up, approval, termination, usage, its own webhooks) — not PUT /clock, not POST /bills/{id}/credit-note |
field | Submit field evidence on assigned appointment cases |
booking | Submit accounting bookings, statutory credits, validated prepaid enrollments and rated charge revisions. Read the account receivable and reviewed credit basis. Execute approved goodwill and tariff changes. |
fault-desk | Supply timestamped outage and repair observations. Each managed incident binds to the original sender. |
investigator | Read the paired invoice evidence from billd for the private Desk investigator. |
billing-source | Read the four contract resources and approved appointment and outage awards from contractd as billd. |
outage-receipt | Read the posted outage receipt from accountingd as contractd. |
read | General read APIs and MCP's read-only tools |
finance | Preview, issue, list and retrieve DATEV batches on accountingd. A separate credential on billd reads the period’s pending booking count. Finance export |
mediation | Deliver classified fixed-line batches to billd and read the frozen invoice facts needed for itemisation and deletion. |
switch | Import mobile batches at billd or outbound voice CSV and JSON at usaged as the named source. Read its voice receipts. Mobile usage · Voice imports |
bill-reader:<account-uuid> | List and retrieve sealed bills for the account through TMF678. Partner bills |
usage-reader:<account-uuid> | List and retrieve accepted mobile traffic records for the account through TMF635. Partner usage |
reviewer | Inspect the queue and approve or reject a proposal under a personal identity. |
proposer:<account-uuid> | Capture evidence, draft checked answers and propose remedies for one account. |
reply-delivery | Poll approved customer replies and acknowledge delivery. |
prepaid-oss | Poll prepaid network proposals and acknowledge one revision. Network controls |
customer:<account-uuid> | Access the account’s portal, invoices, eligible itemisation, prepaid wallet and mobile meters. The authenticated customer portal holds the credential. Customer meter |
carrier | Read its own orders and submit S/PRI messages. The two carrier routes are restricted to the permissions described in Open-access provisioning. |
A missing or invalid bearer token receives 401 auth.missing with a Bearer challenge. A valid key with insufficient permissions receives 403 auth.forbidden, identifying the configured key name, its role and the route. The optional patterns (contract,customer.moved; a bare aggregate means all its types) limit which events the key sees — on GET /events and on every webhook it owns. Keys are compared in constant time and never logged. A test holds the role table against every route in the contract, billing and accounting services.
Rotate an API credential
Keep the caller name when replacing a secret. For example, during a CRM rotation the following command adds a replacement to an existing inline configuration. It assumes that the current CRM entry uses the role and patterns shown above:
export TELCO_API_KEYS="${TELCO_API_KEYS:?existing entries required}; crm integration ${CRM_NEW:?replacement required} contract,customer"- Add the replacement entry alongside the existing entries in your deployment. Roll out the configuration to every contractd and billd replica that accepts this caller. Both secrets authenticate as
crm. - Switch clients to the replacement secret. Check a protected request such as
GET /webhookson each service. Existing subscriptions still belong tocrm, and retrying a POST with its original idempotency key returns its original response. - Remove the old entry and roll out the configuration again. A replica rejects the retired secret with
401 auth.missingonce it has restarted with the new configuration.
The same procedure works with one entry per line in TELCO_API_KEYS_FILE. Put the actual secret values in that file. The inline and file entries are validated together. Each secret must be unique. Entries sharing a name must have the same role and event patterns after shorthand expansion, sorting and deduplication. Empty entries inside a comma-separated pattern list are refused. Omitting the pattern field grants all events.
Retrying safely
On contractd and billd, a retriable business POST may carry Idempotency-Key: <1–255 visible characters>. A retry with the same key gets the first answer again, with Idempotent-Replayed: true — never a second customer, contract or credit note. Keys belong to the caller (two callers may use the same string) and to the request: the same key with another method, path or body is 422 idempotency.mismatch; a retry while the first is still running is 409 idempotency.in-progress. A 5xx answer is not kept, so it can be retried; everything else is kept 24 hours.
Webhooks
POST /webhooks, GET /webhooks, GET|DELETE /webhooks/{name}, POST /webhooks/{name}/test, GET /webhooks/{name}/deliveries, POST /webhooks/{name}/replay — an integration registers and runs its own subscriber; see Webhooks.
For resource paths, parameters and response schemas, open the service’s GET /openapi.yaml. The sales guide covers signup and quotes. The billing guide covers invoice holds, sealing and usage.
MCP
With TELCO_MCP=on, contractd and billd expose stateless read tools at /mcp on their own ports. Each uses the same service function as its REST counterpart. billd also exposes propose_credit, propose_plan_switch and propose_dispute_answer at /agent/mcp. These tools create Desk items for human review. Review a proposal
The anonymous /mcp/public endpoint exposes only quotes and receipt checks over the configured public catalog. Publish a tariff
| Service | Tools |
|---|---|
| contractd | get_customer, get_contract, get_contract_dates (the § 4 block and when a termination arriving on a day would take effect, with the rule), get_subscription |
| billd | get_bill, explain_bill (every line with its „Warum?" — quote it, never recompute it), list_bills, get_open_bill, list_price_books, quote_plan (what a plan will cost from a day) |
Problems
Errors are application/problem+json (RFC 9457) with code, detail, and rule and fix where they apply, and pointer — a JSON pointer into the request (/account/iban) — where the problem is about one part of it. Each problem's type links to its row here. They never echo personal data from the request.
| Code | Status | Meaning |
|---|---|---|
auth.missing | 401 | No token, or a wrong one |
auth.forbidden | 403 | The key's role may not do this (Keys and roles) |
request.invalid | 422 | Unknown field, wrong type, missing reference, or a value out of range |
request.too-large | 413 | Body over 64 KiB |
not-found | 404 | No such resource |
internal | 500 | Something failed that the request did not cause; the log has the detail |
idempotency.invalid | 422 | An Idempotency-Key that is not 1–255 visible ASCII characters |
idempotency.mismatch | 422 | The key was used for another request; use a new key |
idempotency.in-progress | 409 | The first request with this key is still running; retry in a moment |
webhook.url-forbidden | 422 | Not https, credentials in the URL, or a host that is not public |
webhook.exists | 409 | A webhook or configured subscriber has this name |
webhook.configured | 409 | A configured subscriber is changed in the configuration, not the API |
webhook.limit | 409 | A key owns at most 20 webhooks |
webhook.unconfigured | 503 | The service has no TELCO_WEBHOOK_KEY |
webhook.orphaned | 409 | The key that owns the webhook is not configured |
signup.conflict | 409 | The order reference was already signed up with another request; the same request again answers the first answer |
contract.term-too-long | 422 | § 56 Abs. 1 TKG |
contract.notice-too-long | 422 | § 309 Nr. 9 lit. c BGB |
contract.invalid-terms | 422 | Out of range |
contract.awaiting-approval | 409 | § 54 Abs. 3 TKG: activation before approval |
contract.state | 409 | The contract's state does not allow this |
contract.not-effective | 409 | Not an effective contract |
contract.already-terminated | 409 | A termination is already recorded |
contract.no-transparency-block | 404 | A business contract, or a term of one month or less |
contract.addon-extends-term | 409 | § 66 Abs. 3 TKG |
subscription.transition | 409 | A lifecycle step that is not allowed |
subscription.plan-overlap | 409 | The database refused an overlapping assignment |
identifier.taken | 409 | Another subscription holds this identifier in that period |
account.parent-mismatch | 422 | The parent account must belong to the same customer |
account.customer-mismatch | 422 | The billing account must belong to the customer |
account.invalid-iban | 422 | The IBAN fails its check digits or national format |
account.mandate-incomplete | 422 | A direct debit without mandate reference, signature date or IBAN |
account.no-creditor-id | 409 | The operator has no creditor id, so it cannot collect by direct debit |
letter.not-applicable | 409 | No renewal notice: business, non-renewing or terminated contract, or past the last day to cancel |
voice.delivery-pending | 503 | Retry the same batch identity and bytes after billing recovers. |
evn.preference | 422 | Record the subscriber’s choice and required declaration evidence. |
evn.timestamp | 422 | Supply an offset-aware answer time. |
evn.billing-unavailable | 503 | Restore access to the sealed invoice facts at billd and retry. |
evn.protection-unavailable | 503 | Load the confidential current-quarter list in usaged before retrying. |
evn.render | 500 | Retry the itemisation PDF and inspect the service logs if rendering continues to fail. |
bill.replay-expired | 410 | Underlying fixed-line call evidence has expired. Use the sealed invoice and its line-level explanation. |
bill.dispatch-conflict | 409 | A different dispatch receipt already exists. Check the original delivery evidence. |
voice.batch-conflict | 409 | Retry with the original batch UUID, source credential and bytes. Use a fresh UUID for a corrected export |
online.source-unavailable | 503 | Retry the grant after the authoritative contract service is reachable. |
online.entitlement | 409 | Check the active prepaid subscription, service date and prior offline activity in the month. |
online.conflict | 409 | An online report or observation already uses this identifier with different facts. Compare the original receipt. |
usage.conflict | 409 | A known usage id arrived with other content |
usage.period-closed | 409 | The record's month is already billed |
usage.unknown-subscription | 422 | No such subscription |
input.invalid | 422 | A value the core cannot read: a plan reference that is not book@version/plan, a date that is not YYYY-MM-DD |
rate.unknown-plan | 422 | The book has no such plan |
bill.unknown-book | 422 | The open bill needs a price-book version that is not loaded |
bill.mixed-prices | 422 | Gross and net books on one account |
bill.already-credited | 409 | The bill already has a credit note |
bill.not-creditable | 409 | A credit note cannot be credited |
bill.no-einvoice | 409 | A consumer bill has no e-invoice |
bill.einvoice-invalid | 422 | A credit note's e-invoice would not validate (a seal is held instead) |
document.issuer-invalid, document.payment-invalid | 422 | The document could not be built |
quote.busy | 503 | Both anonymous tariff calculation slots are busy. Retry the tool call. |
render.busy | 503 | Every typesetting slot is busy; retry |
render.failed | 500 | Typesetting failed |
agent.evidence-stale | 409 | The wallet snapshot has changed. Capture fresh evidence and verify a new answer before approval or dispatch. |
datev.selection | 422 | Supply the booking month, journal, adviser and client. Use a page size between 1 and 100. |
datev.cursor | 422 | Continue with the cursor and fiscal scope from the preceding page, or restart the list. |
datev.month | 422 | Select the current or a past month in YYYY-MM format. |
datev.unconfigured | 503 | Install an approved fiscal profile and configure the billing-close peer. |
datev.peer-unavailable | 503 | Check billing readiness, its origin and the finance read credential. |
datev.reconciliation | 409 | Check the currency, precision and source entries against the EUR journal. |
datev.stale | 409 | Journal or profile changed. Review a fresh preview. |
datev.not-found | 404 | Check the issued batch UUID and one-based file number. |
datev.pending | 409 | Resolve pending bookings or finish opening-balance reconciliation. |
datev.limit | 422 | Selected journal exceeds the supported position limit. Contact the deployment owner. |
datev.busy | 409 | A close operation is running. Retry the preview. |
datev.digest | 422 | Use the SHA-256 digest returned by the preview. |
datev.conflict | 409 | Retrieve the receipt for this UUID or issue a new reviewed command. |
datev.empty | 409 | All eligible entries are already issued or the month has no postings. |
datev.tax | 422 | Obtain adviser approval for the gross prepaid tax treatment. |
datev.mapping | 422 | Check the journal entry against the client’s approved account mappings. |
datev.control | 409 | Reconcile the mapped rows against both sides of the original posting. |
datev.format | 422 | A posted entry or date cannot be represented by the selected DATEV format. |
ledger.unavailable | 503 | The ledger cannot be read |
inbox.unauthenticated | 401 | A delivery whose signature, headers or timestamp do not verify |
inbox.source-unavailable | 503 | billd cannot read the source; deliver again later |
Events
Poll GET /events on contractd and billd, and GET /usage/events on usaged. Keep a cursor per service. Deduplicate by event ID and order by sequence within each source. See Events for payloads, filtering and signed deliveries.
Passes
Every hour, and whenever the test clock is set:
- contractd — renewals: emits the renewal notice once on its due date (§ 56 Abs. 3 TKG), and records the renewal once after the initial term ends without a termination.
- contractd — endings: ends contracts whose termination took effect, and non-renewing contracts after their term, together with their subscriptions.
- billd — seal: seals every due month of every billing account, in order (Bills).
- billd — posting: sends staged documents to accountingd, idempotently.
Each pass runs behind an advisory lock, so a second instance skips. Each change carries a dedup key, so re-running inserts nothing. Due dates are compared as "on or before today", so a missed day is caught up.
Carrier provisioning problems
An unknown carrier principal or invalid S/PRI order identifier returns carrier.binding (422). An incompatible binding, out-of-order milestone or conflicting service date returns carrier.conflict (409). An unsupported payload returns carrier.message (422). Send the operation body with media type application/xml (415 for other types).