/trogonstack-nats:nats-design-subjectfrom trogonstack-nats
Designs and audits NATS channel contracts across Core NATS and JetStream, covering subjects, streams, consumers, tenancy, authorization, and migrations.
Ships in trogonstack-nats. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Design a NATS channel contract that stays understandable as the system grows. A subject is the routing key, not a declaration of transport or storage. Record delivery, acknowledgement, and ownership separately.
JetStream is not a second application subject tree. Streams bind to ordinary application subjects. The $JS subjects are the control plane and need separate permissions and management ownership.
Choose what the publisher and reader expect before choosing a subject shape. These kinds describe behavior; they are not required subject tokens:
| Kind | Typical transport | Contract |
|---|---|---|
| Request/reply | Core NATS | A caller waits for a business response or a timeout. |
| Live signal | Core NATS publish-subscribe | Delivery is best effort while subscribers are connected. |
| Durable event | JetStream | The event can be replayed and consumers acknowledge progress. |
| Durable work | JetStream | A worker pool shares a durable consumer and retries unacknowledged work. |
Do not silently fall back from Core NATS to JetStream. That changes delivery guarantees. If a durable event also needs live observers, publish it on the JetStream subject and let live Core subscribers observe it. The durable consumer remains the correctness path.
If a stream captures a subject, a Core publish can be stored without giving the publisher a persistence acknowledgement. Use the JetStream publish path when the publisher must know that the server accepted the message for storage.
Skip questions that the user already answered. Ask for the missing contract decisions:
For an existing hierarchy, audit current subjects, subscriptions, streams, consumers, and permissions before proposing replacements.
Use NATS Accounts for tenant or environment isolation when the boundary needs independent credentials, quotas, JetStream, or KV. Use a subject prefix only for an intentional shared-account surface or an exported platform view.
Keep tenant identity out of normal tenant-local subjects when the account already supplies it. Put tenant provenance into platform aggregation subjects only when the data crosses an explicit export or import boundary.
Record one logical channel before creating subjects or streams. Use the small AsyncAPI fragments for application send and receive behavior. Use the NACK JetStream resources for Kubernetes-owned streams and optional consumers. The compact record below is review metadata, not a replacement wire specification:
id: gateway.ingress.raw.github.v1
kind: durable-event
subjects:
- gateway.ingress.raw.github.v1.<event>
transport: jetstream
stream: GITHUB_PRIMARY
owner: gitops
retention: 7d
ack: explicit
For a request/reply channel:
id: gateway.health.v1.check
kind: request-reply
request_subjects:
- gateway.health.v1.check
reply_subjects:
- _INBOX.<generated-by-client>
transport: core
storage: none
owner: gateway
The request subject has no .rpc. token. Such a token is an optional local naming convention, not a NATS requirement. The channel contract states the behavior. Combine it with provisioned resources, such as NACK manifests, and observed state to show topology; do not infer transport from spelling. An application must not create a stream that GitOps or an operator already owns.
Choose tokens that identify the message and support the intended subscriptions and permissions. A stable, low-cardinality prefix helps with bounded filters. Use a kind token such as rpc or event only when it serves that design; no kind token or universal token order is required.
Examples:
orders.created.us-west.order-123
orders.shipped.us-west.order-123
gateway.ingress.raw.github.v1.pull_request
gateway.ingress.raw.slack.v1.event_callback
Publishers send concrete subjects. Only subscriptions, permissions, and stream or consumer filters use wildcards.
* matches exactly one token.> matches one or more trailing tokens and must be the final token.foo* and foo.>bar are not NATS wildcards.$SYS, $JS, $KV, $O, $SRV, and _INBOX for their protocol roles unless the design explicitly documents a boundary.Do not claim a performance effect from token order without a benchmark. Place fields where they make the intended subscription and authorization patterns obvious.
For every subject template, document the intended filters:
- kind: stream
subjects:
- gateway.ingress.raw.github.v1.>
- gateway.ingress.raw.slack.v1.>
- kind: consumer
subjects:
- gateway.ingress.raw.github.v1.pull_request
For a request, document the request subject and reply-to behavior. NATS request-reply uses a generated inbox. Responders publish to the request's reply subject; they do not invent a shared reply subject for each correlation ID.
Compare request subjects with stream filters. A request that expects a business response should not be captured by an unrelated JetStream stream. The NACK example captures ingress events and work, not gateway.health.v1.check.
For each principal, list publish and subscribe permissions separately. A broad > permission also reaches the JetStream control plane, so scope permissions to the channel and the required $JS or _INBOX subjects.
Choose a stream boundary from retention, storage, replication, throughput, ownership, and consumer topology. One stream per domain is an option, not a rule.
Select the retention policy deliberately:
limits keeps replayable history under message, byte, or age limits.workqueue removes messages after one durable consumer acknowledges them.interest keeps messages while a matching consumer has interest.Define storage, replicas, discard behavior, duplicate windows, maximum message size, and retention. Define consumers separately with durable identity, subject filters, pull or push delivery, acknowledgement policy, acknowledgement wait or backoff, maximum delivery attempts, and maximum pending acknowledgements.
Create a consumer only when a reader needs durable delivery. A durable event stream may have zero, one, or many consumers. The producer's event contract does not imply a consumer.
Keep stream subjects disjoint within an account. JetStream rejects a stream whose subjects overlap another stream in the same account. Use sourcing or mirroring to copy messages into another stream. Work-queue consumers must not have overlapping filters. Use a subject filter for routing. Do not assume arbitrary header predicates are available in JetStream consumers.
A single control-plane owner must provision each stream and consumer. In Kubernetes, NACK is the control-plane owner for these JetStream resources. The management view should show:
logical channel
-> subject or subject filter
-> Core or JetStream transport
-> stream and any provisioned consumers
-> owner
-> desired state and observed state
-> retention, backlog, and last error
In the gateway example, GitOps applies the NACK resources while the gateway publishes ingress events. The request/reply channel has no NACK resource. Show that separation in the channel contract and management view.
Before changing a subject:
Make consumers idempotent with an application key when a migration can deliver a message twice. Nats-Msg-Id deduplicates only inside one stream and its duplicate window. It does not deduplicate across the old and new streams.
Present a topology a reader can trace from application behavior to the deployed resources. Use the sections that fit the system. Include the relevant account boundary, channel contracts, subject filters, permissions, provisioning owner, and desired versus observed state. Include a migration plan when changing an existing hierarchy.
Before presenting the design:
> appears only as the final token.nats-subjects info tag. For example, use ```yaml nats-subjects and put a kind and subjects list in each YAML item. Keep the list shape even when it has one value. Ordinary examples stay untagged.node plugins/trogonstack-nats/skills/nats-design-subject/scripts/validate-subjects.mjs --root plugins/trogonstack-nats/skills/nats-design-subject
The bundled validator checks subject syntax and tagged examples. It does not verify stream overlap, permissions, responder availability, or deployed topology.
references/anti-patterns.md (opens in a new tab)references/channel-contract.md (opens in a new tab)references/gateway-asyncapi-fragments.yaml (opens in a new tab)references/jetstream.md (opens in a new tab)references/nack-jetstream.yaml (opens in a new tab)references/patterns.md (opens in a new tab)references/security.md (opens in a new tab)references/subject-fixtures.yaml (opens in a new tab)references/use-cases.md (opens in a new tab)scripts/validate-subjects.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub trogonstack/agentskills --plugin trogonstack-natsOther plugins' skills for the same job