Skip to content

Introduction

What is nestjs-chat?

nestjs-chat is a real-time chat SDK for NestJS, distributed as a regular npm package. You install it into your existing NestJS backend, import ChatModule.forRoot(), provide a few host-side implementations (auth, user lookup, optionally storage), and get a full REST + WebSocket chat API — channels, messages, polls, scheduled messages, reactions, moderation, the lot.

There's no separate server to run and no hosted service. The SDK lives inside your NestJS process, alongside your own controllers.

Why self-host?

SaaS chat services charge per message or per MAU. With nestjs-chat you only pay for your PostgreSQL and Redis. No seat limits, no message caps, no vendor lock-in — it's MIT-licensed and runs wherever your NestJS app runs.

How it fits together

┌─────────────────────────────────────────────────────┐
│                  YOUR NestJS APP                    │
│                                                     │
│  ┌─────────────┐  ┌──────────────┐  ┌────────────┐ │
│  │ AuthGuard   │  │ UserResolver │  │  Storage   │ │
│  │ (your impl) │  │ (your impl)  │  │ (your impl)│ │
│  └──────┬──────┘  └──────┬───────┘  └─────┬──────┘ │
│         │                │                 │        │
│  ┌──────▼────────────────▼─────────────────▼──────┐ │
│  │           ChatModule.forRoot({...})            │ │
│  │  ┌──────────┐ ┌──────────┐ ┌────────────────┐ │ │
│  │  │ Channels │ │ Messages │ │ Polls/Scheduled│ │ │
│  │  └──────────┘ └──────────┘ └────────────────┘ │ │
│  │  ┌──────────┐ ┌──────────┐ ┌────────────────┐ │ │
│  │  │ Gateway  │ │  Users   │ │   Prisma/PG    │ │ │
│  │  │(Socket.IO│ │          │ │                │ │ │
│  │  └──────────┘ └──────────┘ └────────────────┘ │ │
│  └────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────┘

What you bring

Three required providers, two optional ones:

InterfaceRoleRequired
IChatAuthGuardValidates the caller (JWT, session cookie, API key...) for HTTP + WebSocket.Yes
IChatUserExtractorPulls { id, tenantId } out of the request after the guard has run.Yes
IChatUserResolverLooks up user profiles by id (name, avatar, online status) in your user database.Yes
IChatStorageProviderUploads message attachments to S3/GCS/local disk/etc.No
IChatEventHandlerObserves chat events (e.g. to send push notifications or webhooks).No

Full shapes and examples: Configuration.

What the SDK brings

Chat features

  • Channels — 1-on-1 direct messages with automatic deduplication per tenant, group channels with member cap, key/value metadata, custom types, freeze, hide, reset-history.
  • Messages — text / image / video / audio / file, threading, forwarding, full-text search, edit + soft delete, mentions.
  • Real-time — typing indicators, read receipts via lastReadAt, per-user unread counts, delivered receipts, presence (if your resolver implements isOnline).
  • Reactions — emoji reactions per-user per-message, real-time add/remove.
  • Polls — single or multi-vote, scheduled close, optional user-suggested options.
  • Scheduled messages — delayed send backed by BullMQ; edit/cancel/send-now before the deadline.
  • Moderation — channel freeze/unfreeze, per-user timed mute + ban, global user block, reporting.
  • Preferences — per-channel push triggers and unread-count visibility.

Infrastructure

ComponentVersionRole
NestJS10Host framework
Prisma7ORM — 11 models, bundled migrations applied via chat-migrate CLI
PostgreSQL15+Primary datastore for chat data
Socket.IO4Real-time gateway
Redis adapterMulti-instance fan-out for Socket.IO
BullMQ5Delayed job queue for scheduled messages
Redis7+BullMQ backend + Socket.IO adapter
Winston3Structured logging (console + rotating file)

At a glance

MetricValue
REST endpoints63
WebSocket events42
Prisma models11
Error codes30
Internal modules6 (Channel, Message, Poll, User, Scheduled, Gateway)
LicenseMIT

Next: Getting Started to install and run.

MIT License