Skip to content

shkwahab/chatappbackendnestjs

Repository files navigation

Chat Application Backend

Prisma Logo MongoDB Logo

Nest Logo

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Support us

Description

This is the backend for a chat application built with Nest.js, MongoDB, and Prisma. It provides robust features for real-time group chatting with Socket.io and web push notifications.

Features

  • Group Chatting: Supports both public channels and private groups.
  • Real-Time Communication: Utilizes Socket.io for live message updates.
  • Push Notifications: Implemented with web push for notifying users even when the app is closed or in kill mode.

Installation

Prerequisites

  • Node.js: JavaScript runtime for server-side code.
  • Nest.js: Framework for building efficient, scalable Node.js server-side applications.
  • MongoDB: NoSQL database used to store data.
  • Prisma: ORM (Object-Relational Mapping) for database access and management.
  • Socket.io: Library for real-time communication.
  • Web Push: Technology for sending push notifications to users.
  • Swagger Documentation: Api Documentation.

Setup

  1. Clone the repository:

    git clone https://github.com/shkwahab/chatappbackendnestjs.git
    cd chatappbackendnestjs
  2. Install the dependency if you dont have pnpm package manage than follow this setup:

    npm i -g pnpm
    pnpm i

    Otherwsie:

    pnpm i
  3. Create an .env file in the root directory with the following content and replace the keys according to your requirements:

DATABASE_URL            =     "mongodb://localhost:27017/chatapp"
ACCESS_SECRET_KEY       =     "JDzIBEsLl9PZOdYp4eQa/IPTgwNVfA2ts2+0lw6Whpc="
REFRESH_SECRET_KEY      =     "pJEZpMM6xdInYhLk28qL5N9Pob37tsdP7ohQQ4qqb5A="
WEB_PUSH_PUBLIC_KEY     =     "BFhz7f5ZMJes9tsqQhNQ4W8GyGhhoVxigttI5nlk1whWBBDBo5PXSNvPYaxVawRJnUTm9Rmt14Z4FPCigpFSP-0"
WEB_PUSH_PRIVATE_KEY    =     "3mvz9AabmvZ3xqxcVGq9Y4isavxiUMm5nmzFhVSoBm0"
WEB_PUSH_MAIL           =     "yourname@emailprovider.com"
APP_ICON                =     "https://myapp.com/logo.svg"
SITE_URL                =     "https://myapp.com"   
CLOUDINARY_CLOUD_NAME        =     "<YOUR_CLOUD_NAME>"
CLOUDINARY_API_KEY           =     "<YOUR_API_KEY>"
CLOUDINARY_API_SECRET        =     "<YOUR_API_SECRET>"
  1. Set up MongoDB replica set (default port is 27017).

  2. Start the application:

Dev Environment:

pnpm start:dev

Production Environment:

pnpm start

Swagger API Documentation

Run the server visit: localhost:9000/api-docs Here is the Frontend App Github Repo visit: Frontend App

Notifications

  • Subscribe: Adds a new subscriber to the notification system.
  • Send Notification: Sends a push notification to all subscribers.

Group Chatting

  • Public Channels: Channels where anyone can join and chat.
  • Private Groups: Groups where only authorized members can join.