Skip to content

Latest commit

 

History

History
156 lines (117 loc) · 4.21 KB

File metadata and controls

156 lines (117 loc) · 4.21 KB

🚀 LearnMate 2.0 Deployment Guide

This guide provides step-by-step instructions to deploy the LearnMate application (Frontend + Backend + AI Service + MongoDB) to a production environment.


📋 Prerequisites

Before you begin, ensure you have the following installed on your deployment server:

  1. Docker & Docker Compose (Recommended method)
  2. Node.js v18+ & npm (Only for manual deployment)
  3. Python 3.9+ (Only for manual deployment)
  4. Git
  5. A MongoDB Atlas Cluster (Recommended for persistence) or a local MongoDB instance.

🛠️ Method 1: Docker Deployment (Recommended)

This is the easiest way to deploy. It containerizes the Backend and AI Service, and orchestrates them with your database.

1. Clone the Repository

git clone https://github.com/dipak0000812/learnmate-2.0.git
cd learnmate-2.0

2. Configure Environment Variables

Create 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_password

3. Build and Run containers

docker-compose up --build -d
  • --build: Rebuilds the images.
  • -d: Runs in detached mode (background).

4. Verify Services

Check if containers are running:

docker-compose ps

You should see backend and ai-service up and running.


🌐 Method 2: Host Frontend (Vercel / Netlify)

For the frontend, it is best to use a Static Site Host like Vercel or Netlify.

1. Push to GitHub

Ensure your latest code is on GitHub.

2. Connect to Vercel

  1. Go to Vercel.com -> Add New Project.
  2. Import your learnmate-2.0 repository.
  3. Root Directory: Set this to learnmate-frontend.
  4. Environment Variables:
    • REACT_APP_API_URL: https://your-backend-server-ip:5000 (or your domain)
  5. Build Command: npm run build
  6. Output Directory: build
  7. Click Deploy.

💻 Method 3: Manual Deployment (VPS)

If you prefer running directly on a VPS (like a DigitalOcean Droplet or AWS EC2) without Docker:

1. Process Manager (PM2)

Install PM2 to keep your Node.js and Python apps running forever.

npm install -g pm2

2. Setup Backend

cd learnmate-backend
npm install --production
pm2 start app.js --name "learnmate-backend"

3. Setup AI Service

cd AI-Model
pip install -r requirements.txt
pm2 start app.py --name "learnmate-ai" --interpreter python3

4. Setup Frontend (Serving Static Files)

You 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"

🛡️ Post-Deployment Checklist

  • Secure Headers: Ensure Helmet is active on Backend.
  • Rate Limiting: Verify Nginx or Backend rate limits are working.
  • Firewall: allow ports 80, 443 (Frontend) and 5000 (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).

❓ Troubleshooting

Socket.io Connection Fails?

  • Ensure your REACT_APP_API_URL points 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_KEY is valid.

Build Errors?

  • Ensure CI=false environment variable is set if warnings are treated as errors.

Generated by LearnMate Team