A comprehensive, enterprise-grade Customer Relationship Management (CRM) system backend built with NestJS. Designed for businesses to manage customers, sales pipelines, multi-channel messaging, email campaigns, and team collaboration.
- Framework: NestJS 11
- Database: PostgreSQL 16 + Prisma ORM
- Cache/Queue: Redis 7 + BullMQ
- Authentication: Passport (Credentials, Google OAuth, Facebook OAuth, 2FA)
- File Storage: AWS S3
- Email: React Email templates + Nodemailer
- Real-time: Socket.IO (WebSockets)
- i18n: nestjs-i18n
- Multi-method authentication (Credentials, Google OAuth, Facebook OAuth)
- Email verification with secure tokens
- Two-factor authentication (2FA)
- Password reset flow
- User profile management
- Multi-tenant architecture with business isolation
- Role-based access control (Owner, Admin, Member)
- Business email verification
- Team member invitations with expiring tokens
- Custom business types (Service-based, Product-based, Hybrid)
- Business-specific SMTP configuration for email campaigns
- Comprehensive customer profiles with custom fields
- Customer status tracking (New, Active, Inactive, Lost)
- Priority levels (Low, Medium, High)
- Customer tagging system with colors
- Dynamic and static customer segments
- Advanced filtering and search
- Customer analytics
- Telegram Integration β Bot integration, send/receive messages, media support, reply tracking
- Viber Integration β Bot integration, message management
- Instagram Direct Messages β Facebook Graph API integration, message delivery tracking, reactions
- Facebook Messenger β Page integration, message management, delivery tracking, reactions
- Unified message history across all channels
- Automatic customer creation from messaging platforms
- Media file handling (photos, videos, documents, voice messages)
- Broadcast email campaigns to customer segments
- Campaign status tracking (Draft, Sending, Sent, Failed)
- Individual recipient delivery tracking
- Business-specific SMTP configuration support
- React Email templates
- Kanban-style pipeline management
- Customizable pipeline stages with colors
- Deal tracking with value, currency, and discount support
- Deal assignment to team members
- Pipeline access control per member
- Deal analytics
- Internal Chat System β Direct (1:1) and group chats
- Real-time messaging with WebSocket support
- Message replies and threading
- Read receipts and unread count tracking
- Chat participant management
- Mute notifications per chat
- File attachments support
- Real-time notifications via WebSocket
- Multiple notification categories (Messaging, Business, Pipeline, Customer, Campaign, Internal Chat)
- Priority levels (Low, Medium, High)
- Personal and broadcast notifications
- Notification types include:
- New messages from customers
- New customer via messenger
- Deal created/moved/assigned
- Team member invitations
- Campaign completion
- Customer birthdays
- And more...
- Customer analytics
- Deal analytics
- Business performance metrics
- Node.js 20+
- Yarn
- Docker & Docker Compose
- PostgreSQL 16
- Redis 7
yarn installCreate .env file based on .env.example:
# --------------------------------------------------------
# Application Environment
# --------------------------------------------------------
NODE_ENV=development
APPLICATION_PORT=8080
APPLICATION_URL=http://localhost:8080/api
ALLOWED_ORIGIN=http://localhost:3000
# --------------------------------------------------------
# PostgreSQL Database Configuration
# --------------------------------------------------------
POSTGRES_USER=postgres
POSTGRES_PASSWORD=secret
POSTGRES_DB=crm
DATABASE_URL=postgresql://postgres:secret@localhost:5432/crm?schema=public
# --------------------------------------------------------
# Redis Configuration
# --------------------------------------------------------
REDIS_USER=default
REDIS_PASSWORD=secret
REDIS_PORT=6379
REDIS_URL=redis://default:secret@localhost:6379
# --------------------------------------------------------
# Session & Cookie Configuration
# --------------------------------------------------------
COOKIE_SECRET=your-cookie-secret
SESSION_SECRET=your-session-secret
SESSION_NAME=session
SESSION_DOMAIN=localhost
SESSION_MAX_AGE=30d
SESSION_HTTP_ONLY=true
SESSION_SECURE=false
SESSION_PREFIX=sessions:
# --------------------------------------------------------
# Cloudflare Turnstile Configuration
# --------------------------------------------------------
TURNSTILE_SECRET_KEY=your-turnstile-key
# --------------------------------------------------------
# Google OAuth Configuration
# --------------------------------------------------------
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
# --------------------------------------------------------
# SMTP / Email Configuration
# --------------------------------------------------------
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
SMTP_FROM_EMAIL=noreply@yourapp.com
# --------------------------------------------------------
# Facebook / Instagram OAuth Configuration
# --------------------------------------------------------
FACEBOOK_APP_ID=your-facebook-app-id
FACEBOOK_APP_SECRET=your-facebook-app-secret
INSTAGRAM_OAUTH_SUCCESS_REDIRECT=http://localhost:3000/settings/integrations
INSTAGRAM_WEBHOOK_BASE_URL=http://localhost:8080/api
INSTAGRAM_VERIFY_TOKEN=your-verify-token./start-containers.sh
# or
docker-compose up -dyarn prisma:generate # generate Prisma client
yarn prisma:migrate:prod # apply migrations (production)
# or
yarn prisma:push # sync schema (development)yarn start:dev # development (watch mode)
yarn start:prod # productionThe API will be available at http://localhost:8080/api
Swagger documentation: http://localhost:8080/api/docs
| Command | Description |
|---|---|
yarn start:dev |
Run in watch mode |
yarn start:prod |
Run production build |
yarn build |
Build the project |
yarn lint |
Run ESLint |
yarn test |
Run unit tests |
yarn test:e2e |
Run E2E tests |
yarn prisma:studio |
Open Prisma Studio |
yarn prisma:generate |
Generate Prisma client |
yarn prisma:migrate:commit <name> |
Create new migration |
yarn prisma:migrate:prod |
Apply migrations (production) |
yarn prisma:push |
Sync schema (development only) |
src/
βββ config/ # Configuration modules
βββ i18n/ # Internationalization files (en, ru, am, no)
βββ infra/ # Infrastructure layer
β βββ mail/ # Email service + React Email templates
β βββ orm/ # Prisma service
β βββ redis/ # Redis configuration
β βββ s3/ # S3 file storage
βββ modules/
β βββ auth/ # Authentication & authorization
β β βββ strategies/ # Passport strategies (local, Google, Facebook, 2FA)
β β βββ guards/ # Auth guards
β β βββ dto/ # Auth DTOs
β βββ user/ # User profile management
β βββ notification/ # Notification system
β β βββ notification.gateway.ts # WebSocket gateway
β β βββ notification.listener.ts # Event listeners
β β βββ notification.service.ts
β βββ business/ # Business module (multi-tenant)
β βββ customer/ # Customer management
β βββ pipeline/ # Sales pipelines & deals
β βββ tag/ # Customer tags
β βββ segment/ # Customer segments
β βββ invite/ # Team invitations
β βββ analytics/ # Business analytics
β βββ broadcast/ # Email campaigns
β βββ telegram/ # Telegram integration
β βββ viber/ # Viber integration
β βββ instagram/ # Instagram DM integration
β βββ facebook-messenger/ # Facebook Messenger integration
β βββ chat/ # Internal team chat
βββ shared/ # Shared utilities, guards, decorators
- Create a bot via @BotFather
- Get the bot token
- Configure webhook in your business settings
- Start receiving and sending messages
- Create a bot via Viber Admin Panel
- Get the auth token
- Configure webhook
- Connect with customers
- Create a Facebook App
- Add Instagram Basic Display and Instagram Messaging products
- Configure webhook subscriptions
- Link Instagram Business Account
- OAuth flow to get page access token
- Create a Facebook App
- Add Messenger product
- Configure webhook subscriptions
- Get page access token
- Start messaging customers
The notification gateway (/notifications) supports the following events:
-
Client β Server:
joinβ Join notification room for a businessmark_as_readβ Mark notification as read
-
Server β Client:
notificationβ New notification receivederrorβ Error message
Swagger UI is available at /api/docs when running in development mode.
The API uses:
- Session-based authentication with Redis storage
- CORS with configurable allowed origins
- Rate limiting with Redis-backed throttler
- Request validation with class-validator
- i18n support via
x-langheader
- 27 tables with comprehensive relationships
- Soft deletes for critical entities (customers, deals, pipelines)
- Optimized indexes for common query patterns
- JSON fields for flexible custom fields and metadata
- Multi-tenant isolation via
businessId
- Argon2 password hashing
- Session management with Redis
- CSRF protection ready
- Rate limiting per IP
- Input validation and sanitization
- Cloudflare Turnstile support
- Secure cookie configuration
- OAuth 2.0 flows
Private / Unlicensed