Smart Library Docs

Deployment

Production deployment guide for the SLMS frontend and backend — Vercel configuration, environment variables, and deployment architecture.

Deployment

Both the frontend and backend are configured for deployment on Vercel as serverless functions. Each application has its own vercel.json configuration file.

Architecture

┌──────────────────────────────┐     ┌──────────────────────────────┐
│     Frontend (Vercel)        │     │     Backend (Vercel)         │
│  Next.js 16 App              │────▶│  Express.js Serverless       │
│  slms.anandverse.qzz.io      │     │  api.slms.anandverse.qzz.io  │
└──────────────────────────────┘     └──────────┬───────────────────┘


                                     ┌──────────────────────────────┐
                                     │    MongoDB Atlas (Cloud)     │
                                     └──────────────────────────────┘

Live URLs:


Backend Deployment

Vercel Configuration

File: backend/vercel.json

{
  "version": 2,
  "builds": [
    {
      "src": "server.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/server.js"
    }
  ]
}

Key details:

  • Uses @vercel/node builder to run server.js as a serverless function
  • All incoming requests are routed to the Express app via the catch-all route
  • The server conditionally listens only in non-production (process.env.NODE_ENV !== 'production'), since Vercel handles routing

Backend Environment Variables

Set these in the Vercel dashboard under Settings → Environment Variables:

VariableRequiredDescription
DATABASE_URLMongoDB Atlas connection string
AUTH_SECRET or JWT_SECRETSecret key for JWT signing
NODE_ENVSet to production
SMTP_HOSTSMTP server hostname (default: smtp.gmail.com)
SMTP_PORTSMTP port (default: 587)
SMTP_USERSMTP username/email
SMTP_PASSSMTP password or app password

Frontend Deployment

Vercel Configuration

File: frontend/vercel.json

{
  "framework": "nextjs"
}

Next.js is auto-detected by Vercel. No additional build configuration is needed.

Frontend Environment Variables

Set these in the Vercel dashboard:

VariableRequiredDescription
NEXT_PUBLIC_API_URLFull URL to the deployed backend (e.g., https://slms-backend.vercel.app/api/v1)
AUTH_SECRETNextAuth.js secret for session encryption
MONGODB_URIMongoDB connection string (used by NextAuth for the setup flow)
NEXTAUTH_URLCanonical URL of the frontend (e.g., https://slms.vercel.app)

Deployment Checklist

Pre-Deployment

  • Ensure MongoDB Atlas cluster is provisioned and connection string is ready
  • Set all required environment variables in Vercel
  • Verify CORS is configured to allow the frontend origin on the backend
  • Test the health check endpoint after deploying the backend

Post-Deployment Verification

  1. Backend Health Check:

    curl https://your-backend.vercel.app/health
    # Expected: { "status": "ok", "message": "SLMS API is running" }
  2. Frontend Smoke Test:

    • Navigate to the deployed frontend URL
    • Verify the login page loads
    • Test login with admin credentials
    • Confirm role-based redirect works

Local Development vs Production

AspectLocalProduction
Backend URLhttp://localhost:5000/api/v1https://api.slms.anandverse.qzz.io/api/v1
Frontend URLhttp://localhost:3000https://slms.anandverse.qzz.io
Docs URLhttp://localhost:3000/docshttps://docs.slms.anandverse.qzz.io/docs
Server Listeningapp.listen() runsVercel handles routing
HTTPSNot enforcedEnforced via src/app.js middleware
Rate LimitingActiveActive (15-min window, 100 req/IP)

Important Notes

  • Cron Jobs: Vercel serverless functions do not natively support persistent cron jobs. The fine calculator cron job (node-cron) starts when the src/app.js module is loaded but may not run reliably in a cold-start serverless environment. Consider using Vercel Cron Jobs or an external scheduler for production.

  • Cold Starts: Serverless functions may have cold start delays. The MongoDB connection is cached across invocations within the same function instance.

  • File Uploads: The current deployment does not include file upload handling. Cover images referenced in the Book model use external URLs.

On this page