Skip to content

Repository files navigation

CertFlow — Next.js + MongoDB + Docker

Tech Stack

LayerTech
FullstackNext.js 14 App Router
DatabaseMongoDB Atlas (or self-hosted MongoDB 7)
AuthJWT (httpOnly cookie + Bearer header)
PaymentsRazorpay
PDF/Imagecanvas + pdfkit + sharp
EmailNodemailer (SMTP)
DeployDocker + Nginx on any VPS

🚀 Quick Start (Local Dev)

# 1. Install dependencies
npm install
# 2. Configure environment
cp .env.example .env.local
# Edit .env.local with your values (MongoDB URI, SMTP, etc.)# 3. Seed database (creates admin user + default settings)
npm run seed
# 4. Start dev server
npm run dev
# → http://localhost:3000

🐳 Docker Deployment (VPS)

Prerequisites

  • VPS with Docker + Docker Compose installed
  • Domain pointed to your VPS IP
  • SSL certificate (see below)

Step 1 — Clone & configure

git clone https://github.com/yourorg/certflow.git
cd certflow
cp .env.example .env
nano .env # Fill in all values

Step 2 — SSL certificate

# Using Certbot (recommended)
apt install certbot
certbot certonly --standalone -d yourdomain.com
# Copy certs to nginx/ssl/
mkdir -p nginx/ssl
cp /etc/letsencrypt/live/yourdomain.com/fullchain.pem nginx/ssl/
cp /etc/letsencrypt/live/yourdomain.com/privkey.pem nginx/ssl/

Step 3 — Update Nginx config

Edit nginx/certflow.conf:

server_name yourdomain.com www.yourdomain.com;

Step 4 — Deploy

# Build and start everything
docker-compose up -d --build
# Seed the database
docker-compose exec app node scripts/seed.js
# View logs
docker-compose logs -f app

Step 5 — Verify

https://yourdomain.com → Landing page
https://yourdomain.com/admin → Admin panel (use seeded credentials)
https://yourdomain.com/api/health → {"status":"ok","db":"connected"}

🌿 Using MongoDB Atlas (Recommended)

  1. Go to cloud.mongodb.com → Create free cluster
  2. Database Access → Add user with password
  3. Network Access → Allow 0.0.0.0/0 (or your VPS IP)
  4. Connect → Drivers → Copy connection string
  5. Set in .env:
    MONGODB_URI=mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/certflow
    
  6. Comment out the mongo service in docker-compose.yml (you don't need local MongoDB)

⚙️ Key Environment Variables

NEXT_PUBLIC_APP_URL=https://yourdomain.comMONGODB_URI=mongodb+srv://...JWT_SECRET=<random 64-char string>RAZORPAY_KEY_ID=rzp_live_xxxRAZORPAY_SECRET=xxxSMTP_HOST=smtp.sendgrid.netSMTP_PORT=587SMTP_USER=apikeySMTP_PASS=SG.xxxSMTP_FROM_EMAIL=noreply@yourdomain.com

👤 Creating Admin Account

Run the seed script after deployment:

# Local
ADMIN_EMAIL=you@domain.com ADMIN_PASSWORD=SecurePass123! npm run seed
# Docker
docker-compose exec app node scripts/seed.js

Or promote any existing user in MongoDB:

db.users.updateOne({email: "you@domain.com"},{$set: {plan: "admin",certsLimit: 999999}})

📁 File Storage

By default, files are stored in the uploads/ directory (mounted as a Docker volume).

For production at scale, switch to S3:

  1. npm install @aws-sdk/client-s3 @aws-sdk/lib-storage
  2. Replace fs.writeFileSync calls in src/app/api/templates/route.js and src/lib/certGenerator.js with S3 uploads
  3. Return S3 URLs instead of local paths

🔒 Security Checklist

  • JWT_SECRET = random 64+ char string
  • ENCRYPTION_KEY = random 32 char string
  • Razorpay set to live mode in admin panel
  • Remove MongoDB port exposure (27017) from docker-compose.yml in production
  • Set NEXT_PUBLIC_APP_URL to your real domain
  • Renew SSL certs (Certbot auto-renews if configured)

📋 API Routes Reference

MethodRouteAuthDescription
POST/api/auth/registerRegister new user
POST/api/auth/loginLogin, returns JWT
POST/api/auth/googleGoogle OAuth
GET/api/users/meCurrent user profile
GET/api/users/statsDashboard stats
GET/api/templatesList user templates
POST/api/templatesUpload template
GET/api/campaignsList campaigns
POST/api/campaignsCreate + start campaign
GET/api/campaigns/[id]Campaign detail + stats
GET/api/campaigns/[id]/exportExport CSV
GET/api/certificatesList certificates
POST/api/certificates/[id]/resendResend email
GET/api/public/verify/[certId]Public verification
POST/api/payments/create-orderCreate Razorpay order
POST/api/payments/verifyVerify payment + upgrade
GET/api/admin/overviewAdminPlatform stats
GET/api/admin/usersAdminList users
PUT/api/admin/usersAdminUpdate user
GET/api/admin/settingsAdminGet settings
PUT/api/admin/settingsAdminUpdate settings
GET/api/healthHealth check

🔄 Updating Production

git pull
docker-compose up -d --build app
docker-compose logs -f app

© 2025 CertFlow

About

THIS IS THE DIRECTORY GOING TO USE FOR MY OWN LOCAL SAAS _test

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages