This is the backend service for the chat application built using NestJS, Prisma, Redis, and WebSocket technologies. The backend provides authentication, real-time messaging, session management, and rate-limiting using Redis.
- User Registration & Authentication: JWT-based authentication with secure session storage.
- Real-time Chat: WebSocket-based messaging system with support for multiple chat rooms.
- Redis Caching: Frequently accessed data (e.g., chat messages) are cached in Redis to improve performance.
- Rate Limiting: Redis-based rate limiting to control how many messages a user can send in a specified period.
- Database: Prisma ORM connected to a PostgreSQL database for managing users, messages, and chat rooms.
- Session Management: Redis is used to store user login sessions for faster authentication checks.
- NestJS - Node.js framework for building efficient and scalable server-side applications.
- Prisma - ORM for managing PostgreSQL database.
- Redis - In-memory data store used for caching and rate-limiting.
- Socket.io - Real-time bidirectional event-based communication for chat functionality.
- JWT - JSON Web Token for secure user authentication.
- Node.js (v16 or higher)
- PostgreSQL Database
- Redis server
- Docker (optional)
-
Clone the repository:
git clone https://github.com/ricky-ultimate/convo-backend.git cd convo-backend -
Install the dependencies:
npm install
Create a .env file in the root directory and configure the following environment variables:
# PostgreSQL database
DATABASE_URL=postgresql://user:password@localhost:5432/chatapp
# JWT configuration
JWT_SECRET=your_jwt_secret_key
SESSION_SECRET=your-session-secret
# Redis configuration
REDIS_URL=redis://localhost:6379
# Rate-limiting configuration
RATE_LIMIT_POINTS=5 # Max messages per duration
RATE_LIMIT_DURATION=10 # Duration in seconds for rate-limitingTo run the server in development mode:
npm run start- User Registration: Post
/auth/register - User Login: Post
/auth/login - Create Chat Room: Post
/chat/room - Send Message: Post
/chat/message - Get Messages: GET
/chat/messages?chatRoomName=room-name