Skip to content

A RESTful API for managing user subscriptions with automated renewal reminders built with Node.js and Express.

Notifications You must be signed in to change notification settings

Dennis-DW/Subscription-Management-API

Repository files navigation

Subscription Management API

A RESTful API for managing user subscriptions with automated renewal reminders, built with Node.js and Express.

Features

User Authentication

  • Sign up, sign in, and sign out functionality
  • JWT-based authentication
  • Password encryption using bcrypt

Subscription Management

  • Create, read, update, and delete subscriptions
  • Support for different subscription frequencies (daily, weekly, monthly, yearly)
  • Multiple currency support (KSH, USD, EUR)
  • Automatic renewal date calculation
  • Category-based organization

Automated Reminders

  • Email notifications for subscription renewals
  • Customizable reminder schedules (10, 5, 2, 1 days before renewal)
  • Test reminder functionality

Security Features

  • Rate limiting with Arcjet
  • Bot protection
  • Input validation
  • Error handling middleware

Tech Stack

  • Backend: Node.js & Express
  • Database: MongoDB with Mongoose
  • Authentication: JWT
  • Email Notifications: Nodemailer
  • Scheduled Tasks: Upstash Workflow
  • Security: Arcjet

Key Features

Advanced Rate Limiting and Bot Protection - Secure the app with Arcjet.
Database Modeling - Define models and relationships using MongoDB & Mongoose.
JWT Authentication - Manage users and subscriptions securely.
Global Error Handling - Ensure smooth error management with middleware.
Logging Mechanisms - Improve debugging and monitoring.
Email Reminders - Automate smart email reminders using Upstash.
Code Architecture & Reusability - Maintain clean and scalable code.

API Endpoints

Authentication

  • POST /api/v1/auth/sign-up - Register a new user
  • POST /api/v1/auth/sign-in - Log in a user
  • POST /api/v1/auth/sign-out - Log out a user

Users

  • GET /api/v1/users - Get all users (admin only)
  • GET /api/v1/users/:id - Get a user by ID
  • PUT /api/v1/users/:id - Update a user
  • DELETE /api/v1/users/:id - Delete a user
  • DELETE /api/v1/users - Delete all users (admin only)

Subscriptions

  • POST /api/v1/subscriptions - Create a subscription
  • GET /api/v1/subscriptions - Get all subscriptions (admin only)
  • GET /api/v1/subscriptions/:id - Get a subscription by ID
  • PUT /api/v1/subscriptions/:id - Update a subscription
  • DELETE /api/v1/subscriptions/:id - Delete a subscription
  • DELETE /api/v1/subscriptions - Delete all subscriptions (admin only)
  • GET /api/v1/subscriptions/user/:id - Get a user's subscriptions

Setup

1. Clone the Repository

git clone https://github.com/Dennis-DW/Subscription-Management-API.git
cd submanage

2. Install Dependencies

npm install

3. Configure Environment Variables

Create .env.development.local and .env.production.local with the following:

NODE_ENV='production'
QSTASH_URL=''
QSTASH_TOKEN=''
QSTASH_CURRENT_SIGNING_KEY=''
QSTASH_NEXT_SIGNING_KEY=''

# Server
PORT=5500
SERVER_URL=''
NODE_ENV=development

# MongoDB Connection
DB_URI=''

# JWT Authentication
JWT_SECRET=''
JWT_EXPIRES_IN=''

# Arcjet Security
ARCJET_KEY=''
ARCJET_ENV='development'

# Upstash
QSTASH_URL='http://127.0.0.1:8080'
QSTASH_TOKEN=''

# Email Configuration
EMAIL_PASSWORD=''

# Admin Credentials
ADMIN_USERNAME=''
ADMIN_PASSWORD=''
ADMIN_KEY=''

4. Start the Development Server

npm run dev

5. Run Upstash QStash Development Server

npx @upstash/qstash-cli dev  

The Upstash QStash development server will run at:

http://127.0.0.1:8080

Useful Links

About

A RESTful API for managing user subscriptions with automated renewal reminders built with Node.js and Express.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published