# igorantun/node-chat architecture

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

- Interactive diagram: https://gitdiagram.com/igorantun/node-chat
- Repository: https://github.com/igorantun/node-chat

## Overview

##### Project type and purpose
- This is a real‐time, full‐stack chat application built on Node.js.
- Purpose: allow multiple users to chat (with emojis, private messaging, admin controls) via a web interface using SockJS for real‐time communication and Express for HTTP requests.

##### File structure
- Top‐level files:
- app.js – application entry point
- config.json – server configuration (port, SSL cert paths)
- package.json – dependencies (Express, SockJS, etc.)
- Directories:
- lib/ – server‐side utilities (log.js, utils.js)
- public/ – client assets (CSS, JS, fonts, images, sounds)
- views/ – EJS template(s) for server‐rendered HTML
- No explicit database folder: chat state likely held in memory (could be extended to Redis or other store).

##### README for additional insights
- Core stack: Node.js + Express + SockJS
- Features: Material Design on front end, emoji support, private/admin functions
- No external services other than optional SSL certificate, but could integrate a DB or message broker.

##### Main components and their interactions
a. Components
1. Client Browser
- Renders index.ejs, loads CSS/JS, establishes SockJS connection.
- Chat UI logic in public/js/chat.js
2. HTTP Server (Express in app.js)
- Serves static assets under /public
- Renders view(s) via EJS (views/index.ejs)
3. Real‐Time Layer (SockJS)
- Mounted in app.js to handle WebSocket/fallback connections.
4. Chat Core (in‐memory message hub)
- Receives incoming messages/events from SockJS
- Broadcasts to connected clients
- Enforces admin rules (kick/ban/delete)
5. Utilities & Logging (lib/utils.js, lib/log.js)
- Common helpers, formatted logs, timestamping
6. Configuration (config.json)
- Port, SSL certificate paths, other runtime settings
b. Relationships / Data Flow
- Client → HTTP GET / → Express renders index.ejs → sends HTML + CSS/JS assets
- Client JS → SockJS CONNECT → app.js SockJS server
- Client sends “chat message” frames → SockJS server routes to Chat Core → Chat Core processes & logs via lib/log.js → broadcasts to all SockJS clients
- Admin commands flow similarly, Chat Core consults role logic (could be in utils)
c. Architectural patterns / design principles
- Layered architecture: Web layer (Express) vs. Real‐time layer (SockJS) vs. Business logic (Chat Core).
- Separation of concerns: Views (EJS) vs. static assets vs. server logic vs. utilities.
- Event‐driven real‐time messaging.
d. Key technologies
- Node.js + Express
- SockJS for WebSocket fallback
- EJS templating engine
- jQuery + jQuery UI + custom CSS for front end
- In‐memory event hub (could later swap to Redis Pub/Sub)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Browser Client"
        direction TB
        Index["views/index.ejs"]:::frontend
        ChatJS["public/js/chat.js"]:::frontend
        jQueryJS["public/js/jquery.js"]:::frontend
        CSSChat["public/css/chat.css"]:::frontend
        CSSJQ["public/css/jquery-ui.css"]:::frontend
        CSSRipples["public/css/ripples.css"]:::frontend
        Fonts["public/fonts/Material-Design-Icons.eot"]:::frontend
        Images["public/img/"]:::frontend
        Sound["public/sounds/blop.wav"]:::frontend
    end

    Express["Express Web Server<br/>(app.js)"]:::backend
    SockJS["SockJS Server<br/>(app.js)"]:::backend
    ChatCore["Chat Core<br/>(app.js)"]:::backend

    subgraph "Utilities & Logging"
        Utils["lib/utils.js"]:::config
        Log["lib/log.js"]:::config
    end

    Config["config.json"]:::config
    Pkg["package.json"]:::config

    Index -->|"HTTP GET '/' | Sends HTML + Assets"| Express
    Express -->|"Serves HTML & Assets"| Index
    Express -->|"Mounts SockJS"| SockJS
    SockJS -->|"Handles CONNECT"| ChatCore
    ChatCore -->|"Broadcast Messages"| SockJS

    ChatCore -->|"Uses Utilities"| Utils
    ChatCore -->|"Logs Events"| Log
    Express -->|"Uses Utilities"| Utils
    Express -->|"Logs HTTP Requests"| Log
    Express -->|"Reads Configuration"| Config
    Express -->|"Dependencies"| Pkg

    click Index "https://github.com/igorantun/node-chat/blob/master/views/index.ejs"
    click ChatJS "https://github.com/igorantun/node-chat/blob/master/public/js/chat.js"
    click jQueryJS "https://github.com/igorantun/node-chat/blob/master/public/js/jquery.js"
    click CSSChat "https://github.com/igorantun/node-chat/blob/master/public/css/chat.css"
    click CSSJQ "https://github.com/igorantun/node-chat/blob/master/public/css/jquery-ui.css"
    click CSSRipples "https://github.com/igorantun/node-chat/blob/master/public/css/ripples.css"
    click Fonts "https://github.com/igorantun/node-chat/blob/master/public/fonts/Material-Design-Icons.eot"
    click Images "https://github.com/igorantun/node-chat/tree/master/public/img/"
    click Sound "https://github.com/igorantun/node-chat/blob/master/public/sounds/blop.wav"
    click Express "https://github.com/igorantun/node-chat/blob/master/app.js"
    click SockJS "https://github.com/igorantun/node-chat/blob/master/app.js"
    click ChatCore "https://github.com/igorantun/node-chat/blob/master/app.js"
    click Utils "https://github.com/igorantun/node-chat/blob/master/lib/utils.js"
    click Log "https://github.com/igorantun/node-chat/blob/master/lib/log.js"
    click Config "https://github.com/igorantun/node-chat/blob/master/config.json"
    click Pkg "https://github.com/igorantun/node-chat/blob/master/package.json"

    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef config fill:#FFA500,stroke:#000,stroke-width:1px;
```
