Skip to content

dhupthumbadiya2005/subscription-tracker-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± Subscription Tracker API

A robust Node.js API for managing subscription renewals with automated email reminders.

πŸš€ Features

  • User authentication with JWT
  • Subscription management (CRUD operations)
  • Automated renewal reminders via email
  • Workflow scheduling with Upstash
  • Rate limiting with Arcjet
  • MongoDB database integration
  • Email notifications using Nodemailer

πŸ“‹ Prerequisites

  • Node.js v16 or higher
  • MongoDB database
  • Gmail account for sending emails
  • Upstash account for workflows
  • Arcjet account for rate limiting

πŸ› οΈ Installation

  1. Clone the repository:
git clone https://github.com/yourusername/subscription-tracker-api.git cd subscription-tracker-api
  1. Install dependencies:
npm install
  1. Create environment file .env.development.local:
# Port configuration PORT=5500 SERVER_URL="http://localhost:5500" # Database configuration DATABASE_URL="your-mongodb-url" # Environment NODE_ENV="development" # JWT Configuration JWT_SECRET="your-jwt-secret" JWT_EXPIRES_IN="7d" # Arcjet Configuration ARCJET_KEY="your-arcjet-key" ARCJET_ENV="development" # Upstash Configuration QSTASH_URL="your-qstash-url" QSTASH_TOKEN="your-qstash-token" # Email Configuration EMAIL_USER="your-gmail@gmail.com" EMAIL_PASSWORD="your-app-specific-password"
  1. Start the server:
npm run dev

πŸ“š API Documentation

Authentication

Register User

POST /api/v1/auth/signup Content-Type: application/json { "name": "John Doe", "email": "john@example.com", "password": "password123" }

Login

POST /api/v1/auth/signin Content-Type: application/json { "email": "john@example.com", "password": "password123" }

Subscriptions

Create Subscription

POST /api/v1/subscriptions Authorization: Bearer YOUR_JWT_TOKEN Content-Type: application/json { "name": "Netflix", "amount": 199, "currency": "INR", "frequency": "monthly", "category": "entertainment", "paymentMethod": "credit_card", "status": "active", "startDate": "2024-03-15" }

Get All Subscriptions

GET /api/v1/subscriptions Authorization: Bearer YOUR_JWT_TOKEN

Get Single Subscription

GET /api/v1/subscriptions/:id Authorization: Bearer YOUR_JWT_TOKEN

Update Subscription

PUT /api/v1/subscriptions/:id Authorization: Bearer YOUR_JWT_TOKEN Content-Type: application/json { "amount": 249, "status": "active" }

Cancel Subscription

PUT /api/v1/subscriptions/:id/cancel Authorization: Bearer YOUR_JWT_TOKEN

Workflows

Get Upcoming Renewals

GET /api/v1/subscriptions/upcoming-renewals Authorization: Bearer YOUR_JWT_TOKEN

πŸ”„ Workflow System

The API uses Upstash for scheduling renewal reminders:

  • Reminders are sent at 7, 5, 2, and 1 days before renewal
  • Email notifications are sent using Gmail
  • Workflows are automatically created when subscriptions are added

πŸ”’ Security Features

  • JWT authentication
  • Rate limiting with Arcjet
  • Password hashing with bcrypt
  • Input validation
  • Error handling middleware

πŸ“§ Email Templates

The system includes email templates for:

  • Subscription creation confirmation
  • Renewal reminders
  • Cancellation confirmation
  • Payment due notifications

πŸ§ͺ Testing

Run tests using:

npm test

πŸ“± Environment Support

  • Development: .env.development.local
  • Production: .env.production.local
  • Testing: .env.test.local

πŸ›Ÿ Error Handling

The API includes comprehensive error handling for:

  • Invalid requests
  • Authentication failures
  • Database errors
  • Workflow scheduling issues
  • Email sending failures

πŸ“¦ Dependencies

{ "@upstash/qstash": "latest", "@upstash/workflow": "latest", "arcjet": "latest", "bcryptjs": "latest", "cookie-parser": "latest", "dayjs": "latest", "dotenv": "latest", "express": "latest", "jsonwebtoken": "latest", "mongoose": "latest", "nodemailer": "latest" }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors