NestJS-based chat system backend with real-time messaging and guaranteed email notifications
Explore the docs Β»
Report Bug
Β·
Request Feature
Table of Contents
A robust NestJS-based chat system backend with REST API and WebSocket support. Designed to work with any modern frontend framework. Features zero message loss, guaranteed email notifications, and real-time communication capabilities.
- Zero Message Loss: All messages saved to database with atomic transactions
- Guaranteed Email Notifications: Every visitor message triggers an email to admin
- Real-time Communication: WebSocket support for instant messaging
- Session Management: Automatic session creation and management
- Admin Dashboard API: Complete session and message management
- Node.js
- pnpm
- Supabase account
- Docker Desktop
- Email SMTP credentials (Gmail recommended)
-
Clone the repository
git clone https://github.com/Nagell/dawid-nitka-chat.git
-
Install packages
pnpm install
-
Copy
.env.exampleto.envand configure your environment variablescp .env.example .env
-
Set up your database using Supabase migrations (see Development Guide for details)
# For local development pnpm supabase start # For production setup pnpm supabase login pnpm supabase link --project-ref <your-project-id> pnpm supabase db push
-
Start the development server
pnpm run start:dev
-
The server will start on
http://localhost:3001
Once running, test the API with these simple curl commands:
# Health check
curl http://localhost:3001/api/chat/health
# Create a chat session
curl -X POST http://localhost:3001/api/chat/sessions \
-H "Content-Type: application/json" \
-d '{"visitor_email":"[email protected]","visitor_name":"Test User"}'
# Send a message (use session_id from previous response)
curl -X POST http://localhost:3001/api/chat/messages \
-H "Content-Type: application/json" \
-d '{"session_id":1,"content":"Hello!","sender_type":"visitor"}'POST /api/chat/sessions- Create a new chat sessionGET /api/chat/sessions/{id}- Get session detailsGET /api/chat/sessions/{id}/messages- Get messages for a sessionPOST /api/chat/sessions/{id}/mark-read- Mark messages as read
POST /api/chat/messages- Send a new message
GET /api/chat/admin/sessions- Get all sessions with summaryGET /api/chat/admin/stats- Get WebSocket connection statistics
GET /api/chat/health- Health check endpoint
- Backend Architecture - Complete NestJS setup with modular structure
- Database Schema - Comprehensive Supabase schema with triggers and RPC functions
- REST API Endpoints - Full CRUD operations tested in local and production environments
- Input Validation - class-validator DTOs with email, length, and type validation
- WebSocket Gateway - Server-side gateway with room management and typing indicators
- Email Notifications - HTML email service tested and working with Gmail SMTP
- Environment Configuration - Production/development environment separation working
- HTML Security - XSS protection with proper input escaping implemented
- Database Testing - Both local and production Supabase connections verified
- Production Environment - Production server tested with isolated database
- WebSocket Client Testing - Need to test real-time functionality from client side
- Security Hardening - Critical authentication guards and session security needed
- Session Authentication - Token-based session access control
- Admin Authentication - Cross-Supabase JWT validation for admin endpoints
- Rate Limiting - Protection against spam and abuse
- API Documentation - OpenAPI/Swagger documentation generation
- Frontend Integration - Nuxt.js components for portfolio integration
- Admin Dashboard - Complete session management interface
- Performance Optimization - Caching and query optimization
- Deployment Setup - Production deployment to Vercel/Railway
- Session Access Control - Prevent unauthorized access to chat sessions
- Admin Endpoint Protection - Secure admin functionality with proper authentication
- WebSocket Validation - Add validation DTOs for WebSocket message events
- Security Headers - Add helmet middleware with security headers
See TODO.md for detailed implementation progress and security audit findings.
-
Deploy to Vercel:
pnpm add -g vercel vercel --prod
-
Set environment variables in Vercel dashboard
- Connect your repository to Railway
- Set environment variables
- Deploy automatically on push
Distributed under the CC BY-NC 4.0 License. See LICENSE for more information.
Dawid Nitka - LinkedIn
Project Link: https://github.com/Nagell/chat-nest
