A clean REST API to manage users, authentication, subscriptions, and automated renewal reminders.
This project is built for learning backend API design with security, scheduling, and email notification workflows.
- Node.js
- Express.js
- MongoDB + Mongoose
- JWT (JSON Web Token)
- bcryptjs
- Upstash Workflow (QStash)
- Nodemailer
- Arcjet (bot and rate-limit protection)
- dotenv
- Node.js (v18+ recommended)
- MongoDB database (local or cloud)
- Upstash QStash account
- SMTP credentials for email sending
npm installCreate an environment file named:
.env.development.localAdd the following variables:
PORT=3000
NODE_ENV=development
DB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=7d
SERVER_URL=http://localhost:3000
ARCJET_KEY=your_arcjet_key
ARCJET_ENV=development
QSTASH_URL=your_qstash_url
QSTASH_TOKEN=your_qstash_token
MAILER_EMAIL=your_email@example.com
EMAIL_PASS=your_email_password_or_app_passwordnpm run devor
npm startServer runs on:
http://localhost:3000curl -X POST http://localhost:3000/api/v1/auth/sign-up \
-H "Content-Type: application/json" \
-d "{\"name\":\"Ali Khan\",\"email\":\"ali@example.com\",\"password\":\"123456\"}"curl -X POST http://localhost:3000/api/v1/subscriptions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
-d "{\"name\":\"Netflix\",\"price\":12,\"currency\":\"USD\",\"frequency\":\"Monthly\",\"category\":\"Entertainment\",\"paymentMethod\":\"Card\"}"- User signs up or signs in and receives a JWT token.
- Authorized user creates a subscription.
- Subscription is stored in MongoDB with user relation.
- API triggers an Upstash workflow for reminders.
- Workflow waits for reminder dates (7, 5, 2, and 1 day before renewal).
- Reminder email is sent to the user on due reminder dates.
POST /api/v1/auth/sign-up- Register a new userPOST /api/v1/auth/sign-in- Login and get tokenPOST /api/v1/auth/sign-out- Logout response
GET /api/v1/users- Get all usersGET /api/v1/users/:id- Get single user (authorized)
POST /api/v1/subscriptions- Create subscription (authorized)GET /api/v1/subscriptions/user/:id- Get subscriptions by user (authorized)GET /api/v1/subscriptions- Placeholder routeGET /api/v1/subscriptions/:id- Placeholder route
POST /api/v1/workflows/subscription/reminder- Trigger reminder workflow
- Routes Layer: Defines API endpoints and maps requests to controllers.
- Controller Layer: Handles request logic, validation flow, and responses.
- Model Layer: Defines MongoDB schemas and data constraints.
- Middleware Layer:
- JWT authorization
- Arcjet security (rate limiting and bot protection)
- centralized error handling
- External Services:
- Upstash Workflow for delayed reminder orchestration
- Nodemailer for reminder emails
Flow:
Client -> Express Route -> Middleware -> Controller -> MongoDB / Upstash / Mail Service -> Response
This project is open source and available for everyone to use, learn from, and modify.
StackWise Dev
Created for learning purpose.