Production-grade WebSocket patterns for Python (FastAPI/Starlette) with connection management, rooms, and message protocols
View on GitHubadelabdelgawad/fullstack-agents
fullstack-agents
plugins/fullstack-agents/skills/websocket/SKILL.md
January 25, 2026
Select agents to install to:
npx add-skill https://github.com/adelabdelgawad/fullstack-agents/blob/main/plugins/fullstack-agents/skills/websocket/SKILL.md -a claude-code --skill websocketInstallation paths:
.claude/skills/websocket/# WebSocket Skill Production-grade WebSocket patterns for real-time communication in Python applications. ## When to Use This Skill Use this skill when: - Building real-time features (chat, notifications, live updates) - Implementing bidirectional client-server communication - Creating collaborative features (multi-user editing, presence) - Building dashboards with live data feeds - Implementing game servers or real-time applications ## Core Mental Model A WebSocket connection is fundamentally different from HTTP: ``` HTTP: Request → Response → Done WebSocket: Connect → Accept → [Receive Loop] → Disconnect → Cleanup ``` The **receive loop** is unavoidable because: 1. The connection is long-lived - something must continuously listen 2. Messages arrive asynchronously from the client 3. The loop defines the connection's lifetime boundary 4. Even when frameworks abstract it, a loop exists underneath ## Architecture Overview ``` ┌─────────────────────────────────────────────────────────────┐ │ WebSocket System │ ├─────────────────────────────────────────────────────────────┤ │ │ │ ┌──────────────┐ ┌──────────────────────────────────┐ │ │ │ Client 1 │───▶│ │ │ │ └──────────────┘ │ │ │ │ │ Connection Manager │ │ │ ┌──────────────┐ │ ┌─────────────────────────────┐ │ │ │ │ Client 2 │───▶│ │ connections: Set[WebSocket] │ │ │ │ └──────────────┘ │ │ rooms: Dict[str, Set[WS]] │ │ │ │ │ └─────────────────────────────┘ │ │ │ ┌──────────────┐ │ │ │ │ │ Client N │───▶│ connect() → track │ │ │ └──────────────┘ │ disconnect() → remove │ │ │ │ broadcast() → fan-out │ │ │ │ send_to_room(