Skip to content

Write a service

A service behind Plat5 is a plain HTTP server in any language. This guide separates the few rules required for security and isolation from the optional Plat5 standards you can follow for richer platform capabilities.

Requests arrive from a front door on the private network:

  • Tree routes: resolved node ids in the path (and in X-Plat5-<Kind>-Id) and X-Plat5-Member-Id.
  • User routes: the caller’s user id in the path (and in X-Plat5-User-Id).
  • Every route: X-Request-ID, traceparent, and (when UPSTREAM_SIGNING_KEY is set) X-Plat5-Signature.

Full header list: reference/headers.md. Services never receive slugs, Authorization, or the caller’s role or permissions.

These three rules keep multi-tenant isolation intact:

  1. Stay on the private network — or verify X-Plat5-Signature. The rewritten path and X-Plat5-* headers are authentic only if nothing except your front doors (Plat5’s gateway, an operator plane, etc.) can reach the service, or the gateway signs requests with UPSTREAM_SIGNING_KEY and your service verifies X-Plat5-Signature (reference/headers.md).
  2. Scope every query by the node id from the request. Never look up, update, or delete a record by its record id alone — the record id comes from the client, while the node id comes from the front door.
    -- Wrong: serves another tenant's task to anyone with its id
    SELECT * FROM tasks WHERE id = $2;
    -- Right: scoped to the project the gateway authorized
    SELECT * FROM tasks WHERE project_id = $1 AND id = $2;
    A record in another node returns the same 404 as one that doesn’t exist. Inserts take the node id from the request, never from the body. (You may also store ancestor ids from X-Plat5-<Kind>-Id alongside the node id for roll-ups or Postgres RLS, never instead of it.)
  3. Leave auth and access decisions to the front door. Don’t validate JWTs, parse Authorization, implement CORS, or check roles yourself. Document which X-Plat5-* headers your endpoints require (e.g. X-Plat5-Member-Id when recording an author) and answer 400 if a required header is missing.

Key tree data by node id (and X-Plat5-Member-Id when logic needs an author or owner). Key per-user data that is the same across every tree by X-Plat5-User-Id on user routes (where a field goes).

Everything below is opt-in — each gives you a concrete capability across the platform:

Set optional response headers on audited routes (concepts/audit.md) to get richer customer audit logs:

  • X-Plat5-Audit-Details (a JSON object, e.g. { "status": { "from": "open", "to": "done" } }) → shows before/after diffs in the audit log.
  • X-Plat5-Audit-Created → records the created resource’s id on the audit event.
  • X-Plat5-Audit-Nodes and X-Plat5-Audit-Member (on user routes) → also publishes the event into the affected tree’s audit logs.

The gateway strips all X-Plat5-Audit-* headers before responding to the client. Never put secrets in details.

  • Log X-Request-ID as request_id → tie a single request across gateway logs, audit events, error responses, and your service logs.
  • Propagate traceparent (via any OpenTelemetry SDK) → get one distributed trace from the edge through the gateway into your handlers and database (reference/telemetry.md).
  • Follow the error envelope (error: { type, code, message, request_id, details }, using whatever code values fit your domain) → clients need only one error parser across gateway, identity, audit, and your APIs.
  • Follow cursor pagination (limit, starting_after, has_more) → one list pagination pattern across your whole API.

Follow identity’s transactional lifecycle log (GET /internal/events, reference/api/internal.md) to clean up your own tables when data ends (concepts/lifecycle.md):

  • node.purged → delete the node’s data (matching on kind).
  • member.removed → delete member-owned data (subscriptions, preferences); authored records stay.
  • user.deleted → delete everything keyed by that user_id.

Keep your cursor in the same database as the data it cleans up, make handlers idempotent, and restart from the first event on 409 CURSOR_AHEAD.

The gateway checks access for the caller during a request. When your service acts outside a request (notifications, digests, scheduled jobs, webhooks) or on behalf of another member (assignees, mentions), ask identity’s internal AuthZEN endpoint (reference/api/internal.md) when the work runs:

POST {IDENTITY_INTERNAL_URL}/access/v1/evaluations
{
"resource": { "type": "project", "id": "<project id>" },
"action": { "name": "<permission from your config>" },
"evaluations": [
{ "subject": { "type": "member", "id": "<member id>" } },
{ "subject": { "type": "member", "id": "<another member id>" } }
]
}
→ { "evaluations": [ { "decision": true }, { "decision": false } ] }

Read permission names from your service’s own config rather than hardcoding them, and fail closed on any non-200 response (don’t send; retry later).

For cross-node queries inside a broader scope (for example, listing a member’s tasks across every project they can read in an org), ask identity’s resource search endpoint (reference/api/internal.md):

POST {IDENTITY_INTERNAL_URL}/access/v1/search/resource
{
"subject": { "type": "member", "id": "<member id>" },
"action": { "name": "<permission from your config>" },
"resource": { "type": "project" },
"scope": { "node_id": "<organization id>" }
}
→ { "all": true, "results": [] }
// or { "all": false, "results": [ { "type": "project", "id": "<project id>" } ] }

When all is true, the member holds the permission on every live node of that kind under scope; otherwise filter by the returned results ids.

If your deployment configures a top-level external AuthZEN 1.0 authorizer and your routes add resource: { type, id } (authorizer), the gateway enforces record-level decisions before requests reach your handler. Leave AUTHORIZER_CACHE_TTL and AUTHORIZER_NEGATIVE_CACHE_TTL at 0s (the default) when share/unshare writes must take effect immediately, or use short TTLs (2s–5s) for high-traffic read routes. See the Topaz playbook.

Identity stores a node’s id, kind, parent_id, slug, display_name, and status (plus root-only sub-resources like security-policy and rate-limit-tier). Any product-specific fields about a node (like a project’s region or plan settings) live in your service, keyed by the node id:

  • Identity creates the node through its route.
  • Your service treats a node with no row yet as having defaults, creating its row lazily on first read/write or via a follow-up PUT from the console.

Wrapping identity routes for custom orchestration

Section titled “Wrapping identity routes for custom orchestration”

Identity’s public routes live in services/identity.yml like any other service. When a lifecycle mutation needs synchronous business logic — such as checking seat or project limits, refusing to delete a project that still has active resources, creating default child nodes, or writing bootstrap relations to an external PDP before returning 201 — the expected pattern is to claim that (method, path) in your own service file (services/api.yml) and call identity’s service API (http://identity:3000/…) from your handler:

  1. Claim the public route (for example POST /orgs, POST /orgs/{organization}/projects, or DELETE /orgs/{organization}/projects/{project}) in your service’s YAML. The gateway still handles authentication, permission checks, rate limits, and audit, and forwards X-Plat5-User-Id or X-Plat5-<Kind>-Id + X-Plat5-Member-Id.
  2. In your handler, run your validation or checks, call identity’s service API (POST /roots/organization, POST /nodes/{org_id}/children/project, DELETE /nodes/{id}, …) forwarding X-Plat5-User-Id / X-Plat5-Member-Id, perform any synchronous follow-up work (seeding DB rows, writing PDP tuples), and return the response. Remember that identity’s service API trusts its front door on the private network: only pass verified X-Plat5-* values received from the gateway.
  3. Forward any X-Plat5-Audit-* response headers (X-Plat5-Audit-Details, X-Plat5-Audit-Created, X-Plat5-Audit-Nodes, X-Plat5-Audit-Member) returned by identity back to the gateway so user routes like POST /orgs and POST /user/invites/redeem still land in the new tree’s audit log and carry full audit details.
  4. Because the public path and response shape stay unchanged, consoles and API clients keep working without modification — and plat5 routes generate skips routes already claimed by your services.