A robust microservice for managing administrative functions, built with Express.js, MongoDB, and Redis. This service is designed to work seamlessly with other microservices like Custom Auth Service and Software Management Service.
Author: Yatharth Kumar Saxena
Version: 1.0.0
License: ISC
- Overview
- Features
- Technology Stack
- Prerequisites
- Installation
- Setup Guide
- Running the Application
- Project Structure
- API Documentation
- Configuration
- Troubleshooting
The Custom Admin Panel Service is a microservice that provides administrative capabilities including:
- User and admin management
- Organization and organizational user management
- Device management
- Activity tracking and auditing
- Client conversion request handling
- Rate limiting and security features
- Microservice-to-microservice communication
- π Authentication & Authorization: JWT-based token validation with microservice compatibility
- π Activity Tracking: Comprehensive audit logs and activity tracking
- π¦ Rate Limiting: Global and endpoint-specific rate limiting using Redis
- π Cron Jobs: Scheduled tasks for maintenance and data processing
- π― Role-Based Access: Fine-grained permission management
- π± Device Management: Track and manage user devices
- π’ Organization Management: Multi-tenant support
- β‘ Redis Caching: Session management and performance optimization
| Technology | Purpose |
|---|---|
| Express.js | Web framework |
| MongoDB | Primary database |
| Mongoose | MongoDB ODM |
| Redis/IORedis | Caching, sessions, rate limiting |
| JWT | Token-based authentication |
| Axios | HTTP client for microservices |
| dotenv | Environment configuration |
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- npm (v6 or higher)
- MongoDB (v4.4 or higher)
- Redis (v6.0 or higher)
git clone <repository-url>
cd Custom_Admin_Panel_Servicenpm installThis will install all required packages:
- express (v5.2.1)
- mongoose (v9.2.3)
- ioredis (v5.10.0)
- jsonwebtoken (v9.0.3)
- express-rate-limit (v8.2.1)
- And other dependencies...
npm list --depth=0- Create
.envfile from the template:
cp .env.example .env- Configure the following variables:
# π MongoDB Configuration
DB_NAME=admin_panel_service_db
DB_URL=mongodb://localhost/admin_panel_service_db
# π Server Configuration
PORT_NUMBER=8081
NODE_ENV=development
# π΄ Redis Configuration
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD= # Leave blank if no authentication
REDIS_DB=0
REDIS_MAX_RETRY_ATTEMPTS=10
REDIS_RETRY_INITIAL_DELAY=100
REDIS_RETRY_MAX_DELAY=2000
# π¦ Rate Limiting
RATE_LIMIT_WINDOW=10 # minutes
RATE_LIMIT_MAX=100 # requests per window
# π§ Email Configuration (Optional)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=xxxx xxxx xxxx xxxxBefore starting the application, make sure these services are running:
# macOS (with Homebrew)
brew services start mongodb-community
# Linux (with systemd)
sudo systemctl start mongod
# Windows
net start MongoDB
# Manual start
mongodVerify MongoDB connection:
mongosh
> show dbs# macOS (with Homebrew)
brew services start redis
# Linux (with systemd)
sudo systemctl start redis-server
# Manual start
redis-server
# Verify Redis connection
redis-cli ping
# Expected output: PONGIf you need to seed initial data or set up collections:
# Check the bootstrap directory for any initialization scripts
ls src/bootstrap/npm startExpected output:
β
Connection established with MongoDB Successfully
β οΈ Microservice init failed (if microservice not fully configured)
π Server running on port 8081
β
Cron Jobs Initialized
# In another terminal
curl http://localhost:8081
# Or check health
curl http://localhost:8081/health-
Open the included Postman collection:
postman/Custom Admin Panel Service.postman_collection.json -
Import it into Postman to test all available endpoints
Custom_Admin_Panel_Service/
βββ server.js # Entry point - initializes server & DB
βββ package.json # Dependencies & scripts
βββ .env.example # Environment template
βββ jsconfig.json # JavaScript path aliases
βββ postman/ # API collection for testing
β βββ Custom Admin Panel Service.postman_collection.json
βββ src/
β βββ app.js # Express app configuration
β βββ routes/ # API route definitions
β βββ controllers/ # Request handlers
β βββ services/ # Business logic
β βββ models/ # MongoDB schemas
β βββ middlewares/ # Custom middlewares
β βββ configs/ # Configuration files
β βββ utils/ # Helper utilities
β βββ responses/ # Response formatters
β βββ rate-limiters/ # Rate limiting rules
β βββ cron-jobs/ # Scheduled tasks
β βββ internals/ # Microservice communication
βββ testing/ # Test utilities
For detailed navigation and component descriptions, see src/README.md
http://localhost:8081
| Module | Endpoint | Purpose |
|---|---|---|
| Admins | /api/admins |
Admin management |
| Users | /api/users |
User management |
| Organizations | /api/organizations |
Organization management |
| Organization Users | /api/organization-users |
Org user relationships |
| Devices | /api/devices |
Device management |
| Activity Trackers | /api/activity-trackers |
Activity logging |
| Client Conversion | /api/client-conversion-requests |
Conversion requests |
| Internal | /api/internal |
Microservice routes |
For detailed API documentation, import the Postman collection.
The project uses module aliases for cleaner imports. See package.json:
"@": "src"
"@routes": "src/routes"
"@controllers": "src/controllers"
"@models": "src/models"
"@services": "src/services"
// ... and moreUsage:
// Instead of:
const { app } = require("../../../app");
// Use:
const { app } = require("@app");- Global Rate Limiter: Applied to all requests
- Endpoint-Specific: Different limits for different routes
- Redis-Backed: Distributed rate limiting across instances
See src/rate-limiters/ for implementation details.
β MongoDB Connection Failed
Solutions:
- Check MongoDB is running:
mongosh - Verify
DB_URLin.env - Check firewall settings
- Ensure MongoDB service is started
Error: Cannot connect to Redis
Solutions:
- Check Redis is running:
redis-cli ping - Verify
REDIS_HOSTandREDIS_PORTin.env - Check Redis password if authentication is enabled
- Restart Redis service
Error: listen EADDRINUSE: address already in use :::8081
Solutions:
# Find process using port 8081
lsof -i :8081 # macOS/Linux
# Kill the process
kill -9 <PID>
# Or use a different port
PORT_NUMBER=8082 npm startCannot find module '@services/...'
Solutions:
- Ensure
module-alias/registeris required first inserver.jsβ (already done) - Check
jsconfig.jsonpath mappings - Clear
node_modulesand reinstall:rm -rf node_modules && npm install
β οΈ Microservice init failed
This is normal if:
- Custom Auth Service or other microservices aren't running yet
- Check
src/services/bootstrap/microservice-init.service.jsfor requirements
- Express.js Documentation
- MongoDB Documentation
- Mongoose Documentation
- Redis Documentation
- JWT Documentation
This project is licensed under the ISC License.
Yatharth Kumar Saxena
For contributions, please follow the existing code structure and conventions found in the project.
Last Updated: May 2026
Status: Active Development