A comprehensive, production-ready multi-tenant WhatsApp SaaS platform built with Next.js, Fastify, Prisma, and Evolution API integration.
- Multi-tenant Architecture: Complete tenant isolation with role-based access control
- WhatsApp Integration: Full Evolution API integration for WhatsApp messaging
- Real-time Communication: WebSocket support for live messaging
- Comprehensive Testing: Unit, integration, E2E, performance, and security tests
- Production Ready: Docker containers, CI/CD pipelines, monitoring, and disaster recovery
- Scalable Infrastructure: Load balancing, caching, and horizontal scaling support
- Security First: Authentication, authorization, rate limiting, and security hardening
- Monitoring & Observability: Prometheus metrics, health checks, and alerting
- Backup & Recovery: Automated backups with disaster recovery procedures
- Quick Start
- Architecture
- Installation
- Configuration
- Development
- Testing
- Deployment
- Monitoring
- Backup & Recovery
- API Documentation
- Contributing
- License
- Node.js 18+ and npm 9+
- PostgreSQL 15+
- Redis 7+
- Docker and Docker Compose
- Evolution API instance
-
Clone the repository
git clone https://github.com/your-org/zapin-whatsapp-saas.git cd zapin-whatsapp-saas -
Install dependencies
npm install
-
Set up environment
cp .env.example .env # Edit .env with your configuration -
Set up database
npm run db:migrate npm run db:seed
-
Start development servers
npm run dev
-
Access the application
- Frontend: http://localhost:3000
- API: http://localhost:3001
- Health Check: http://localhost:3001/api/health
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Load Balancer β β Web Frontend β β API Backend β
β (Nginx) ββββββ (Next.js) ββββββ (Fastify) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ β
β Evolution API β β
β (WhatsApp) βββββββββββββββ€
βββββββββββββββββββ β
β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β PostgreSQL β β Redis β β File Storage β
β (Database) ββββββ (Cache) ββββββ (S3) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Frontend: Next.js with TypeScript, Tailwind CSS
- Backend: Fastify API with TypeScript
- Database: PostgreSQL with Prisma ORM
- Cache: Redis for session and data caching
- Queue: Redis-based job queue for background tasks
- Storage: AWS S3 for file storage
- Monitoring: Prometheus + Grafana stack
- Logging: Winston with structured logging
-
Development Environment
docker-compose -f docker-compose.development.yml up -d
-
Production Environment
docker-compose -f docker-compose.production.yml up -d
-
System Dependencies
# Ubuntu/Debian sudo apt update sudo apt install nodejs npm postgresql redis-server nginx # CentOS/RHEL sudo yum install nodejs npm postgresql redis nginx
-
Application Setup
npm install npm run build npm run db:migrate
-
Service Configuration
# Copy service files sudo cp config/systemd/*.service /etc/systemd/system/ sudo systemctl daemon-reload sudo systemctl enable zapin-api zapin-app sudo systemctl start zapin-api zapin-app
Create a .env file based on .env.example:
# Application
NODE_ENV=production
APP_URL=https://zapin.app
API_URL=https://api.zapin.app
# Database
DATABASE_URL=postgresql://user:password@localhost:5432/zapin
# Redis
REDIS_URL=redis://localhost:6379
# Evolution API
EVOLUTION_API_URL=http://localhost:8080
EVOLUTION_API_KEY=your-api-key
# Security
JWT_SECRET=your-jwt-secret-32-chars-minimum
ENCRYPTION_KEY=your-encryption-key-32-chars-long
# External Services
AWS_ACCESS_KEY_ID=your-aws-key
AWS_SECRET_ACCESS_KEY=your-aws-secret
AWS_S3_BUCKET=your-s3-bucketUse the configuration deployment script for environment-specific settings:
# Deploy development configuration
./scripts/config-deploy.sh deploy development
# Deploy production configuration
./scripts/config-deploy.sh deploy production --backup
# Validate configuration
./scripts/config-deploy.sh validate productionzapin-whatsapp-saas/
βββ src/ # Source code
β βββ api/ # API routes and middleware
β βββ components/ # React components
β βββ lib/ # Shared libraries
β βββ pages/ # Next.js pages
β βββ services/ # Business logic services
β βββ types/ # TypeScript type definitions
βββ tests/ # Test files
β βββ unit/ # Unit tests
β βββ integration/ # Integration tests
β βββ e2e/ # End-to-end tests
β βββ performance/ # Performance tests
β βββ security/ # Security tests
βββ scripts/ # Deployment and utility scripts
βββ config/ # Configuration files
βββ docs/ # Documentation
βββ prisma/ # Database schema and migrations
# Development
npm run dev # Start development servers
npm run build # Build for production
npm run start # Start production servers
# Database
npm run db:generate # Generate Prisma client
npm run db:migrate # Run database migrations
npm run db:seed # Seed database with test data
npm run db:studio # Open Prisma Studio
# Testing
npm run test # Run all tests
npm run test:unit # Run unit tests
npm run test:integration # Run integration tests
npm run test:e2e # Run end-to-end tests
npm run test:performance # Run performance tests
npm run test:security # Run security tests
# Code Quality
npm run lint # Run ESLint
npm run format # Format code with Prettier
npm run type-check # TypeScript type checking-
Feature Development
git checkout -b feature/new-feature npm run dev # Make changes npm run test npm run lint git commit -m "feat: add new feature" git push origin feature/new-feature
-
Code Review Process
- Create pull request
- Automated CI/CD checks run
- Code review by team members
- Merge after approval
The project includes comprehensive testing at multiple levels:
- Unit Tests: Test individual functions and components
- Integration Tests: Test API endpoints and service interactions
- End-to-End Tests: Test complete user workflows
- Performance Tests: Load testing and performance benchmarks
- Security Tests: Vulnerability assessment and security testing
# Run all tests
npm run test
# Run specific test types
npm run test:unit
npm run test:integration
npm run test:e2e
npm run test:performance
npm run test:security
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watchTests are configured using Jest and Playwright:
- Jest: Unit and integration tests
- Playwright: End-to-end tests
- Artillery: Performance tests
- Custom: Security tests
Use the automated deployment scripts:
# Initial server setup
./scripts/setup-environment.sh --environment production
# Deploy application
./scripts/deploy.sh --environment production
# SSL setup
./scripts/ssl-setup.sh --domain zapin.app --email admin@zapin.app# Build production image
docker build -f Dockerfile.production -t zapin-api .
# Deploy with Docker Compose
docker-compose -f docker-compose.production.yml up -d
# Check deployment
docker-compose -f docker-compose.production.yml psThe project includes GitHub Actions workflows for:
- Continuous Integration: Automated testing and code quality checks
- Security Scanning: Dependency and container vulnerability scanning
- Automated Deployment: Deploy to staging and production environments
- Release Management: Automated releases with semantic versioning
- Environment variables configured
- Database migrations applied
- SSL certificates installed
- Monitoring configured
- Backup systems active
- Health checks passing
- Performance tests passed
- Security scans completed
The application provides comprehensive health checks:
# Application health
curl https://api.zapin.app/health
# Database health
curl https://api.zapin.app/health/database
# Redis health
curl https://api.zapin.app/health/redis
# Evolution API health
curl https://api.zapin.app/health/evolution- Prometheus: Metrics collection
- Grafana: Visualization and dashboards
- AlertManager: Alert routing and management
- Custom Metrics: Application-specific metrics
Structured logging with Winston:
# View logs
tail -f logs/combined.log
# View error logs
tail -f logs/error.log
# View access logs
tail -f /var/log/nginx/access.logConfigure alerts for:
- High error rates
- Performance degradation
- Resource exhaustion
- Security incidents
- Service unavailability
# Full system backup
./scripts/backup-system.sh full --encrypt --s3
# Database backup
./scripts/backup-system.sh database
# Files backup
./scripts/backup-system.sh files
# Configuration backup
./scripts/backup-system.sh configSet up automated backups:
# Install backup scheduler
./scripts/backup-scheduler.sh install --enable-s3 --enable-encryption
# Check backup status
./scripts/backup-scheduler.sh status
# Monitor backups
./scripts/backup-scheduler.sh monitor# Interactive recovery wizard
./scripts/recovery-system.sh interactive
# Full system recovery
./scripts/recovery-system.sh full --backup backup_name
# Database recovery
./scripts/recovery-system.sh database --backup db_backup_nameFor complete disaster recovery procedures, see Disaster Recovery Plan.
# Check DR status
./scripts/disaster-recovery.sh status
# Execute failover
./scripts/disaster-recovery.sh failover --scenario server-failure
# Validate DR readiness
./scripts/disaster-recovery.sh validateAll API endpoints require authentication using JWT tokens:
# Login
curl -X POST https://api.zapin.app/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "user@example.com", "password": "password"}'
# Use token
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
https://api.zapin.app/instancesGET /api/instances- List WhatsApp instancesPOST /api/instances- Create new instanceGET /api/instances/:id- Get instance detailsPUT /api/instances/:id- Update instanceDELETE /api/instances/:id- Delete instance
POST /api/instances/:id/messages- Send messageGET /api/instances/:id/messages- Get message historyPOST /api/instances/:id/media- Send media message
POST /api/webhooks/evolution- Evolution API webhookGET /api/webhooks/status- Webhook status
For complete API documentation, see API Guide.
# Check database status
sudo systemctl status postgresql
# Check connection
psql -h localhost -U zapin_user -d zapin -c "SELECT 1;"
# View database logs
sudo tail -f /var/log/postgresql/postgresql-15-main.log# Check Redis status
sudo systemctl status redis
# Test connection
redis-cli ping
# View Redis logs
sudo tail -f /var/log/redis/redis-server.log# Check application logs
tail -f logs/combined.log
# Check process status
pm2 status
# Restart services
sudo systemctl restart zapin-api zapin-app# Check system resources
htop
df -h
free -h
# Check database performance
./scripts/db-management.sh analyze
# Run performance tests
npm run test:performance# Run security scan
npm run test:security
# Check for vulnerabilities
npm audit
# Update dependencies
npm updateWe welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Clone your fork
- Create a feature branch
- Make your changes
- Add tests for your changes
- Ensure all tests pass
- Submit a pull request
- Follow TypeScript best practices
- Write comprehensive tests
- Use conventional commit messages
- Update documentation as needed
- Ensure security best practices
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: docs/
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@zapin.app
- Evolution API for WhatsApp integration
- Next.js for the frontend framework
- Fastify for the backend framework
- Prisma for database management
- All contributors and the open-source community
Built with β€οΈ by the Zapin Team
For more detailed information, please refer to the documentation in the docs/ directory.