This document outlines the CI/CD pipeline implementation for the FlowFocus MERN stack monorepo. The pipeline maintains code quality, catches issues early, and automatically deploys to production VPS using separate CI and CD workflows.
ci.yml- Continuous Integration (runs on all branches and PRs)deploy.yml- Continuous Deployment (runs only after CI passes on main)
- Push to
mainanddevelopbranches - Pull requests targeting
mainanddevelop - Manual workflow dispatch
- Automatically triggered when CI completes successfully on
mainbranch - Manual deployment trigger with branch selection
- Only deploys if CI pipeline passes
Push to main → CI Pipeline → (if successful) → CD Pipeline → Production
- Purpose: Ensures consistent code formatting and catches linting issues
- Actions:
- Verifies Prettier formatting
- Runs ESLint on client code
- Conditionally runs server linting (when configured)
- Tools: Prettier, ESLint
- Purpose: Validates React frontend functionality
- Actions:
- Runs Jest tests for the React app
- Builds the Vite production bundle
- Tests on Node.js 20
- Uploads build artifacts for review
- Tools: Jest, Vite, Testing Library
- Purpose: Validates Express backend functionality with real MongoDB
- Actions:
- Runs Jest tests with MongoDB test instance
- Tests on Node.js 20
- Uses MongoDB Docker service for integration tests
- Tools: Jest, Supertest, MongoDB Memory Server
- Purpose: Identifies security vulnerabilities and outdated dependencies
- Actions:
- Runs
npm auditon both client and server - Reports outdated packages
- Fails on moderate+ security issues
- Runs
- Tools: npm audit
- Purpose: Ensures both apps can start and work together
- Actions:
- Installs all dependencies across the monorepo
- Tests that both client and server can start
- Validates development environment setup
- Dependencies: Requires all previous jobs to pass
- Purpose: Automated deployment to Ubuntu VPS
- Trigger: Only after CI pipeline completes successfully on
mainbranch - Actions:
- Connects to VPS via SSH
- Creates timestamped backup of current deployment
- Pulls latest code from GitHub
- Installs/updates dependencies
- Builds client application
- Restarts PM2 backend service
- Restarts Apache reverse proxy
- Performs health check
- Provides deployment summary
- Cleans up old backups (keeps last 5)
- Tools: SSH, PM2, Apache2, curl
- Target: https://flowfocus.bestoneclinic.com
VPS_HOST- VPS hostname/IPVPS_USER- VPS usernameVPS_SSH_PRIVATE_KEY- SSH private key content for deployment
- Navigate to GitHub repository Settings → Secrets and variables → Actions
- Add each secret with the exact names above
- Ensure SSH key is properly formatted with headers and footers
- Location:
.github/workflows/ci.ymland.github/workflows/deploy.yml - Purpose: Separated CI and CD pipeline definitions
GitHub Actions (CI) → GitHub Actions (CD) → Ubuntu VPS
↓
/var/www/flowfocus/
├── client/ (React + Vite)
├── server/ (Express + PM2)
└── Apache Reverse Proxy
- Location:
.commitlintrc.json - Purpose: Validates conventional commit format
- Allowed Types:
feat,fix,docs,style,refactor,test,chore,ci,perf,revert - Allowed Scopes: Matches project structure (client, server, docs, etc.)
- ✅ Code Quality & Linting
- ✅ Test Frontend (Node.js 20)
- ✅ Test Backend (Node.js 20)
- ✅ Security Audit
- ✅ Integration Check
- ✅ Deploy to Production (only after CI passes)
- Early Issue Detection: Catches problems before they reach main branches
- Consistent Code Quality: Automated formatting and linting enforcement
- Standardized Environment: Validates functionality on Node.js 20
- Security Awareness: Regular dependency vulnerability scanning
- Automated Deployment: Zero-touch deployment to production
- Consistent Deployments: Same process every time
- Rollback Capability: Automated backups for quick recovery
- Health Monitoring: Automatic health checks post-deployment
- Reduced Downtime: Fast, automated deployment process
- Faster CI: CI pipeline runs quickly without deployment overhead
- Focused Workflows: Each pipeline has a clear, single responsibility
- Better Debugging: Easier to troubleshoot CI vs deployment issues
- Flexible Deployment: Can deploy manually without re-running CI
- Push to main → Triggers CI pipeline
- CI Pipeline → All quality checks must pass
- CD Pipeline → Automatically triggered if CI succeeds
- Backup → Current version backed up with timestamp
- Update → Latest code pulled from GitHub
- Build → Dependencies installed, client built
- Restart → PM2 backend and Apache restarted
- Health Check → Site availability verified
- Cleanup → Old backups removed (keeps last 5)
- Summary → Deployment status reported
- Navigate to Actions tab in GitHub
- Select "Deploy to Production"
- Click "Run workflow"
- Select
mainbranch - Click "Run workflow"
Push any change to the main branch and both pipelines will run automatically.
# Check code formatting
npm run format -- --check
# Lint client code
cd client && npm run lint
# Run all tests
npm test
# Security audit
cd client && npm audit
cd ../server && npm audit# SSH into VPS
ssh user@vps_host
# Check PM2 status
sudo pm2 list
# Check Apache status
sudo systemctl status apache2
# View deployment logs
sudo journalctl -f
# Check recent backups
ls -la /var/www/flowfocus-backup-*- Build success/failure rates for all branches
- Test coverage and performance
- Security vulnerability trends
- Lint and formatting compliance
- Deployment success/failure rates
- Deployment duration trends
- Health check response times
- Backup creation verification
- Site availability (automated health checks)
- PM2 process status
- Apache server status
- Disk space usage (for backups)
# Run tests locally
cd client && npm test
cd ../server && npm test# Fix formatting
npm run format
# Check linting
cd client && npm run lintError: "Permission denied" or "Host key verification failed"
Solution:
# Verify SSH key works
ssh -T git@github.com
ssh user@vps_hostError: "Process 'flowfocus-backend' not found"
Solution:
# On VPS, restart PM2 manually
cd /var/www/flowfocus
sudo pm2 restart flowfocus-backend
sudo pm2 logs flowfocus-backendError: Site returns 500 or doesn't respond
Solution:
# Check Apache status and logs
sudo systemctl status apache2
sudo journalctl -u apache2 -f
sudo systemctl restart apache2If deployment fails, rollback can be performed:
# SSH into VPS
ssh user@vps_host
# Find latest backup
ls -la /var/www/flowfocus-backup-*
# Restore backup (replace with actual backup name)
sudo rm -rf /var/www/flowfocus
sudo mv /var/www/flowfocus-backup-YYYYMMDD-HHMMSS /var/www/flowfocus
# Restart services
sudo pm2 restart flowfocus-backend
sudo systemctl restart apache2When contributing to this project:
- Follow Conventional Commits: Use the established format and scopes
- Ensure CI Passes: All CI checks must be green before merging
- Test Thoroughly: Both local and staging environments
- Monitor Deployments: Check deployment status after merge to main
- Staging Environment: Deploy to staging before production
- Blue-Green Deployment: Zero-downtime deployments
- Database Migrations: Automated schema updates
- Performance Monitoring: Response time and error tracking
- Slack/Discord Integration: Deployment notifications
- Environment Variables Management: Secure config deployment
- Multi-environment Support: Dev, staging, and production environments
This separated CI/CD pipeline provides a professional, scalable approach that follows industry best practices while maintaining high standards for code quality and deployment reliability.