DEV Community

Daniel Ioni
Daniel Ioni

Posted on

🚀 MyZubster Backend: Complete Setup & Deployment Guide

🚀 MyZubster Backend: Complete Setup & Deployment Guide

A comprehensive guide to setting up, developing, and deploying the MyZubster backend
📋 Table of Contents

Project Overview

Prerequisites

Local Development Setup

Environment Configuration

Database Models

API Routes

AI Integration (DeepSeek)

Payment System (Mock)

Deployment on VPS

PM2 Management

Troubleshooting

Next Steps
Enter fullscreen mode Exit fullscreen mode

📖 Project Overview

MyZubster is an open-source peer-to-peer skill-sharing platform that connects neighbors to exchange services with Monero (XMR) payments. The backend is built with:

Node.js (v20+) with Express

MongoDB with Mongoose ODM

DeepSeek API for AI features

Monero for private payments

PM2 for process management
Enter fullscreen mode Exit fullscreen mode

🛠️ Prerequisites
On Your Local Machine:

Node.js v20+ installed

MongoDB installed and running

Git installed

A GitHub account (for pushing code)

A DeepSeek API key (optional, for AI features)
Enter fullscreen mode Exit fullscreen mode

On the VPS:

A Linux server (Ubuntu 22.04 LTS recommended)

Root access or sudo privileges

SSH access to the server

A domain name (optional, but recommended for production)
Enter fullscreen mode Exit fullscreen mode

💻 1. Local Development Setup
1.1 Clone the Repository
bash

git clone https://github.com/DanielIoni-creator/MyZubsterGateway.git
cd MyZubsterGateway

1.2 Install Dependencies
bash

npm install

1.3 Create the .env File
bash

cp .env.example .env

or manually create it

nano .env

Add the following variables:
env

PORT=3000
MONGODB_URI=mongodb://localhost:27017/myzubster
JWT_SECRET=your_super_secret_key_here
NODE_ENV=development

DeepSeek AI

DEEPSEEK_API_KEY=your_deepseek_api_key
DEEPSEEK_MODEL=deepseek-chat
DEEPSEEK_API_URL=https://api.deepseek.com/v1/chat/completions

Monero (for later)

MONERO_RPC_URL=http://localhost:18082/json_rpc
MONERO_WALLET_ADDRESS=
MONERO_VIEW_KEY=
MONERO_NETWORK=testnet

Payment Mode (mock | real)

PAYMENT_MODE=mock

1.4 Start MongoDB
bash

On Ubuntu/Debian

sudo systemctl start mongodb

On macOS

brew services start mongodb-community

On Windows (as Administrator)

net start MongoDB

1.5 Start the Server
bash

node server.js

The server should start on http://localhost:3000. Test with:
bash

curl http://localhost:3000/api/health

Expected response:
json

{
"status": "OK",
"message": "MyZubster Gateway is running!",
"timestamp": "2026-07-24T..."
}

🔧 2. Environment Configuration
2.1 Production .env File

Create a .env file for production on the VPS:
bash

nano .env

env

PORT=3001
MONGODB_URI=mongodb://localhost:27017/myzubster
JWT_SECRET=fd2cb60aba88af3ffc3832c8354cd1c8d4e0a9bb47dcd0f105ecaaa11dc23831801e214087c5745ec8ba675c43b05f387222714b047253a4cc405e43ac395f92
NODE_ENV=production

DeepSeek AI

DEEPSEEK_API_KEY=your_production_deepseek_api_key
DEEPSEEK_MODEL=deepseek-chat
DEEPSEEK_API_URL=https://api.deepseek.com/v1/chat/completions

Monero (mainnet for production)

MONERO_RPC_URL=http://localhost:18082/json_rpc
MONERO_WALLET_ADDRESS=your_monero_wallet_address
MONERO_VIEW_KEY=your_monero_view_key
MONERO_NETWORK=mainnet

Payment Mode

PAYMENT_MODE=real

Frontend

FRONTEND_URL=https://myzubster.com

2.2 Generate a Secure JWT Secret
bash

node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"

Copy the output and use it as your JWT_SECRET.
2.3 .gitignore Configuration

Ensure .env and other sensitive files are excluded from Git:
gitignore

Environment variables

.env
.env.local
.env.*.local
.env.production
.env.development

Node modules

node_modules/

Logs

.log
npm-debug.log

OS files

.DS_Store
Thumbs.db

IDE

.vscode/
.idea/

Temp files

*.swp
*.save

📊 3. Database Models
3.1 Existing Models
Model File Purpose
User models/User.js User accounts, authentication
Order models/Order.js Service orders between users
3.2 New Models Added
Model File Purpose
Skill models/Skill.js Skills/competencies users offer
Offer models/Offer.js Active service offers with availability
Request models/Request.js Service requests from users
Transaction models/Transaction.js Payment and credit history
Review models/Review.js User reviews and ratings
3.3 Model Example: Skill.js
javascript

const mongoose = require('mongoose');

const SkillSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
title: {
type: String,
required: true,
trim: true,
maxlength: 100
},
description: {
type: String,
required: true,
maxlength: 2000
},
category: {
type: String,
required: true,
enum: [
'Manutenzione', 'Bellezza', 'Informatica',
'Giardinaggio', 'Pulizie', 'Insegnamento',
'Arte', 'Salute', 'Altro'
]
},
zone: {
type: String,
required: true
},
pricePerHour: {
type: Number,
default: 0
},
fixedPrice: {
type: Number,
default: 0
},
pricingType: {
type: String,
enum: ['hourly', 'fixed'],
default: 'hourly'
},
isActive: {
type: Boolean,
default: true
}
}, {
timestamps: true
});

SkillSchema.index({ user: 1 });
SkillSchema.index({ category: 1 });
SkillSchema.index({ zone: 1 });
SkillSchema.index({ title: 'text', description: 'text' });

module.exports = mongoose.model('Skill', SkillSchema);

🔌 4. API Routes
4.1 All Available Routes
Route File Endpoints
Auth routes/auth.js /api/auth/register, /api/auth/login
Skills routes/skills.js /api/skills (CRUD)
Offers routes/offers.js /api/offers (CRUD)
Requests routes/requests.js /api/requests (CRUD)
Orders routes/orders.js /api/orders (CRUD)
Payments routes/payments.js /api/payments/create, /api/payments/status/:id
Transactions routes/transactions.js /api/transactions (CRUD)
Reviews routes/reviews.js /api/reviews (CRUD)
AI routes/ai.js /api/ai/matchmaking, /api/ai/chat, /api/ai/generate-description
4.2 Example API Request: Create a Skill
bash

curl -X POST http://localhost:3000/api/skills \
-H "Content-Type: application/json" \
-d '{
"user": "USER_ID_HERE",
"title": "Professional Plumber",
"description": "Fixing pipes, faucets, and boilers",
"category": "Manutenzione",
"zone": "Rimini Centro",
"pricePerHour": 0.5
}'

4.3 Example API Request: AI Matchmaking
bash

curl -X POST http://localhost:3000/api/ai/matchmaking \
-H "Content-Type: application/json" \
-d '{
"request": "Looking for a plumber to fix my boiler, Rimini Centro area"
}'

🤖 5. AI Integration (DeepSeek)
5.1 Services

The AI functionality is implemented in services/aiService.js:
javascript

const aiService = require('../services/aiService');

// Matchmaking
const professionals = await aiService.findBestMatch(userRequest, professionalsList);

// Chatbot
const response = await aiService.chatAssistant(userMessage);

// Generate Description
const description = await aiService.generateDescription(title, category, zone, price);

5.2 AI Features

Matchmaking Intelligente: Analyzes user requests and ranks professionals by relevance

Chatbot Assistant: Answers FAQs and helps with navigation

Description Generator: Creates professional service descriptions
Enter fullscreen mode Exit fullscreen mode

5.3 Getting a DeepSeek API Key

Go to platform.deepseek.com

Create an account or log in

Navigate to API Keys

Generate a new key

Copy the key and add it to your .env file
Enter fullscreen mode Exit fullscreen mode

💳 6. Payment System (Mock)
6.1 Mock Payment Service

Located in services/paymentService.js, the mock service:

Generates random payment IDs

Simulates address and QR code

Auto-confirms payments after 5 seconds

Stores payments in memory
Enter fullscreen mode Exit fullscreen mode

6.2 Switching to Real Payments

To enable real Monero payments, set in .env:
env

PAYMENT_MODE=real

Then implement services/realPaymentService.js using Monero RPC.
6.3 Payment API Endpoints
javascript

POST /api/payments/create
Body: { orderId, amount, currency }
Response: { success: true, data: { id, address, qrCode, amount, status } }

GET /api/payments/status/:paymentId
Response: { success: true, data: { status, confirmedAt, ... } }

POST /api/payments/confirm/:paymentId
Response: { success: true, data: { status: 'confirmed', ... } }

☁️ 7. Deployment on VPS
7.1 Initial VPS Setup

Connect to your VPS:
bash

ssh root@your_vps_ip

Update the system:
bash

apt update && apt upgrade -y

7.2 Install Node.js (v20+)
bash

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
apt install -y nodejs
node -v # Should show v20.x

7.3 Install MongoDB
bash

Add MongoDB GPG key

wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -

Add MongoDB repository

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

Install MongoDB

apt update
apt install -y mongodb-org

Start MongoDB

systemctl start mongod
systemctl enable mongod
systemctl status mongod

7.4 Install Git and PM2
bash

apt install -y git
npm install -g pm2

7.5 Clone the Repository on VPS
bash

git clone https://github.com/DanielIoni-creator/MyZubsterGateway.git
cd MyZubsterGateway

7.6 Configure Git Authentication

Option A: Using HTTPS with Personal Access Token
bash

git remote set-url origin https://YOUR_USERNAME@github.com/DanielIoni-creator/MyZubsterGateway.git

Option B: Using SSH
bash

ssh-keygen -t ed25519 -C "your-email@example.com"
cat ~/.ssh/id_ed25519.pub

Copy the key, add it to GitHub > Settings > SSH Keys

7.7 Install Dependencies and Configure .env
bash

npm install
nano .env

Paste your production .env content and save.
7.8 Start the Server with PM2
bash

PORT=3001 node server.js # Test manually first

If it works, Ctrl+C, then:

pm2 start server.js --name myzubster-gateway -- --PORT=3001
pm2 save
pm2 status

7.9 Configure PM2 Startup
bash

pm2 startup

Run the command that PM2 shows (e.g., sudo env PATH=...)

🔄 8. PM2 Management
8.1 Basic Commands
bash

List all processes

pm2 list

Start a process

pm2 start server.js --name myzubster-gateway -- --PORT=3001

Stop a process

pm2 stop myzubster-gateway

Restart a process

pm2 restart myzubster-gateway

Delete a process

pm2 delete myzubster-gateway

Save current process list

pm2 save

Show logs

pm2 logs myzubster-gateway
pm2 logs myzubster-gateway --lines 50

8.2 Monitoring
bash

Real-time monitoring

pm2 monit

Process status

pm2 status

🐛 9. Troubleshooting
9.1 Port Already in Use (EADDRINUSE)

Find the process:
bash

lsof -i :3000
ss -tulpn | grep 3000
ps aux | grep node

Kill the process:
bash

kill -9

Or kill all Node processes

pkill -9 node

9.2 Git Authentication Failed

Solution 1: Use Personal Access Token

Generate a token on GitHub (Settings → Developer settings → Personal access tokens)

Use the token as password when prompted
Enter fullscreen mode Exit fullscreen mode

Solution 2: Change remote URL
bash

git remote set-url origin https://YOUR_USERNAME@github.com/DanielIoni-creator/MyZubsterGateway.git

9.3 MongoDB Connection Issues

Check if MongoDB is running:
bash

systemctl status mongodb
systemctl start mongodb
systemctl enable mongodb

Check the MongoDB URI in .env:
env

MONGODB_URI=mongodb://localhost:27017/myzubster

9.4 PM2 Process Not Found
bash

Start the process

pm2 start server.js --name myzubster-gateway -- --PORT=3001
pm2 save

Or kill and restart all

pm2 kill
pm2 start server.js --name myzubster-gateway -- --PORT=3001
pm2 save

9.5 Duplicate Schema Index Warnings (Mongoose)

Fix: Remove duplicate index definitions in models/User.js:
javascript

// Remove unique: true from schema fields
username: { type: String, required: true, trim: true }
email: { type: String, required: true, trim: true, lowercase: true }

// Keep only index definitions
UserSchema.index({ email: 1 }, { unique: true });
UserSchema.index({ username: 1 }, { unique: true });

Clear old indexes in the database:
bash

node cleanup.js

9.6 Server Not Responding

Check if the server is running:
bash

pm2 status
lsof -i :3001

Check logs:
bash

pm2 logs myzubster-gateway

Test the API:
bash

curl http://localhost:3001/api/health

🔗 10. Next Steps
10.1 Install Nginx (Reverse Proxy)
bash

apt install -y nginx

Create a configuration:
bash

nano /etc/nginx/sites-available/myzubster

nginx

server {
listen 80;
server_name api.myzubster.com; # Replace with your domain

location / {
    proxy_pass http://localhost:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
Enter fullscreen mode Exit fullscreen mode

}

Enable the site:
bash

ln -s /etc/nginx/sites-available/myzubster /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx

10.2 Enable HTTPS with Let's Encrypt
bash

apt install -y certbot python3-certbot-nginx
certbot --nginx -d api.myzubster.com

10.3 Connect Marketplace (Frontend)

Build your React/Next.js frontend

Configure the API base URL in the frontend:
text

API_BASE_URL=https://api.myzubster.com

Deploy the frontend to another VPS, Netlify, or Vercel
Enter fullscreen mode Exit fullscreen mode

10.4 Complete Monero Integration

Install Monero CLI tools

Create a wallet for the application

Implement realPaymentService.js

Test on testnet first, then switch to mainnet
Enter fullscreen mode Exit fullscreen mode

10.5 Testing End-to-End Flow

Register a user → /api/auth/register

Login → /api/auth/login

Create a skill → /api/skills

Create an offer → /api/offers

Create a request → /api/requests

Create an order → /api/orders

Create a payment → /api/payments/create

Check payment status → /api/payments/status/:id

Create a review → /api/reviews
Enter fullscreen mode Exit fullscreen mode

📦 11. Quick Reference: Useful Commands
Local Development
bash

Start MongoDB

sudo systemctl start mongodb

Start server

node server.js

Test health

curl http://localhost:3000/api/health

VPS Management
bash

Connect to VPS

ssh root@your_vps_ip

Navigate to project

cd ~/MyZubsterGateway

Pull latest changes

git pull origin main

Install dependencies

npm install

Restart with PM2

pm2 restart myzubster-gateway

View logs

pm2 logs myzubster-gateway

Check status

pm2 status

Database
bash

Connect to MongoDB shell

mongosh

Show databases

show dbs

Use MyZubster database

use myzubster

Show collections

show collections

Exit

exit

🌟 12. Conclusion

Congratulations! 🎉 You now have a fully functional MyZubster backend with:

✅ Complete API with 10+ routes

✅ AI integration (DeepSeek)

✅ Mock payment system

✅ 5 new database models

✅ Production deployment on VPS

✅ PM2 process management

✅ Environment configuration
Enter fullscreen mode Exit fullscreen mode

Key Achievements:
Feature Status
Server ✅ Online on port 3001
Database ✅ Connected (MongoDB)
API ✅ Responding (health check OK)
AI Services ✅ Integrated (matchmaking, chatbot, generation)
Payments ✅ Mock service active
PM2 ✅ Configured and running
Code ✅ Pushed to GitHub
🤝 Contributing

We welcome contributions! Here's how you can help:

Top comments (0)