A robust subscription management system built with microservices architecture using Node.js, Express, MongoDB, and RabbitMQ.
The system consists of three main microservices:
-
User Service (Port: 3001)
- Handles user authentication and management
- Manages user profiles and verification
-
Plan Service (Port: 3002)
- Manages subscription plans
- Handles plan CRUD operations
-
Subscription Service (Port: 3003)
- Manages user subscriptions
- Handles subscription lifecycle
- Monitors subscription expiry
-
API Gateway (Port: 3000)
- Routes requests to appropriate services
- Handles service discovery
- User authentication with JWT
- Email verification system
- Subscription plan management
- User subscription handling
- Automatic subscription expiry checking
- Inter-service communication using RabbitMQ
- Microservices architecture
- Email notifications
- Node.js (v14 or higher)
- MongoDB
- RabbitMQ
- Gmail account (for email notifications)
- Clone the repository:
git clone <repository-url>
cd Microservices-Subscription-management-system
- Install dependencies for each service:
# Install dependencies for User Service
cd UserService && npm install
# Install dependencies for Plan Service
cd ../PlanService && npm install
# Install dependencies for Subscription Service
cd ../SubscriptionService && npm install
# Install dependencies for Gateway
cd ../gateway && npm install
- Configure environment variables:
Create .env files in each service directory using the provided .env.example files:
User Service (.env):
MONGODB_URI=<your-mongodb-uri>
JWT_SECRET=<your-jwt-secret>
PORT=3001
EMAIL_USER=<your-gmail>
EMAIL_PASS=<your-gmail-app-password>
FRONTEND_URL=http://localhost:5173
RABBITMQ_URL=<your-rabbitmq-url>
Plan Service (.env):
MONGODB_URI=<your-mongodb-uri>
JWT_SECRET=<your-jwt-secret>
PORT=3002
USER_SERVICE_URL=http://localhost:3001
RABBITMQ_URL=<your-rabbitmq-url>
Subscription Service (.env):
MONGODB_URI=<your-mongodb-uri>
JWT_SECRET=<your-jwt-secret>
PORT=3003
USER_SERVICE_URL=http://localhost:3000
RABBITMQ_URL=<your-rabbitmq-url>
- POST
/register
- Register new user - POST
/login
- User login - POST
/verify
- Verify user email - POST
/forgot-password
- Request password reset - POST
/reset-password/:token
- Reset password - POST
/logout
- User logout - GET
/profile
- Get user profile
- POST
/
- Create new plan - GET
/
- Get all plans - PUT
/:id
- Update plan - DELETE
/:id
- Delete plan
- POST
/
- Create new subscription - GET
/
- Get user subscriptions - PUT
/:subId
- Update subscription - DELETE
/:subId
- Cancel subscription
User Service Events:
user.created
user.updated
user.deleted
Plan Service Events:
plan.created
plan.updated
plan.deleted
Subscription Service Events:
subscription.created
subscription.renewed
subscription.cancelled
subscription.expired
- Start all services:
# Start User Service
cd UserService && npm run dev
# Start Plan Service
cd ../PlanService && npm run dev
# Start Subscription Service
cd ../SubscriptionService && npm run dev
# Start Gateway
cd ../gateway && npm run dev
The system includes comprehensive error handling:
- Input validation using Zod
- HTTP error responses with appropriate status codes
- RabbitMQ message handling error recovery
- Database connection error handling
- Email service error handling
- JWT authentication
- Password hashing using bcrypt
- Email verification
- Protected routes
- CORS configuration
- Input validation
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
This project is licensed under the ISC License.
For support, email [email protected]