A comprehensive subscription tracking API built with Node.js and Express that helps users manage and monitor their recurring subscriptions.
- 🔐 User Authentication - JWT-based secure authentication
- 📋 Subscription Management - Create, read, update, delete, and cancel subscriptions
- 🆓 Trial Support - Comprehensive trial subscription handling
- 🌐 Website Integration - Track subscription websites
- 🔒 Security - Arcjet integration for enhanced security
- 📧 Email Notifications - Automated email reminders (coming soon)
- ⚡ Workflow Automation - Upstash workflow integration
- 🚀 Production Ready - Environment-based configuration
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Authentication: JWT with bcryptjs
- Security: Arcjet protection
- Workflow: Upstash Workflow
- Email: Nodemailer
- Deployment: Vercel
- Development: Nodemon, ESLint
- Node.js (v14 or higher)
- MongoDB database
- npm or yarn package manager
-
Clone the repository
git clone <repository-url> cd substrack-server
-
Install dependencies
npm install
-
Environment Setup
Create a
.env.development.localfile in the root directory:# Server Configuration PORT=5500 NODE_ENV=development SERVER_URL=http://localhost:5500 # Database DB_URI=mongodb://localhost:27017/substrack # OR for MongoDB Atlas: # DB_URI=mongodb+srv://username:password@cluster.mongodb.net/substrack # JWT Configuration JWT_SECRET=your-super-secret-jwt-key-here JWT_EXPIRES_IN=7d # Arcjet Security ARCJET_ENV=development ARCJET_KEY=your-arcjet-key # Upstash Workflow QSTASH_URL=https://qstash.upstash.io QSTASH_TOKEN=your-qstash-token QSTASH_CURRENT_SIGNING_KEY=your-current-signing-key QSTASH_NEXT_SIGNING_KEY=your-next-signing-key # Email Configuration EMAIL_PASSWORD=your-email-app-password
-
Start the development server
npm run dev
The server will start at
http://localhost:5500
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/v1/auth/signup |
Register new user | ❌ |
| POST | /api/v1/auth/signin |
User login | ❌ |
| POST | /api/v1/auth/signout |
User logout | ❌ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/v1/subscriptions/ |
Create subscription | ✅ |
| GET | /api/v1/subscriptions/user/:id |
Get user subscriptions | ✅ |
| PUT | /api/v1/subscriptions/:id |
Edit subscription | ✅ |
| PUT | /api/v1/subscriptions/:id/cancel |
Cancel subscription | ✅ |
| DELETE | /api/v1/subscriptions/:id |
Delete subscription | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /api/v1/users/ |
Get all users | ✅ |
{
name: String, // Required, 2-50 characters
email: String, // Required, unique, valid email
password: String, // Required, min 6 characters (hashed)
createdAt: Date, // Auto-generated
updatedAt: Date // Auto-generated
}{
name: String, // Required, 2-100 characters
price: Number, // Required, >= 0
currency: String, // Default: "USD"
frequency: String, // "daily", "weekly", "monthly", "yearly"
category: String, // Required
websiteUrl: String, // Optional, valid URL
startDate: String, // Required
paymentMethod: String, // Required
isTrial: Boolean, // Default: false
trialInfo: {
trialDuration: Number, // Default: 30
trialDurationUnit: String, // "days", "weeks", "months"
trialEndDate: String, // Default: ""
postTrialPrice: Number, // Default: 0
autoConvertToRegular: Boolean, // Default: true
reminderSent: Boolean, // Default: false
cancellationDate: Date // Default: null
},
status: String, // "active", "cancelled", "expired"
user: ObjectId, // Reference to User
createdAt: Date, // Auto-generated
updatedAt: Date // Auto-generated
}Sign Up
POST /api/v1/auth/signup
Content-Type: application/json
{
"name": "John Doe",
"email": "john@example.com",
"password": "securePassword123"
}Sign In
POST /api/v1/auth/signin
Content-Type: application/json
{
"email": "john@example.com",
"password": "securePassword123"
}Create Subscription
POST /api/v1/subscriptions/
Authorization: Bearer <your-jwt-token>
Content-Type: application/json
{
"name": "Netflix Premium",
"price": 15.99,
"currency": "USD",
"frequency": "monthly",
"category": "Entertainment",
"websiteUrl": "https://netflix.com",
"startDate": "2024-01-01",
"paymentMethod": "Credit Card",
"isTrial": false
}Edit Subscription
PUT /api/v1/subscriptions/:id
Authorization: Bearer <your-jwt-token>
Content-Type: application/json
{
"name": "Netflix Premium Family",
"price": 19.99,
"websiteUrl": "https://netflix.com/family"
}Cancel Subscription
PUT /api/v1/subscriptions/:id/cancel
Authorization: Bearer <your-jwt-token>- JWT Authentication - Secure token-based authentication
- Password Hashing - bcryptjs for secure password storage
- Arcjet Protection - Advanced security middleware
- Input Validation - Mongoose schema validation
- Authorization Checks - Route-level permission validation
- CORS Configuration - Cross-origin request handling
The application supports multiple environments:
- Development:
.env.development.local - Production:
.env.production.local
Key environment variables:
NODE_ENV- Environment modeJWT_SECRET- JWT signing secret (keep secure!)DB_URI- MongoDB connection stringPORT- Server port (default: 5500)
# Development
npm run dev # Start with nodemon (auto-reload)
# Production
npm start # Start production server
# Code Quality
npm run lint # Run ESLint checks
npm run lint:fix # Run ESLint and auto-fix issues
npm run format # Format all code with Prettier
npm run format:check # Check if code is properly formattedThe application is deployed on AWS with plans for automated CI/CD using GitHub Actions.
- Platform: Amazon Web Services (AWS)
- Environment: Production server running on AWS infrastructure
- Configuration: Environment variables managed through AWS services
- Production URL: Configured via
SERVER_URLenvironment variable
🔄 Automated Deployment Workflow (Coming Soon):
# .github/workflows/deploy.yml (Planned)
name: Deploy to AWS
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Run linting
run: npm run lint
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- name: Deploy to AWS
# AWS deployment steps here{
"version": 2,
"builds": [{ "src": "app.js", "use": "@vercel/node" }],
"routes": [{ "src": "/(.*)", "dest": "/app.js" }]
}- CI/CD Pipeline - GitHub Actions automated testing and deployment
- Add TypeScript support
- Swagger API documentation
- Email notification system
- Subscription analytics
- Currency conversion support
- AWS infrastructure optimization
- Automated testing suite
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is private and proprietary.