Skip to content

Nethmina01/subscription_Management_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Subscription Management System API

Automated Subscription Tracking & Email Reminder Backend

A production-ready backend API that helps users manage subscriptions and avoid unexpected renewals by sending automated email reminders before renewal dates, powered by serverless background workflows.

Built with Node.js, Express, MongoDB, and modern cloud-native services, following real-world backend engineering best practices.


✨ Why This Project Exists

Subscriptions are everywhere streaming platforms, SaaS tools, utilities but users often forget renewal dates and get charged unexpectedly.

This project solves that problem by:

  • Automatically tracking subscription renewal dates
  • Proactively notifying users before renewals happen
  • Running reminders reliably in the background
  • Remaining stable even if the API server restarts

The goal is predictability, transparency, and user trust.


🧠 What This System Does

  • Authenticates users securely using JWT
  • Allows users to create and manage subscriptions
  • Automatically calculates renewal dates
  • Triggers background workflows on subscription creation
  • Sends multiple email reminders before renewal
  • Protects APIs against bots and abuse
  • Scales cleanly using stateless APIs and serverless workflows

πŸ—οΈ System Architecture Overview

Client (Postman / Frontend)
β”‚
β–Ό
Express REST API
β”‚
β”œβ”€β”€ JWT Authentication
β”œβ”€β”€ Arcjet Security Layer
β”œβ”€β”€ Controllers
β”‚   β”œβ”€β”€ Auth
β”‚   β”œβ”€β”€ User
β”‚   β”œβ”€β”€ Subscription
β”‚   └── Workflow
β”‚
β”œβ”€β”€ MongoDB (Mongoose)
β”‚
β”œβ”€β”€ Upstash Workflow (QStash)
β”‚   └── Automated Email Reminders

Architectural Principles

  • Stateless API design
  • Separation of concerns
  • Fail-open third-party integrations
  • Asynchronous background processing
  • Environment-based configuration

πŸ” Authentication & Authorization

  • User sign-up and sign-in using JWT
  • Password hashing with bcrypt
  • Authorization middleware for protected routes
  • Token-based access control (Bearer tokens)

Example Authorization Header Authorization: Bearer <JWT_TOKEN>


πŸ“¦ Subscription Lifecycle

Subscription Creation

When a user creates a subscription:

  1. Input is validated
  2. Renewal date is automatically calculated
  3. Subscription status is determined (active / expired)
  4. Subscription is saved to the database
  5. A background workflow is triggered

Subscription Status

  • Active β†’ Renewal date is in the future
  • Expired β†’ Renewal date has passed

πŸ”” Automated Email Reminder System (Core Feature)

How It Works

  1. A subscription is created
  2. The system calculates the renewal date
  3. A serverless workflow is triggered via Upstash
  4. The workflow schedules reminders at:
    • 7 days before renewal
    • 5 days before renewal
    • 2 days before renewal
    • 1 day before renewal
  5. On each reminder date:
    • The workflow wakes up
    • An email notification is sent
  6. Users can renew or cancel in advance

Why Background Workflows?

Traditional approaches like setTimeout or cron jobs:

  • Fail on server restarts
  • Don’t scale reliably
  • Are hard to retry safely

Upstash Workflows solve this by:

  • Persisting workflow state
  • Sleeping in the cloud
  • Resuming execution reliably
  • Retrying failed steps automatically

πŸ” Background Workflow Responsibilities

  • Receive subscription ID payload
  • Fetch subscription data safely
  • Validate subscription state
  • Calculate reminder dates
  • Sleep until scheduled times
  • Trigger email delivery logic
  • Run independently of API uptime

🌐 API Design & Endpoints

Authentication

POST /api/v1/auth/sign-up POST /api/v1/auth/sign-in

Users

GET /api/v1/user/me GET /api/v1/user/:id

Subscriptions

POST /api/v1/subscription GET /api/v1/subscription/:userId

Workflows (Internal)

POST /api/v1/workflows/subscription/reminder

Workflow endpoints are not intended for public use and are invoked internally by Upstash.


πŸ“ Project Structure

subscriptionManagementSystem/
β”‚
β”œβ”€β”€ app.js                     # Application entry point
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ env.js                 # Environment configuration
β”‚   └── upstash.js             # Upstash workflow client
β”‚
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ auth.controller.js
β”‚   β”œβ”€β”€ user.controller.js
β”‚   β”œβ”€β”€ subscription.controller.js
β”‚   └── workflow.controller.js
β”‚
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ auth.routes.js
β”‚   β”œβ”€β”€ user.routes.js
β”‚   β”œβ”€β”€ subscription.routes.js
β”‚   └── workflow.routes.js
β”‚
β”œβ”€β”€ middlewares/
β”‚   β”œβ”€β”€ auth.middleware.js
β”‚   β”œβ”€β”€ arcjet.middleware.js
β”‚   └── error.middleware.js
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ user.model.js
β”‚   └── subscription.model.js
β”‚
β”œβ”€β”€ database/
β”‚   └── mongodb.js             # MongoDB connection
β”‚
└── package.json


πŸ›‘οΈ Security Considerations

  • Passwords are never stored in plain text
  • JWT secrets are environment-scoped
  • Bot protection and rate limiting enabled
  • Sensitive fields excluded from responses
  • Background workflows isolated from API logic

πŸ“¦ Technology Stack

Backend

  • Node.js
  • Express
  • MongoDB
  • Mongoose

Security

  • JWT
  • bcrypt
  • Arcjet

Background Automation

  • Upstash Workflow
  • QStash

Utilities

  • dotenv
  • dayjs
  • cookie-parser
  • nodemon

βš™οΈ Environment Configuration

Example .env.development.local:

PORT=5500
NODE_ENV=development

DB_URI=mongodb://localhost:27017/subscriptions

JWT_SECRET=your_secret_key
JWT_EXPIRES_IN=7d

ARCJET_KEY=your_arcjet_key
ARCJET_ENV=development

QSTASH_TOKEN=your_qstash_token
QSTASH_URL=https://qstash.upstash.io

SERVER_URL=http://localhost:5500

▢️ Running the Application

npm install
npm run dev

🚫 Non-Goals (Intentional Scope)

This project does not:

  • Process payments
  • Handle billing or invoices
  • Integrate payment gateways
  • Replace full CRM systems

The system focuses on subscription tracking and reminders, not financial transactions.


πŸ“ˆ Future Enhancements

  • Email provider integration (SES / SendGrid / Resend)
  • User notification preferences
  • Admin roles & dashboards
  • Subscription analytics
  • Swagger / OpenAPI documentation
  • Unit & integration tests

About

Production-ready Node.js backend for subscription management with JWT authentication, automated renewal tracking, and serverless email reminder workflows using Upstash.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors