This guide provides step-by-step instructions to deploy the LearnMate application (Frontend + Backend + AI Service + MongoDB) to a production environment.
Before you begin, ensure you have the following installed on your deployment server:
- Docker & Docker Compose (Recommended method)
- Node.js v18+ & npm (Only for manual deployment)
- Python 3.9+ (Only for manual deployment)
- Git
- A MongoDB Atlas Cluster (Recommended for persistence) or a local MongoDB instance.
This is the easiest way to deploy. It containerizes the Backend and AI Service, and orchestrates them with your database.
git clone https://github.com/dipak0000812/learnmate-2.0.git
cd learnmate-2.0Create a .env file in the root directory with your production secrets:
# General
NODE_ENV=production
PORT=5000
# Database
MONGO_URI=mongodb+srv://<your_user>:<your_password>@cluster0.mongodb.net/learnmate_prod
# Authentication
JWT_SECRET=your_super_secure_random_string_here
JWT_EXPIRES_IN=7d
# Frontend URL (For CORS)
FRONTEND_URL=https://your-frontend-domain.com
# AI Service (Python)
AI_SERVICE_URL=http://ai-service:5001
AI_API_KEY=your_internal_ai_service_key
GEMINI_API_KEY=your_google_gemini_api_key
# Email Service (Gmail SMTP)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_app_specific_passworddocker-compose up --build -d--build: Rebuilds the images.-d: Runs in detached mode (background).
Check if containers are running:
docker-compose psYou should see backend and ai-service up and running.
For the frontend, it is best to use a Static Site Host like Vercel or Netlify.
Ensure your latest code is on GitHub.
- Go to Vercel.com -> Add New Project.
- Import your
learnmate-2.0repository. - Root Directory: Set this to
learnmate-frontend. - Environment Variables:
REACT_APP_API_URL:https://your-backend-server-ip:5000(or your domain)
- Build Command:
npm run build - Output Directory:
build - Click Deploy.
If you prefer running directly on a VPS (like a DigitalOcean Droplet or AWS EC2) without Docker:
Install PM2 to keep your Node.js and Python apps running forever.
npm install -g pm2cd learnmate-backend
npm install --production
pm2 start app.js --name "learnmate-backend"cd AI-Model
pip install -r requirements.txt
pm2 start app.py --name "learnmate-ai" --interpreter python3You can serve the build folder using Nginx or a simple HTTP server.
cd learnmate-frontend
npm install
npm run build
npm install -g serve
pm2 start "serve -s build -l 3000" --name "learnmate-frontend"- Secure Headers: Ensure Helmet is active on Backend.
- Rate Limiting: Verify Nginx or Backend rate limits are working.
- Firewall: allow ports
80,443(Frontend) and5000(Backend API). - Domain: Set up A Records for your domain to point to your VPS IP.
- SSL: Use Certbot to enable HTTPS (Critical for PWA features).
Socket.io Connection Fails?
- Ensure your
REACT_APP_API_URLpoints to the backend (e.g.https://api.yourdomain.com). - Ensure your VPS firewall allows the WebSocket connection.
AI Errors?
- Check logs:
docker-compose logs ai-service - Verify
GEMINI_API_KEYis valid.
Build Errors?
- Ensure
CI=falseenvironment variable is set if warnings are treated as errors.
Generated by LearnMate Team