websockets-realtime
Skill1 starsChanged 11 months agoMITView on GitHub
WebSocket and real-time communication patterns. Auto-activates when implementing chat, notifications, or live updates.
- Reads credentials
Files
WebSockets & Real-time
Socket.IO Server
import { Server } from 'socket.io';
const io = new Server(server, {
cors: {
origin: process.env.CLIENT_URL,
methods: ['GET', 'POST']
}
});
// Authentication middleware
io.use((socket, next) => {
const token = socket.handshake.auth.token;
try {
const user = verifyToken(token);
socket.data.user = user;
next();
} catch {
next(new Error('Authentication failed'));
}
});
// Connection handling
io.on('connection', (socket) => {
console.log(`User connected: ${socket.data.user.id}`);
// Join user's room
socket.join(`user:${socket.data.user.id}`);
// Handle events
socket.on('message', async (data) => {
const message = await saveMessage(data);
io.to(data.roomId).emit('message', message);
});
socket.on('disconnect', () => {
console.log(`User disconnected: ${socket.data.user.id}`);
});
});Socket.IO Client
import { io } from 'socket.io-client';
const socket = io(SERVER_URL, {
auth: { token: getAuthToken() },
reconnection: true,
reconnectionAttempts: 5
});
socket.on('connect', () => {
console.log('Connected');
});
socket.on('message', (message) => {
addMessageToUI(message);
});
// Send message
socket.emit('message', {
roomId: 'room-123',
content: 'Hello!'
});Room Patterns
// Join room
socket.join('room:123');
// Leave room
socket.leave('room:123');
// Broadcast to room
io.to('room:123').emit('event', data);
// Broadcast to all except sender
socket.to('room:123').emit('event', data);
// Private message
io.to(`user:${userId}`).emit('private', message);Scaling with Redis
import { createAdapter } from '@socket.io/redis-adapter';
import { createClient } from 'redis';
const pubClient = createClient({ url: REDIS_URL });
const subClient = pubClient.duplicate();
io.adapter(createAdapter(pubClient, subClient));Use Cases
| Feature | Implementation |
| Chat | Rooms + messages |
| Notifications | User rooms + emit |
| Live updates | Broadcast on DB change |
| Presence | Track connections |
| Typing indicators | Debounced events |
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- cohen-liel/hivemind★ 108same name
- travisjneuman/.claude★ 106same name
- hallucinaut/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-integrationSkill
- authenticationSkill
- caching-strategiesSkill
- ci-cd-pipelinesSkill
- clean-architectureSkill
- code-patternsSkill
- database-designSkill
- docker-composeSkill
- error-handlingSkill
- frontend-designSkill
- git-workflowSkill
- logging-monitoringSkill
- microservicesSkill
- performance-tuningSkill
- project-setupSkill
- security-best-practicesSkill
- systematic-debuggingSkill
- tddSkill
- testing-strategiesSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

