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.
What you receive
Section titled “What you receive”Requests arrive from a front door on the private network:
- Tree routes: resolved node ids in the path (and in
X-Plat5-<Kind>-Id) andX-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 (whenUPSTREAM_SIGNING_KEYis set)X-Plat5-Signature.
Full header list: reference/headers.md. Services never receive slugs, Authorization, or the caller’s role or permissions.
Must do
Section titled “Must do”These three rules keep multi-tenant isolation intact:
- Stay on the private network — or verify
X-Plat5-Signature. The rewritten path andX-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 withUPSTREAM_SIGNING_KEYand your service verifiesX-Plat5-Signature(reference/headers.md). - 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.
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-- Wrong: serves another tenant's task to anyone with its idSELECT * FROM tasks WHERE id = $2;-- Right: scoped to the project the gateway authorizedSELECT * FROM tasks WHERE project_id = $1 AND id = $2;
X-Plat5-<Kind>-Idalongside the node id for roll-ups or Postgres RLS, never instead of it.) - Leave auth and access decisions to the front door. Don’t validate JWTs, parse
Authorization, implement CORS, or check roles yourself. Document whichX-Plat5-*headers your endpoints require (e.g.X-Plat5-Member-Idwhen 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).
Follow Plat5 standards for more
Section titled “Follow Plat5 standards for more”Everything below is opt-in — each gives you a concrete capability across the platform:
Audit log enrichment
Section titled “Audit log enrichment”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-NodesandX-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.
End-to-end traces and correlated logs
Section titled “End-to-end traces and correlated logs”- Log
X-Request-IDasrequest_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).
Consistent client errors and pagination
Section titled “Consistent client errors and pagination”- Follow the error envelope (
error: { type, code, message, request_id, details }, using whatevercodevalues 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.
Automatic cleanup via the lifecycle log
Section titled “Automatic cleanup via the lifecycle log”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 onkind).member.removed→ delete member-owned data (subscriptions, preferences); authored records stay.user.deleted→ delete everything keyed by thatuser_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.
Checking access outside a request
Section titled “Checking access outside a request”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.
Record-level auth with an external PDP
Section titled “Record-level auth with an external PDP”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.
Nodes with service fields
Section titled “Nodes with service fields”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
PUTfrom 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:
- Claim the public route (for example
POST /orgs,POST /orgs/{organization}/projects, orDELETE /orgs/{organization}/projects/{project}) in your service’s YAML. The gateway still handles authentication, permission checks, rate limits, and audit, and forwardsX-Plat5-User-IdorX-Plat5-<Kind>-Id+X-Plat5-Member-Id. - 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}, …) forwardingX-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 verifiedX-Plat5-*values received from the gateway. - 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 likePOST /orgsandPOST /user/invites/redeemstill land in the new tree’s audit log and carry full audit details. - Because the public path and response shape stay unchanged, consoles and API clients keep working without modification — and
plat5 routes generateskips routes already claimed by your services.