# steffenwt/nodejs-pub-sub-chat-demo architecture

> Architecture diagram of the GitHub repository steffenwt/nodejs-pub-sub-chat-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/steffenwt/nodejs-pub-sub-chat-demo
- Repository: https://github.com/steffenwt/nodejs-pub-sub-chat-demo

## Overview

##### Project type and purpose
- This is a lightweight, real‐time chat demo built on Node.js that illustrates two modes:
a) A pure Socket.io version (app.js)
b) A Redis Pub/Sub + Socket.io version (app_redis.js)
- Its goal is to show how messages can be broadcast in‐process or distributed across multiple Node instances via Redis.

##### File structure
- Top‐level files only—no frontend/backend folder split:
- app.js            → HTTP + Socket.io server (no Redis)
- app_redis.js      → HTTP + Socket.io server wired to Redis Pub/Sub
- index.html        → Static client UI for chat
- package.json      → Defines dependencies: socket.io, redis, express (or http)
- There are no separate build scripts or microservices—everything runs in one Node process.

##### README for additional insights
- Emphasizes two run modes (“npm run sockets” or “npm run redis”)
- Mentions Redis must be installed/running for the Pub/Sub demo

– HTTP/WebSocket (socket.io)
– Redis Pub/Sub client (in app_redis.js only)
- From Browsers → Node.js: “WebSocket: chat message”
- From Node.js → Redis (Pub): “PUBLISH chat”
- From Redis → Node.js (Sub): “SUBSCRIBE chat”
- From Node.js → Browsers: “WebSocket: broadcast”
5. A second path directly from Server → Clients for the non‐Redis mode.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Clients Layer"
        Browser["Browser Client"]:::client
    end

    subgraph "Project Files"
        Pkg["package.json"]:::docs
        Readme["README.textile"]:::docs
        GitIgnore[".gitignore"]:::docs
    end

    subgraph "Node.js Chat Server"
        A["app.js\n(Socket.io only mode)"]:::server
        B["app_redis.js\n(Redis Pub/Sub + Socket.io)"]:::server
        ClientUI["index.html\n(Static Client UI)"]:::client
    end

    Redis["Redis Server\n(Pub/Sub Broker)"]:::redis

    Browser -->|"WebSocket: chat message"| A
    A -->|"WebSocket: broadcast"| Browser
    A -->|"serves static files"| ClientUI

    Browser -->|"WebSocket: chat message"| B
    B -->|"PUBLISH channel:chat"| Redis
    Redis -->|"SUBSCRIBE channel:chat"| B
    B -->|"WebSocket: broadcast"| Browser
    B -->|"serves static files"| ClientUI

    classDef client fill:#D5E8D4,stroke:#333,stroke-width:1px
    classDef server fill:#FFF2CC,stroke:#333,stroke-width:1px
    classDef redis fill:#F8CECC,stroke:#333,stroke-width:1px
    classDef docs fill:#E1D5E7,stroke:#333,stroke-width:1px

    click A "https://github.com/steffenwt/nodejs-pub-sub-chat-demo/blob/master/app.js"
    click B "https://github.com/steffenwt/nodejs-pub-sub-chat-demo/blob/master/app_redis.js"
    click ClientUI "https://github.com/steffenwt/nodejs-pub-sub-chat-demo/blob/master/index.html"
    click Pkg "https://github.com/steffenwt/nodejs-pub-sub-chat-demo/blob/master/package.json"
    click Readme "https://github.com/steffenwt/nodejs-pub-sub-chat-demo/blob/master/README.textile"
    click GitIgnore "https://github.com/steffenwt/nodejs-pub-sub-chat-demo/blob/master/.gitignore"
```
