# Backend
cd backend
npm install
npm run dev
# Frontend (new terminal)
cd frontend
npm install
npm run devVisit http://localhost:3000
- Docker installed
- Docker Compose installed
Create backend/Dockerfile:
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY src ./src
EXPOSE 5000
CMD ["npm", "start"]Create frontend/Dockerfile:
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM node:18-alpine
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./
EXPOSE 3000
CMD ["npm", "start"]Create docker-compose.yml:
version: '3.8'
services:
mongodb:
image: mongo:5.0
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: password
volumes:
- mongo_data:/data/db
backend:
build: ./backend
ports:
- "5000:5000"
environment:
MONGODB_URI: mongodb://admin:password@mongodb:27017/investment-platform
JWT_SECRET: your_jwt_secret
NODE_ENV: production
depends_on:
- mongodb
restart: unless-stopped
frontend:
build: ./frontend
ports:
- "3000:3000"
environment:
NEXT_PUBLIC_API_URL: http://backend:5000/api
depends_on:
- backend
restart: unless-stopped
volumes:
mongo_data:docker-compose up -d# Install Heroku CLI
# Login
heroku login
# Create app
heroku create your-app-name
# Set environment variables
heroku config:set JWT_SECRET=your_secret
heroku config:set MONGODB_URI=your_mongodb_uri
# Deploy
git push heroku main# Install Vercel CLI
npm i -g vercel
# Deploy
vercel
# Set environment variables in dashboard
# NEXT_PUBLIC_API_URL = your_backend_url# SSH into instance
ssh -i keypair.pem ubuntu@your-instance-ip
# Install Node.js
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Install MongoDB
sudo apt-get install -y mongodb
# Clone repo
git clone your-repo-url
# Install & run
cd backend
npm install
npm run build
npm start# Build
cd frontend
npm run build
# Deploy to S3
aws s3 sync .next/export s3://your-bucket/
# Invalidate CloudFront
aws cloudfront create-invalidation --distribution-id ID --paths "/*"upstream backend {
server localhost:5000;
}
server {
listen 80;
server_name api.yourdomain.com;
location / {
proxy_pass http://backend;
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;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
}
}upstream frontend {
server localhost:3000;
}
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://frontend;
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;
}
}# Install Certbot
sudo apt-get install certbot python3-certbot-nginx
# Get certificate
sudo certbot certonly --nginx -d yourdomain.com -d api.yourdomain.com
# Auto-renewal
sudo systemctl enable certbot.timer
sudo systemctl start certbot.timerUpdate Nginx config:
server {
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
# ... rest of config
}
server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri;
}# Install PM2
npm install -g pm2
# Create ecosystem config
cat > ecosystem.config.js << EOF
module.exports = {
apps: [{
name: 'investment-backend',
script: './src/server.js',
instances: 4,
exec_mode: 'cluster',
env: {
NODE_ENV: 'production'
}
}]
};
EOF
# Start
pm2 start ecosystem.config.js
# Monitor
pm2 monit
# Save
pm2 save
pm2 startup# Backup
mongodump --uri "mongodb://user:pass@host:27017/investment-platform"
# Restore
mongorestore --uri "mongodb://user:pass@host:27017" dump/
# Automated backup (cron)
0 2 * * * mongodump --uri "mongodb://user:pass@host:27017" --out /backups/mongo-$(date +\%Y\%m\%d)pm2 web # Visit http://localhost:9615# Elasticsearch, Logstash, Kibana
docker-compose -f elk-compose.yml up// backend/src/logger.js
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: 'error.log', level: 'error' }),
new winston.transports.File({ filename: 'combined.log' })
]
});
module.exports = logger;// Add to User model
userSchema.index({ email: 1 });
portfolioSchema.index({ userId: 1 });
transactionSchema.index({ userId: 1, createdAt: -1 });npm install redis# Analyze bundle
npm run build -- --analyzeCreate .github/workflows/deploy.yml:
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '18'
- name: Install & Test
run: |
cd backend && npm install && npm test
cd ../frontend && npm install && npm run build
- name: Deploy to Heroku
uses: AkhileshNS/heroku-deploy@v3.12.12
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
heroku_app_name: "your-app"
heroku_email: "your-email@example.com"- SSL/TLS certificate installed
- Database backups configured
- Monitoring and alerts set up
- Log rotation configured
- CDN enabled
- Email service configured
- 2FA enabled
- Rate limiting enabled
- CORS configured correctly
- Environment variables secured
- Database credentials rotated
- Security headers verified
- API documentation deployed
- Status page created
- Incident response plan ready
Deployment complete! Monitor your application regularly. 🚀