websocket-broadcasting

A pattern for sending application events to browser clients over WebSocket connections using Socket.IO. It includes authenticated, room-based delivery so messages can be limited to an organization or user, with Redis Pub/Sub for multiple server instances.

In plain words
What is it for?
Use it to broadcast domain events to frontend applications, including multi-tenant updates across several backend instances.
Why use it?
It gives backend code a defined gateway interface and keeps event broadcasting separate from business logic. Room isolation helps prevent one organization from receiving another organization's events.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/softtor/nestjs-hexagonal/websocket-broadcasting
Any agent
npx skills add Softtor/nestjs-hexagonal --skill websocket-broadcasting
Clone the repo
git clone --depth 1 https://github.com/Softtor/nestjs-hexagonal

Made for: Claude Code, Codex.

Per session 55 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,335 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00055 $0.01335
Opus 5 $0.00028 $0.00668
Sonnet 5 $0.00011 $0.00267
Haiku 4.5 $0.00006 $0.00134

Measured 2d ago against content hash 2303f75fc037, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

websocket-broadcasting scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/websocket-broadcasting/SKILL.md · 177 lines

How it starts

The opening of the file, as written. The whole thing — 177 lines — stays where its author put it; the contents beside it link to each section on GitHub.

WebSocket Broadcasting

Broadcasts domain events to connected frontend clients via Socket.IO. Simple pattern: @EventsHandler -> enrich if needed -> WsGatewayPort.emit().


Flow

Entity.apply(event)           <- domain (queued)
  -> entity.commit()          <- handler (dispatch via EventBus)
    -> @EventsHandler         <- bridge handler
      -> (optional) repo.findById() to enrich payload
      -> gateway.emitToOrganization(orgId, event, data)
        -> Socket.IO server.to(`org:${orgId}`).emit()
          -> Redis Pub/Sub (multi-pod)
            -> connected clients

1. WsGatewayPort (hexagonal abstraction)

Define in shared/ports/ or the BC's application/ports/:

export const WS_GATEWAY_TOKEN = Symbol('WsGateway');

export interface WsGatewayPort {
  emitToOrganization(orgId: string, event: string, data: Record<string, unknown>): void;
  emitToUser(userId: string, event: string, data: Record<string, unknown>): void;
  emitGlobal(event: string, data: Record<string, unknown>): void;
}

Register in module: { provide: WS_GATEWAY_TOKEN, useExisting: AppGateway }

See references/ws-gateway-port.md for full implementation + mock for testing.


2. Bridge Handler (the only pattern you need)

For each domain event that needs to reach the frontend, create an @EventsHandler:

@EventsHandler(OrderCreatedEvent)
export class OrderCreatedBroadcastHandler implements IEventHandler<OrderCreatedEvent> {
  private readonly logger = new Logger(OrderCreatedBroadcastHandler.name);

  constructor(
    @Inject(WS_GATEWAY_TOKEN) private readonly gateway: WsGatewayPort,
    @Inject(ORDER_REPOSITORY) private readonly repo: OrderRepository.Repository,
  ) {}

  async handle(event: OrderCreatedEvent): Promise<void> {
    try {
      // Enrich if needed (optional — skip if event payload is sufficient)
      const order = await this.repo.findById(event.aggregateId);
      if (!order) return;

      this.gateway.emitToOrganization(event.organizationId, 'order:created', {
        id: order.id,
        total: order.total,
        status: order.status,
      });
    } catch (error) {
      // Log but never re-throw — don't break the event chain
      this.logger.error(`Failed to broadcast order:created`, error);
    }
  }
}

Read the full file on GitHub · 177 lines

Files

What ships with it

3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 177 lines · 55 tokens per session scan A 2303f75fc037

Subscribe to this mod's changes

websocket-broadcasting is a skill published in the GitHub repository Softtor/nestjs-hexagonal (5 stars, last pushed 22d ago), licensed MIT. It adds 55 tokens to every session and 1,335 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

design-patterns

Full-spectrum Design Patterns skill: Detect anti-patterns in existing codebases, diagnose architectural debt, propose optimal patterns (GoF, SOLID, DDD, CQRS, Microservices, Cloud), and generate production-ready boilerplate code. Optimized for Next.js, FastAPI, NestJS, Django, Express, and Go.

VoDaiLocz/Design-Patterns · 71 tokens

clean-architecture

Implement Clean Architecture combined with CQRS for scalable NestJS applications.

agency-skills/agency-skills-b · 16 tokens

new-skill

Scaffold a new brooks-lint analysis skill so it passes npm run validate and npm run evals on the first try — generates skills/{name}/SKILL.md (with the mandatory "Do NOT trigger for:" clause and a Process section citing guide step ranges) plus skills/{name}/{name}-guide.md (sequentially numbered steps), then appends…

hyhmrright/brooks-lint · 145 tokens

brooks-sweep

Full-sweep mode: runs a unified analysis across all quality dimensions — code decay, architecture, tech debt, and test quality — then applies fixes directly to the codebase. Safe changes are auto-applied; risky changes are confirmed before execution. Drawing on twelve classic engineering books. Triggers when: user…

hyhmrright/brooks-lint · 178 tokens

brooks-review

PR code review that surfaces decay risks, design smells, and maintainability issues with concrete Symptom → Source → Consequence → Remedy findings, drawing on twelve classic engineering books. Triggers when: user asks to review code, check a PR, shares a diff or pastes code asking "does this look right?" / "any issues…

hyhmrright/brooks-lint · 172 tokens

frontend-conventions

Frontend convention reference (SvelteKit / Svelte 5). Auto-injected into frontend-aware agents - not user-invocable.

fpindej/netrock · 27 tokens