Skip to content

REST API for managing personal subscriptions with automated renewal tracking, email notifications, and spending analytics

Notifications You must be signed in to change notification settings

Sumant3086/Subscription-tracker

Repository files navigation

Subscription Tracker Backend

A REST API for managing personal subscriptions with automated renewal tracking and email notifications.

Features

  • User authentication with JWT
  • Subscription CRUD operations
  • Spending analytics and insights
  • Email notifications for renewals
  • Automated status updates via cron jobs
  • Rate limiting and security middleware

Tech Stack

  • Node.js + Express.js
  • MongoDB + Mongoose
  • JWT authentication
  • Nodemailer for emails
  • Node-cron for scheduling

Installation

  1. Clone and install dependencies:
git clone https://github.com/Sumant3086/Subscription-tracker.git
cd Subscription-tracker
npm install
  1. Configure environment variables:
cp .env.example .env.development.local

Edit .env.development.local:

PORT=5500
NODE_ENV=development
DB_URI=mongodb+srv://username:password@cluster.mongodb.net/database
JWT_SECRET=your_jwt_secret
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_app_password
EMAIL_FROM=your_email@gmail.com
  1. Start the server:
npm run dev

API Endpoints

Authentication

  • POST /api/v1/auth/sign-up - Register user
  • POST /api/v1/auth/sign-in - Login user

Subscriptions (Protected)

  • GET /api/v1/subscriptions - List subscriptions with analytics
  • POST /api/v1/subscriptions - Create subscription
  • PUT /api/v1/subscriptions/:id - Update subscription
  • DELETE /api/v1/subscriptions/:id - Delete subscription
  • PATCH /api/v1/subscriptions/:id/cancel - Cancel subscription
  • GET /api/v1/subscriptions/analytics - Get spending analytics
  • GET /api/v1/subscriptions/upcoming-renewals - Get upcoming renewals

Users (Protected)

  • GET /api/v1/users/profile - Get user profile
  • PUT /api/v1/users/profile - Update profile

Usage Workflow

  1. Register a new user:
POST /api/v1/auth/sign-up
{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123"
}
  1. Login to get JWT token:
POST /api/v1/auth/sign-in
{
  "email": "john@example.com",
  "password": "password123"
}
  1. Add subscriptions (use token in Authorization header):
POST /api/v1/subscriptions
Authorization: Bearer <jwt_token>
{
  "name": "Netflix",
  "price": 15.99,
  "currency": "USD",
  "frequency": "monthly",
  "category": "entertainment",
  "payment": "Credit Card",
  "startDate": "2024-01-01"
}
  1. View analytics and manage subscriptions:
GET /api/v1/subscriptions/analytics
GET /api/v1/subscriptions/upcoming-renewals

Testing

Run the test suite:

node test-api.js

Project Structure

├── controllers/     # Request handlers
├── models/         # Database schemas
├── routes/         # API routes
├── middlewares/    # Custom middleware
├── services/       # Business logic (email, cron)
├── config/         # Configuration
├── database/       # DB connection
└── app.js         # Express app

License

MIT

About

REST API for managing personal subscriptions with automated renewal tracking, email notifications, and spending analytics

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published