# abhinav5568/ws-chat-room architecture

> Architecture diagram of the GitHub repository abhinav5568/ws-chat-room, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhinav5568/ws-chat-room
- Repository: https://github.com/abhinav5568/ws-chat-room

## Overview

This repository implements anonymous, one-to-one chat with random or interest-based matchmaking, backed by a WebSocket server and Redis. The main workflow is: a client connects, joins a queue, receives a match and session key, exchanges messages and typing status, then leaves or disconnects. Two frontend implementations are present: an older React interface and a newer Svelte app with routed pages and shared WebSocket state. The graph shows documented calls and imports; the README is empty, and some frontend and matchmaking internals were not sampled.

Main entry points: [`frontend-v2/src/App.svelte`](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/App.svelte) (Svelte app and routes), [`backend/services/sessionService.js`](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/sessionService.js) (Session and message relay), [`backend/handlers/connectionHandler.js`](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/handlers/connectionHandler.js) (Connection lifecycle), [`backend/services/queueService.js`](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/queueService.js) (Queue coordination)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Client apps"]
  node_react_app["React chat UI<br/>[App.jsx]"]
  node_svelte_app["Svelte app and routes<br/>[App.svelte]"]
  node_home["Home page<br/>[Home.svelte]"]
  node_chat["Chat page<br/>[Chat.svelte]"]
  node_navbar["Navigation<br/>[Navbar.svelte]"]
  node_footer["Footer<br/>[Footer.svelte]"]
  node_about["About page<br/>[About.svelte]"]
  node_not_found["Not-found page<br/>[NotFound.svelte]"]
  node_ws_store["WebSocket state"]
end

subgraph group_server["WebSocket server"]
  node_ws_server["WebSocket server<br/>[server.js]"]
  node_connection["Connection lifecycle"]
  node_message_handler["Message dispatch<br/>[messageHandler.js]"]
end

subgraph group_matching["Matchmaking"]
  node_queue["Queue coordination<br/>[queueService.js]"]
  node_interest_match["Interest matching<br/>[interestMatcher.js]"]
  node_random_match["Random matching<br/>[randomMatcher.js]"]
  node_embedding_pipe["Embedding provider<br/>[pipeProvider.js]"]
end

subgraph group_sessions["Chat sessions"]
  node_session["Session and message relay<br/>[sessionService.js]"]
  node_rate_limit["Message rate limiting"]
end

subgraph group_state["State and services"]
  node_user_map["Live connection map<br/>[userMap.js]"]
  node_redis_config["Redis client<br/>[redis.js]"]
  node_redis[("Redis")]
end

node_visitor(("Chat visitor"))

node_visitor -->|"uses"| node_react_app
node_visitor -->|"uses"| node_svelte_app
node_svelte_app -->|"routes to"| node_home
node_svelte_app -->|"routes to"| node_chat
node_svelte_app -->|"routes to"| node_not_found
node_svelte_app -->|"renders"| node_navbar
node_svelte_app -->|"renders"| node_footer
node_svelte_app -->|"connects through"| node_ws_store
node_chat -->|"uses"| node_ws_store
node_navbar -->|"uses"| node_ws_store
node_svelte_app -->|"connects to"| node_ws_server
node_react_app -->|"connects to"| node_ws_server
node_ws_server -->|"connects"| node_redis_config
node_ws_server -->|"dispatches connection"| node_connection
node_connection -->|"dispatches messages"| node_message_handler
node_connection -->|"cleans session"| node_session
node_connection -->|"cleans queue"| node_queue
node_connection -->|"cleans interest data"| node_redis
node_connection -->|"tracks sockets"| node_user_map
node_message_handler -->|"joins or leaves"| node_queue
node_message_handler -->|"relays chat events"| node_session
node_message_handler -->|"checks message rate"| node_rate_limit
node_queue -->|"starts interest match"| node_interest_match
node_queue -->|"starts random match"| node_random_match
node_queue -->|"creates session"| node_session
node_queue -->|"stores queue state"| node_redis
node_interest_match -->|"gets embeddings"| node_embedding_pipe
node_interest_match -->|"matches candidates"| node_redis
node_interest_match -->|"creates session"| node_session
node_random_match -->|"uses queue state"| node_redis
node_random_match -->|"creates session"| node_session
node_session -->|"reads and writes sessions"| node_redis
node_session -->|"notifies sockets"| node_user_map
node_rate_limit -->|"tracks message counts"| node_redis
node_redis_config -->|"connects client"| node_redis

click node_react_app "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend/src/App.jsx"
click node_svelte_app "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/App.svelte"
click node_home "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/Home.svelte"
click node_chat "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/Chat.svelte"
click node_navbar "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/components/Navbar.svelte"
click node_footer "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/components/Footer.svelte"
click node_about "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/About.svelte"
click node_not_found "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/NotFound.svelte"
click node_ws_store "https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/store/websocket.svelte.js"
click node_ws_server "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/server.js"
click node_connection "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/handlers/connectionHandler.js"
click node_message_handler "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/handlers/messageHandler.js"
click node_queue "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/queueService.js"
click node_interest_match "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/matchmaking/interestMatcher.js"
click node_random_match "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/matchmaking/randomMatcher.js"
click node_embedding_pipe "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/pipeProvider.js"
click node_session "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/sessionService.js"
click node_rate_limit "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/rateLimitService.js"
click node_user_map "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/state/userMap.js"
click node_redis_config "https://github.com/abhinav5568/ws-chat-room/blob/main/backend/config/redis.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_react_app,node_svelte_app,node_home,node_chat,node_navbar,node_footer,node_about,node_not_found,node_ws_store toneBlue
class node_ws_server,node_connection,node_message_handler toneAmber
class node_queue,node_interest_match,node_random_match,node_embedding_pipe toneMint
class node_session,node_rate_limit toneRose
class node_user_map,node_redis_config,node_redis,node_visitor toneIndigo
```

## Components

### Client apps

- [React chat UI](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Svelte app and routes](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/App.svelte): `frontend-v2/src/App.svelte`
- [Home page](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/Home.svelte): `frontend-v2/src/pages/Home.svelte`
- [Chat page](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/Chat.svelte): `frontend-v2/src/pages/Chat.svelte`
- [Navigation](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/components/Navbar.svelte): `frontend-v2/src/components/Navbar.svelte`
- [Footer](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/components/Footer.svelte): `frontend-v2/src/components/Footer.svelte`
- [About page](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/About.svelte): `frontend-v2/src/pages/About.svelte`
- [Not-found page](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/pages/NotFound.svelte): `frontend-v2/src/pages/NotFound.svelte`
- [WebSocket state](https://github.com/abhinav5568/ws-chat-room/blob/main/frontend-v2/src/store/websocket.svelte.js): `frontend-v2/src/store/websocket.svelte.js`

### WebSocket server

- [WebSocket server](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/server.js): `backend/server.js`
- [Connection lifecycle](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/handlers/connectionHandler.js): `backend/handlers/connectionHandler.js`
- [Message dispatch](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/handlers/messageHandler.js): `backend/handlers/messageHandler.js`

### Matchmaking

- [Queue coordination](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/queueService.js): `backend/services/queueService.js`
- [Interest matching](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/matchmaking/interestMatcher.js): `backend/services/matchmaking/interestMatcher.js`
- [Random matching](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/matchmaking/randomMatcher.js): `backend/services/matchmaking/randomMatcher.js`
- [Embedding provider](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/pipeProvider.js): `backend/services/pipeProvider.js`

### Chat sessions

- [Session and message relay](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/sessionService.js): `backend/services/sessionService.js`
- [Message rate limiting](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/services/rateLimitService.js): `backend/services/rateLimitService.js`

### State and services

- [Live connection map](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/state/userMap.js): `backend/state/userMap.js`
- [Redis client](https://github.com/abhinav5568/ws-chat-room/blob/main/backend/config/redis.js): `backend/config/redis.js`
- **Redis**

### Other components

- **Chat visitor**

## Connections

- Chat visitor → React chat UI: uses (evidence: `frontend/src/App.jsx`)
- Chat visitor → Svelte app and routes: uses (evidence: `frontend-v2/src/App.svelte`)
- Svelte app and routes → Home page: routes to (evidence: `frontend-v2/src/App.svelte`)
- Svelte app and routes → Chat page: routes to (evidence: `frontend-v2/src/App.svelte`)
- Svelte app and routes → Not-found page: routes to (evidence: `frontend-v2/src/App.svelte`)
- Svelte app and routes → Navigation: renders (evidence: `frontend-v2/src/App.svelte`)
- Svelte app and routes → Footer: renders (evidence: `frontend-v2/src/App.svelte`)
- Svelte app and routes → WebSocket state: connects through (evidence: `frontend-v2/src/App.svelte`)
- Chat page → WebSocket state: uses (evidence: `frontend-v2/src/pages/Chat.svelte`)
- Navigation → WebSocket state: uses (evidence: `frontend-v2/src/components/Navbar.svelte`)
- Svelte app and routes → WebSocket server: connects to (evidence: `frontend-v2/src/App.svelte`)
- React chat UI → WebSocket server: connects to (evidence: `frontend/src/App.jsx`)
- WebSocket server → Redis client: connects (evidence: `backend/server.js`)
- WebSocket server → Connection lifecycle: dispatches connection (evidence: `backend/server.js`)
- Connection lifecycle → Message dispatch: dispatches messages (evidence: `backend/handlers/connectionHandler.js`)
- Connection lifecycle → Session and message relay: cleans session (evidence: `backend/handlers/connectionHandler.js`)
- Connection lifecycle → Queue coordination: cleans queue (evidence: `backend/handlers/connectionHandler.js`)
- Connection lifecycle → Redis: cleans interest data (evidence: `backend/handlers/connectionHandler.js`)
- Connection lifecycle → Live connection map: tracks sockets (evidence: `backend/handlers/connectionHandler.js`)
- Message dispatch → Queue coordination: joins or leaves (evidence: `backend/handlers/messageHandler.js`)
- Message dispatch → Session and message relay: relays chat events (evidence: `backend/handlers/messageHandler.js`)
- Message dispatch → Message rate limiting: checks message rate (evidence: `backend/handlers/messageHandler.js`)
- Queue coordination → Interest matching: starts interest match (evidence: `backend/services/queueService.js`)
- Queue coordination → Random matching: starts random match (evidence: `backend/services/queueService.js`)
- Queue coordination → Session and message relay: creates session (evidence: `backend/services/queueService.js`)
- Queue coordination → Redis: stores queue state (evidence: `backend/services/queueService.js`)
- Interest matching → Embedding provider: gets embeddings (evidence: `backend/services/matchmaking/interestMatcher.js`)
- Interest matching → Redis: matches candidates (evidence: `backend/services/matchmaking/interestMatcher.js`)
- Interest matching → Session and message relay: creates session (evidence: `backend/services/matchmaking/interestMatcher.js`)
- Random matching → Redis: uses queue state (evidence: `backend/services/matchmaking/randomMatcher.js`)
- Random matching → Session and message relay: creates session (evidence: `backend/services/matchmaking/randomMatcher.js`)
- Session and message relay → Redis: reads and writes sessions (evidence: `backend/services/sessionService.js`)
- Session and message relay → Live connection map: notifies sockets (evidence: `backend/services/sessionService.js`)
- Message rate limiting → Redis: tracks message counts (evidence: `backend/services/rateLimitService.js`)
- Redis client → Redis: connects client (evidence: `backend/config/redis.js`)
