npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@procuregenie/chat-backend

v1.0.6

Published

Here is a **clean, professional, and production-ready updated `README.md`** for your **Chatbot Backend Package**, rewritten for **clarity, correctness, and npm-quality documentation**.

Readme

Here is a clean, professional, and production-ready updated README.md for your Chatbot Backend Package, rewritten for clarity, correctness, and npm-quality documentation.

You can copy–paste this directly into your repository.


🚀 Chatbot Backend Package

A scalable, real-time chatbot backend built with Node.js, Express, Sequelize, and Socket.IO. Designed to plug into any existing user table without modifying your schema.


📌 Node Version

Node.js >= 23.11.0

📖 Introduction

chatbortbackend is a ready-to-use backend engine for real-time chat applications. It provides:

  • REST APIs for messages & groups
  • Socket.IO real-time events
  • Dynamic user-table integration
  • Transaction-safe group management
  • Clean service-based architecture

You do not need to redesign your user table — simply map it during initialization.


✨ Features

  • 🔴 Real-time Messaging (Socket.IO)
  • 👥 One-to-One & Group Chat
  • 📎 File & Document Sharing
  • ✏️ Edit / Delete Messages (Live Sync)
  • 🟢 Online / Offline User Tracking
  • 🔒 Transaction-Safe Group Operations
  • 🧩 Plug-and-Play User Table Mapping
  • 🧱 Clean Architecture (Controller / Service / Model)

🗂 Folder Structure

src/
├── config/
│   └── DatabaseConfig.js        # Sequelize DB connection
│
├── controllers/
│   └── MessageController.js     # REST API controllers
│
├── models/
│   ├── Group.js                 # Group model
│   ├── GroupMember.js           # Group-user mapping
│   ├── Message.js               # Message model
│   └── init_models.js           # Model associations
│
├── services/
│   └── ChatService.js           # Core business logic
│
├── sockets/
│   └── MessageSocketHandler.js  # Socket.IO events
│
├── utils/
│   ├── AppUtils.js              # Utility helpers
│   └── FileManager.js           # File handling
│
├── validators/
│   └── ChatValidators.js        # Express validators
│
└── index.js                     # Package entry point

📦 Installation

Install from npm

npm install chatbortbackend

⚙️ Configuration & Initialization

🔧 Database Support

  • PostgreSQL (Sequelize ORM)

🧠 Initialization Example

const { Service } = require('chatbortbackend').ChatService;

const chatService = new Service();

(async () => {
    await chatService.init({
        dbconfig: {
            host: 'localhost',
            username: 'postgres',
            password: 'password',
            database: 'chat_db',
            port: 5432,
            dialect: 'postgres'
        },
        userModel: {
            name: 'users', // existing user table
            columns: {
                id: { columns: ['id'] },
                username: { columns: ['first_name', 'last_name'] },
                email: { columns: ['email'] },
                phoneNumber: { columns: ['phone'] }
            }
        }
    });
})();

✔ No schema changes required ✔ Works with existing production databases


🔌 API Documentation

📩 Messages

➤ Create Message

POST /api/messages

Request Body

{
  "fromUserId": 1,
  "toUserId": 2,
  "groupId": null,
  "messageType": "text",
  "messageText": "Hello world",
  "file": {
    "name": "image.png",
    "base64": "..."
  }
}

➤ Fetch Messages

GET /api/messages

Query Parameters

| Parameter | Required | Description | | ---------- | -------- | ---------------- | | fromUserId | Optional | Sender user ID | | toUserId | Optional | Receiver user ID | | groupId | Optional | Group ID | | search | Optional | Search text | | page | Optional | Default: 1 | | limit | Optional | Default: 10 |


🔄 Socket.IO Events

Client → Server

| Event | Description | | ---------------------- | -------------- | | handleUserConnection | Register user | | handleSendMessage | Send message | | handleEditMessage | Edit message | | handleDeleteMessage | Delete message |


Server → Client

| Event | Description | | ----------------- | -------------------- | | new_message | New incoming message | | message_edited | Message updated | | message_deleted | Message removed | | online_users | Active users list |


Sample Payload

{
  "fromUserId": 1,
  "toUserId": 2,
  "groupId": null,
  "messageType": "text",
  "messageText": "Hello"
}

🗃 Database Schema

Tables

| Table | Purpose | | ----------------- | ------------------ | | groupsmaster | Group metadata | | groupuserslines | Group-user mapping | | message | Messages |


Relationships

  • Group ➝ hasMany ➝ GroupMember
  • Group ➝ hasMany ➝ Message
  • GroupMember ➝ belongsTo ➝ Group
  • Message ➝ belongsTo ➝ Group

🧠 Service Layer (ChatService)

Available Methods:

  • fetchMessages()
  • fetchGroups()
  • createGroup()
  • updateGroup()
  • assignGroupMembers()
  • getGroupManageUsers()

✔ All group operations are transaction-safe


🚀 Express.js Example

const express = require('express');
const http = require('http');
const { Server } = require('socket.io');

const {
    MessageController,
    MessageSocketHandler,
    ChatValidators
} = require('chatbortbackend');

const { Service } = require('chatbortbackend').ChatService;

const app = express();
const server = http.createServer(app);
const io = new Server(server);

app.use(express.json());

// Initialize Chat Service
const chatService = new Service();
(async () => {
    await chatService.init({ ...config });
})();

// Routes
app.get(
    '/messages',
    ChatValidators.validateGetMessages,
    MessageController.fetchMessages
);

// Socket
io.on('connection', (socket) => {
    MessageSocketHandler(socket, io);
});

server.listen(3000, () => {
    console.log('🚀 Server running on port 3000');
});

🛠 Development Usage

Using npm link (Local Development)

npm link
npm link chatbortbackend

Install from Local Path

npm install /absolute/path/to/chatbortbackend