Skip to content

Architecture

tlm-cli is a command-line front-end for the ToloMEO Manager platform that talks to several backend services, each responsible for a distinct domain, through one shared session built from the tlm-cloud-sdk library.

Each Backend Service Has Its Own Client

PMS — Product Management System

The PMS is the manufacturing record of truth. It holds:

  • Parts and part families
  • Devices (serial numbers, batch IDs, production data)
  • Customers (with tenant IDs)
  • Public and internal events
  • Provisioning records (ConnHex IDs)

tlm-cli talks to the PMS via a JSON:API interface using the PMSClient class. All tlm-cli pms commands route through this client.

Base URL: https://apis.<instance>/manufacturing

FM — Fleet Manager

The FM tracks deployed devices that have been claimed from the PMS. It holds:

  • Claimed devices (serial numbers, names)
  • Device status (firmware version, last seen, connectivity state)

tlm-cli uses the FMClient class for JSON:API access, and a separate ClaimClient for the ownership (claiming) REST endpoint.

All tlm-cli fm commands route through these clients.

Base URL: https://apis.<instance>/resources

EM — Embedded Manager

The EM builds firmware for IoT models through GitLab pipelines. It holds:

  • Projects (firmware ↔ GitLab repository, GitLab connection, storage bucket, board farm slot)
  • Builds (pipeline runs with ref, version, status and timings)

tlm-cli uses the EMClient class for JSON:API access. EM resources are served by the same resource server as the FM and share its session through ResourcesApiModel.

All tlm-cli em commands route through this client.

Base URL: https://apis.<instance>/resources

ToloMEO Manager (REST)

The ToloMEO Manager is the platform-level REST API. It handles:

  • Customer creation and updates
  • User and team management
  • Permission management
  • Device model assignments
  • Bulk device provisioning and unprovisioning

All tlm-cli admin commands and the provisioning commands use this client.

Base URL: https://apis.<instance>/tolomeo

IoT API

The IoT API manages firmware models, firmware releases, and device things — the platform-side device identity that includes the init key. It is accessed via a plain REST client.

Used by:

  • tlm-cli pms models — list and show firmware models and releases
  • tlm-cli pms devices set-model and tlm-cli pms parts set-model — resolve model names to IDs
  • Provisioning — retrieve the init key for writing agent.env

Base URL: https://apis.<instance>/iot

All Services Share One Session

All services share the same session, authenticated via Ory Kratos (the account service at https://accounts.<instance>). On the first request, the KratosTokenProvider exchanges the credentials from the configuration file for a session token. The CLI caches the token in ~/.tlm-cli/token.json with a FileTokenStorage, one entry per instance and user, and reuses it on later calls. Authentication happens only when no valid token is cached.

The SDK Takes All Its Configuration from the Caller

On startup, tlm-cli searches for .config.toml in:

  1. Current working directory
  2. ~/.config/tlm-cli/
  3. /etc/tlm-cli/

The file is read once and cached in the CLI's ConfigRegistry, which also builds the one CloudSession of the run. The instance hostname from [application] is used to derive all API base URLs.

These paths belong to the CLI. The library, tlm-cloud-sdk, searches for no file and keeps no global configuration: whoever uses it (the CLI, or an application such as the ToloMEO provisioner) builds a CloudSession from values it passes in, including where the token is kept.

Two Packages Split the Library from the Command

The repository is a uv workspace with two packages, versioned and released together:

packages/
├── tlm-cloud-sdk/               # the library — runtime deps: httpx2, jsonapi-requests, pydantic[email], requests
│   └── tlm_cloud_sdk/
│       ├── session.py           # CloudSession — instance + token provider; every client is built from one
│       ├── config/              # AppConfig Pydantic model ([application] + [auth]) and TOML loading of a given file
│       ├── auth/                # KratosTokenProvider, TokenStorage (File, Memory), PMSApi / ResourceApi providers
│       ├── http/                # AuthenticatedClient, ServiceClient(session) and the bearer auth (httpx2 + requests)
│       ├── core/                # JSON:API base model, bind_session, BaseApiInterface, BaseAttributeHandler
│       ├── builders/            # FilterBuilder and ResourceQueryBuilder for JSON:API query parameters
│       ├── manufacturing/       # PMS: PMSClient, its records, JSON:API resources, models, provisioning
│       ├── fleet/               # FM: FMClient and its resources
│       ├── embedded/            # EM: EMClient, EMApiClient and their resources
│       ├── iot/  iam/  claim/   # REST clients of the IoT, IAM and claim services
│       ├── trials/              # Trial tenant orchestration
│       └── tolomeo/  cybersec/  # Pydantic models of REST responses
│
└── tlm-cloud-cli/               # the `tlm-cli` command — adds typer, rich and click
    ├── tlm_cloud_cli/
    │   ├── main.py              # Entry point
    │   ├── app.py               # Root app: registers admin, cs, em, fm, pms sub-apps
    │   ├── config.py            # Config search paths, token file path, ConfigRegistry and the run's CloudSession
    │   ├── context.py           # Builds the API clients from the run's session
    │   ├── interactive.py       # Interactive editors and paginator
    │   ├── output.py            # Rich-based output formatting helpers
    │   └── admin/ pms/ fm/ cs/ em/   # tlm-cli sub-commands

Key Patterns

Session — every client is built from a CloudSession: PMSClient(session), IoTClient(session), and so on. The session holds the instance and a token provider; tokens are fetched when first needed, renewed when they expire, and fetched once at a time even across threads. In the CLI, ConfigRegistry.initialize() runs once in the root Typer callback and ConfigRegistry.session() builds the session from that config, with the token in ~/.tlm-cli/token.json; tlm_cloud_cli/context.py builds the clients from it.

JSON:API interface layer — BaseApiInterface (in core/interfaces/) provides a uniform get / get_list / exists / set_attributes API over any JSON:API resource. The manufacturing/ and fleet/ packages subclass these abstractions directly with domain-specific resource classes. jsonapi-requests keeps the session on the model classes, so it is process-wide: domains served by the same server share one base model (PMSApiModel for /manufacturing, ResourcesApiModel for /resources), and PMSClient(session) / FMClient(session) / EMClient(session) bind the session of their server for the whole process. Using a model before a client has bound one raises a clear error.

Provisioning as orchestration — DeviceProvisioner (in manufacturing/provisioning/) is the one place where multiple clients converge. A single provision() call touches three backends: PMS (JSON:API) to create the device record, ToloMEO Manager (REST) for bulk provisioning, and the IoT API (REST) to retrieve the init key for the agent.env file.

See also