A comprehensive subscription management API that helps users track their subscriptions, manage renewal dates, and receive automated email reminders.
- User registration and login
- JWT-based authentication
- Secure password hashing with bcrypt
- Profile management
- Create, read, update, and delete subscriptions
- Automatic renewal date calculation
- Support for multiple frequencies (daily, weekly, monthly, yearly)
- Categorized subscriptions (entertainment, technology, finance, etc.)
- Status tracking (active, cancelled, expired)
- Automated email notifications before renewal dates
- Reminder schedule: 7, 5, 2, and 1 days before renewal
- Rate limiting and bot protection with Arcjet
- Input validation and sanitization
- Error handling middleware
- MongoDB transactions for data integrity
- Node.js - JavaScript runtime
- Express.js - Web application framework
- ES Modules - Modern JavaScript module system
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- JSON Web Tokens (JWT) - Stateless authentication
- bcryptjs - Password hashing
- Arcjet - Security layer (rate limiting, bot detection)
- Nodemailer - Email sending library
- Gmail SMTP - Email service provider
- Upstash Workflow - Scheduled email automation
POST /api/v1/auth/sign-up # User registration
POST /api/v1/auth/sign-in # User login
POST /api/v1/auth/sign-out # User logout
GET /api/v1/users/ # Get all users
GET /api/v1/users/profile # Get current user profile
PUT /api/v1/users/profile # Update current user profile
GET /api/v1/users/:id # Get user by ID
POST /api/v1/users/ # Create new user
PUT /api/v1/users/:id # Update user by ID
DELETE /api/v1/users/:id # Delete user by ID
GET /api/v1/subscriptions/ # Get all subscriptions
GET /api/v1/subscriptions/upcoming_renewals # Get upcoming renewals
GET /api/v1/subscriptions/user/:id # Get user's subscriptions
GET /api/v1/subscriptions/:id # Get subscription details
POST /api/v1/subscriptions/ # Create subscription
PUT /api/v1/subscriptions/:id # Update subscription
DELETE /api/v1/subscriptions/:id # Delete subscription
PUT /api/v1/subscriptions/:id/cancel # Cancel subscription
POST /api/v1/workflows/subscription/reminders # Trigger reminder workflow
- Node.js (v16 or higher)
- MongoDB (local or cloud instance)
- Gmail account with app password
-
Clone the repository
git clone <repository-url> cd sub-tracker
-
Install dependencies
npm install
-
Environment Setup Create
.env.development.localfile:# Server Configuration PORT=5500 SERVER_URL=http://localhost:5500 NODE_ENV=development # Database DB_URI=mongodb://localhost:27017/subscription-tracker # JWT Configuration JWT_SECRET=your-super-secret-jwt-key JWT_EXPIRES_IN=7d # Email Configuration EMAIL_PASSWORD=your-gmail-app-password # Upstash QStash (for workflows) QSTASH_TOKEN=your-qstash-token QSTASH_URL=https://qstash.upstash.io # Arcjet Security ARCJET_KEY=your-arcjet-key ARCJET_ENV=development
-
Start the development server
npm run dev
The API will be available at http://localhost:5500
- Enable 2-factor authentication on your Gmail account
- Generate an App Password:
- Go to Google Account settings
- Security β 2-Step Verification β App passwords
- Generate password for "Mail"
- Use the generated password as
EMAIL_PASSWORDin your environment
- Automated Reminders: Sent 7, 5, 2, and 1 days before renewal
- Beautiful Templates: Clean, responsive design similar to Amazon
- Smart Scheduling: Uses Upstash Workflow for precise timing
curl -X POST http://localhost:5500/api/v1/auth/sign-up \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}'curl -X POST http://localhost:5500/api/v1/subscriptions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"name": "Netflix Premium",
"price": 15.99,
"currency": "USD",
"frequency": "monthly",
"category": "entertainment",
"paymentMethod": "Credit Card ending in 1234",
"startDate": "2025-05-01T00:00:00.000Z"
}'- JWT Authentication: Stateless authentication with secure tokens
- Password Hashing: bcrypt with salt rounds for secure password storage
- Rate Limiting: Arcjet protection against brute force attacks
- Bot Detection: Automatic blocking of malicious bots
- Input Validation: Mongoose schema validation
- Error Handling: Comprehensive error middleware
- Automatically calculates renewal dates based on frequency
- Updates renewal dates when start date or frequency changes
- Handles different subscription periods accurately
- Integrates with Upstash Workflow for scheduled emails
- Graceful handling of workflow failures
- Subscription creation continues even if email scheduling fails
- Profile-based authentication
- Cascade deletion (deleting user removes all subscriptions)
- Email uniqueness validation
Built with β€οΈ by Khulan