A real-time multi-room chat application built with a Python WebSocket backend and a vanilla JS frontend. No frameworks, no dependencies beyond the websockets library.
- Real-time messaging over WebSockets — no polling
- Multi-room support — join any named room, isolated from others
- Typing indicators with debounce so they don't spam
- Dark / light theme toggle, persisted in localStorage
- Connection status dot with live feedback and a reconnect button on drop
- Character counter (500 char limit enforced on both client and server)
- Rate limiting — max 5 messages per second per client, handled server-side
- Particle canvas on the welcome screen with mouse repulsion
- Browser history API — back/forward navigation works between screens
| Layer | Tech |
|---|---|
| Backend | Python 3, asyncio, websockets |
| Frontend | Vanilla JS, HTML, CSS (no frameworks) |
| Transport | WebSocket (ws://) |
Requirements: Python 3.10+
# Install the dependency
pip install websockets
# Start the server
python server.pyThen open index.html in your browser. That's it.
By default the server runs on
ws://localhost:8765. To change it, editWS_URLat the top of the<script>block inindex.html, andHOST/PORTinserver.py.
Browser (index.html)
│
│ WebSocket (ws://localhost:8765)
▼
server.py
├── rooms{} # dict of room_name → set of (websocket, username)
├── client_activity # per-client deque of timestamps for rate limiting
└── broadcast() # fans out a message to all clients in a room
Each client sends a join message on connect with a username and room name. After that, the server routes chat and typing messages to everyone else in the same room. Disconnects are caught in a finally block so the room always gets a leave notification.
├── index.html # entire frontend — UI, WebSocket logic, canvas animation
├── server.py # async WebSocket server
└── favicon.svg
MIT