Real-time communication patterns for live updates, collaboration, and presence. Use when building chat applications, collaborative tools, live dashboards, or streaming interfaces (LLM responses, metrics). Covers SSE (server-sent events for one-way streams), WebSocket (bidirectional communication), WebRTC (peer-to-peer video/audio), CRDTs (Yjs, Automerge for conflict-free collaboration), presence patterns, offline sync, and scaling strategies. Supports Python, Rust, Go, and TypeScript.
npx skills add https://github.com/ancoleman/ai-design-components --skill implementing-realtime-sync
Implement real-time communication for live updates, collaboration, and presence awareness across applications.
Use this skill when building:
Choose the transport protocol based on communication pattern:
ONE-WAY (Server → Client only)
├─ LLM streaming, notifications, live feeds
└─ Use SSE (Server-Sent Events)
├─ Automatic reconnection (browser-native)
├─ Event IDs for resumption
└─ Simple HTTP implementation
BIDIRECTIONAL (Client ↔ Server)
├─ Chat, games, collaborative editing
└─ Use WebSocket
├─ Manual reconnection required
├─ Binary + text support
└─ Lower latency for two-way
COLLABORATIVE EDITING
├─ Multi-user documents/spreadsheets
└─ Use WebSocket + CRDT (Yjs or Automerge)
├─ CRDT handles conflict resolution
├─ WebSocket for transport
└─ Offline-first with sync
PEER-TO-PEER MEDIA
├─ Video, screen sharing, voice calls
└─ Use WebRTC
├─ WebSocket for signaling
├─ Direct P2P connection
└─ STUN/TURN for NAT traversal
| Protocol | Direction | Reconnection | Complexity | Best For |
|----------|-----------|--------------|------------|----------|
| SSE | Server → Client | Automatic | Low | Live feeds, LLM streaming |
| WebSocket | Bidirectional | Manual | Medium | Chat, games, collaboration |
| WebRTC | P2P | Complex | High | Video, screen share, voice |
Stream LLM tokens progressively to frontend (ai-chat integration).
Python (FastAPI):
from sse_starlette.sse import EventSourceResponse
@app.post("/chat/stream")
async def stream_chat(prompt: str):
async def generate():
async for chunk in llm_stream:
yield {"event": "token", "data": chunk.content}
yield {"event": "done", "data": "[DONE]"}
return EventSourceResponse(generate())
Frontend:
const es = new EventSource('/chat/stream')
es.addEventListener('token', (e) => appendToken(e.data))
Reference references/sse.md for full implementations, reconnection, and event ID resumption.
Bidirectional communication for chat applications.
Python (FastAPI):
connections: set[WebSocket] = set()
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
connections.add(websocket)
try:
while True:
data = await websocket.receive_text()
for conn in connections:
await conn.send_text(data)
except WebSocketDisconnect:
connections.remove(websocket)
Reference references/websockets.md for multi-language examples, authentication, heartbeats, and scaling.
Conflict-free multi-user editing using Yjs.
TypeScript (Yjs):
import * as Y from 'yjs'
import { WebsocketProvider } from 'y-websocket'
const doc = new Y.Doc()
const provider = new WebsocketProvider('ws://localhost:1234', 'doc-id', doc)
const ytext = doc.getText('content')
ytext.observe(event => console.log('Changes:', event.changes))
ytext.insert(0, 'Hello collaborative world!')
Reference references/crdts.md for conflict resolution, Yjs vs Automerge, and advanced patterns.
Track online users, cursor positions, and typing indicators.
Yjs Awareness API:
const awareness = provider.awareness
awareness.setLocalState({ user: { name: 'Alice' }, cursor: { x: 100, y: 200 } })
awareness.on('change', () => {
awareness.getStates().forEach((state, clientId) => {
renderCursor(state.cursor, state.user)
})
})
Reference references/presence-patterns.md for cursor tracking, typing indicators, and online status.
Queue mutations locally and sync when connection restored.
TypeScript (Yjs + IndexedDB):
import { IndexeddbPersistence } from 'y-indexeddb'
import { WebsocketProvider } from 'y-websocket'
const doc = new Y.Doc()
const indexeddbProvider = new IndexeddbPersistence('my-doc', doc)
const wsProvider = new WebsocketProvider('wss://api.example.com/sync', 'my-doc', doc)
wsProvider.on('status', (e) => {
console.log(e.status === 'connected' ? 'Online' : 'Offline')
})
Reference references/offline-sync.md for conflict resolution and sync strategies.
WebSocket:
websockets 13.x - AsyncIO-based, production-readyFastAPI WebSocket - Built-in, dependency injectionFlask-SocketIO - Socket.IO protocol with fallbacksSSE:
sse-starlette - FastAPI/Starlette, async, generator-basedFlask-SSE - Redis backend for pub/subWebSocket:
tokio-tungstenite 0.23 - Tokio integration, production-readyaxum WebSocket - Built-in extractors, tower middlewareSSE:
axum SSE - Native support, async streamsWebSocket:
gorilla/websocket - Battle-tested, compression supportnhooyr/websocket - Modern API, context supportSSE:
net/http (native) - Flusher interface, no dependenciesWebSocket:
ws - Native WebSocket server, lightweightSocket.io 4.x - Auto-reconnect, fallbacks, roomsHono WebSocket - Edge runtime (Cloudflare Workers, Deno)SSE:
EventSource (native) - Browser-native, automatic retryhttp (native) - Server-side, no dependenciesCRDT:
Yjs - Mature, TypeScript/Rust, rich text editingAutomerge - Rust/JS, JSON-like data, time-travelSSE: Browser's EventSource handles reconnection automatically with exponential backoff.
WebSocket: Implement manual exponential backoff with jitter to prevent thundering herd.
Reference references/sse.md and references/websockets.md for complete implementation patterns.
Authentication: Use cookie-based (same-origin) or token in Sec-WebSocket-Protocol header.
Rate Limiting: Implement per-user message throttling with sliding window.
Reference references/websockets.md for authentication and rate limiting implementations.
For horizontal scaling, use Redis pub/sub to broadcast messages across multiple backend servers.
Reference references/websockets.md for complete Redis scaling implementation.
SSE for LLM Streaming (ai-chat):
useEffect(() => {
const es = new EventSource(`/api/chat/stream?prompt=${prompt}`)
es.addEventListener('token', (e) => setContent(prev => prev + e.data))
return () => es.close()
}, [prompt])
WebSocket for Live Metrics (dashboards):
useEffect(() => {
const ws = new WebSocket('ws://localhost:8000/metrics')
ws.onmessage = (e) => setMetrics(JSON.parse(e.data))
return () => ws.close()
}, [])
Yjs for Collaborative Tables:
useEffect(() => {
const doc = new Y.Doc()
const provider = new WebsocketProvider('ws://localhost:1234', docId, doc)
const yarray = doc.getArray('rows')
yarray.observe(() => setRows(yarray.toArray()))
return () => provider.destroy()
}, [docId])
For detailed implementation patterns, consult:
references/sse.md - SSE protocol, reconnection, event IDsreferences/websockets.md - WebSocket auth, heartbeats, scalingreferences/crdts.md - Yjs vs Automerge, conflict resolutionreferences/presence-patterns.md - Cursor tracking, typing indicatorsreferences/offline-sync.md - Mobile patterns, conflict strategiesWorking implementations available in:
examples/llm-streaming-sse/ - FastAPI SSE for LLM streaming (RUNNABLE)examples/chat-websocket/ - Python FastAPI + TypeScript chatexamples/collaborative-yjs/ - Yjs collaborative editorUse scripts to validate implementations:
scripts/test_websocket_connection.py - WebSocket connection testingCreating interactive data visualisations using d3.js. This skill should be used when creating custom charts, graphs, network diagrams, geographic visualisations, or any complex SVG-based data visualisation that requires fine-grained control over visual elements, transitions, or interactions. Use this for bespoke visualisations beyond standard charting libraries, whether in React, Vue, Svelte, vanilla JavaScript, or any other environment.
Comprehensive Python library for astronomy and astrophysics. This skill should be used when working with astronomical data including celestial coordinates, physical units, FITS files, cosmological calculations, time systems, tables, world coordinate systems (WCS), and astronomical data analysis. Use when tasks involve coordinate transformations, unit conversions, FITS file manipulation, cosmological distance calculations, time scale conversions, or astronomical data processing.
Convert laboratory instrument output files (PDF, CSV, Excel, TXT) to Allotrope Simple Model (ASM) JSON format or flattened 2D CSV. Use this skill when scientists need to standardize instrument data for LIMS systems, data lakes, or downstream analysis. Supports auto-detection of instrument types. Outputs include full ASM JSON, flattened CSV for easy import, and exportable Python code for data engineers. Common triggers include converting instrument files, standardizing lab data, preparing data for upload to LIMS/ELN systems, or generating parser code for production pipelines.
Quantum mechanics simulations and analysis using QuTiP (Quantum Toolbox in Python). Use when working with quantum systems including: (1) quantum states (kets, bras, density matrices), (2) quantum operators and gates, (3) time evolution and dynamics (Schrödinger, master equations, Monte Carlo), (4) open quantum systems with dissipation, (5) quantum measurements and entanglement, (6) visualization (Bloch sphere, Wigner functions), (7) steady states and correlation functions, or (8) advanced methods (Floquet theory, HEOM, stochastic solvers). Handles both closed and open quantum systems across various domains including quantum optics, quantum computing, and condensed matter physics.
Retrieve and display GitHub Copilot usage metrics for organizations and enterprises using the GitHub CLI and REST API.
Socratic mentoring for junior developers and AI newcomers. Guides through questions, never answers. Triggers: "help me understand", "explain this code", "I''m stuck", "Im stuck", "I''m confused", "Im confused", "I don''t understand", "I dont understand", "can you teach me", "teach me", "mentor me", "guide me", "what does this error mean", "why doesn''t this work", "why does not this work", "I''m a beginner", "Im a beginner", "I''m learning", "Im learning", "I''m new to this", "Im new to this", "walk me through", "how does this work", "what''s wrong with my code", "what''s wrong", "can you break this down", "ELI5", "step by step", "where do I start", "what am I missing", "newbie here", "junior dev", "first time using", "how do I", "what is", "is this right", "not sure", "need help", "struggling", "show me", "help me debug", "best practice", "too complex", "overwhelmed", "lost", "debug this", "/socratic", "/hint", "/concept", "/pseudocode". Progressive clue systems, teaching techniques, and success metrics.
Core Python library for astronomy and astrophysics workflows that need Astropy APIs, including units/quantities, coordinates, FITS I/O, tables, time systems, WCS, and cosmology. Use when implementing or debugging astronomical data analysis code with Astropy.
High-performance DataFrame library for Python ETL, analytics, and pandas migration. Use for expression-based data manipulation with lazy query optimization, parallel execution, streaming out-of-core processing, Arrow interoperability, and optional GPU execution.
Take ancoleman/implementing-realtime-sync from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.