Skip to content

Harmeet10000/ScaleForge-monolith-template

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” Production-Grade Authentication & Monolith Template

Key Integrations

Novu Razorpay OpenFGA AWS S3
Swagger UI Helmet CORS
RabbitMQ Google Gemini JWT
Compression Prometheus

A comprehensive, production-ready Monolith template with authentication, search, notifications, payments, and fine-grained permissions built with Node.js, Express, MongoDB, Redis, and Elasticsearch.

Project Summary

πŸ“‘ Table of Contents

✨ Features

πŸ”‘ Complete Authentication System
  • βœ… User registration with email verification
  • βœ… Login with JWT (access and refresh tokens)
  • βœ… Secure password reset flow
  • βœ… Account confirmation mechanism
  • βœ… Session management with Redis
  • βœ… Secure password handling with bcrypt
  • βœ… Refresh token rotation
πŸ›‘οΈ Security First Approach
  • βœ… CORS protection with configurable origins
  • βœ… Helmet security headers
  • βœ… Intelligent rate limiting
  • βœ… MongoDB sanitization against NoSQL injection
  • βœ… XSS protection with input sanitization
  • βœ… Secure HTTP-only cookies
  • βœ… Comprehensive input validation with Joi
  • βœ… Content security policies
πŸ” Advanced Search & Analytics
  • βœ… Elasticsearch integration with semantic search
  • βœ… Vector embeddings with Google Gemini AI
  • βœ… Full-text search with fuzzy matching
  • βœ… Search analytics and performance metrics
  • βœ… Custom search pipelines and aggregations
  • βœ… Real-time indexing and data synchronization
  • βœ… Search suggestions and autocomplete
πŸ”” Smart Notifications
  • βœ… Multi-channel notifications (Email, SMS, Push, In-App)
  • βœ… Novu integration for notification workflows
  • βœ… User notification preferences management
  • βœ… Device management for push notifications
  • βœ… Notification templates and personalization
  • βœ… Delivery tracking and analytics
  • βœ… Scheduled and triggered notifications
πŸ’³ Payment Processing
  • βœ… Razorpay integration for secure payments
  • βœ… Subscription management and billing
  • βœ… Payment webhooks and event handling
  • βœ… Invoice generation and management
  • βœ… Refund and dispute handling
  • βœ… Payment analytics and reporting
  • βœ… Multi-currency support
πŸ” Fine-Grained Permissions
  • βœ… OpenFGA integration for relationship-based access control
  • βœ… Role-based and attribute-based permissions
  • βœ… Dynamic permission evaluation
  • βœ… Permission inheritance and delegation
  • βœ… Audit trails for permission changes
  • βœ… Real-time permission updates
  • βœ… Custom authorization policies
☁️ Cloud Storage & CDN
  • βœ… AWS S3 integration for file storage
  • βœ… Secure file upload with presigned URLs
  • βœ… Image processing and optimization
  • βœ… CDN integration for fast delivery
  • βœ… File versioning and backup
  • βœ… Access control and permissions
  • βœ… Automatic database backups to S3
🏭 Production Ready
  • βœ… Dockerized deployment with HMR in development
  • βœ… Request timeout configuration for reliability
  • βœ… Webpack bundling for optimized builds
  • βœ… Environment-specific configurations
  • βœ… Comprehensive error handling with correlation IDs
  • βœ… Interactive API documentation at /api-docs
  • βœ… Structured logging with Loki integration
  • βœ… Health check endpoints with dependency monitoring
  • βœ… Prometheus metrics and Grafana dashboards
  • βœ… RabbitMQ and Kafka for event-driven architecture
πŸ‘¨β€πŸ’» Developer Experience
  • βœ… Hot reloading in development
  • βœ… Code linting and formatting with ESLint and Prettier
  • βœ… Git hooks with Husky
  • βœ… Comprehensive test suite
  • βœ… Conventional commit messages
  • βœ… Clear project structure
  • βœ… Utility scripts for common tasks

πŸ“‹ Prerequisites

Node.js β‰₯ 22.14.0
npm β‰₯ 10.7.0
MongoDB β‰₯ 7.0
Redis β‰₯ 7.0
Elasticsearch β‰₯ 8.0
Docker & Docker Compose For containerized deployment with HMR

πŸš€ Getting Started

⬇️ Installation
  1. Clone the repository
git clone https://github.com/Harmeet10000/production-grade-auth-template.git
cd production-grade-auth-template
  1. Install dependencies
npm i
pnpm i
  1. Set up environment variables

Create a .env.development file in the root directory with the following variables:

# Server
# Server Configuration
NODE_ENV=development
PORT=8000
SERVER_URL=
FRONTEND_URL=http://localhost:5173

# Database Configuration
DATABASE=
DB_POOL_SIZE=

# Migration
MIGRATE_MONGO_URI=
MIGRATE_AUTOSYNC=true

# Redis Configuration
REDIS_HOST=
REDIS_PORT=
REDIS_USERNAME=
REDIS_PASSWORD=

# RabbitMQ Configuration
RABBITMQ_URL=
RABBITMQ_PRIVATE_URL=
RABBITMQ_NODENAME=
RABBITMQ_DEFAULT_USER=
RABBITMQ_DEFAULT_PASS=

# Kafka Configuration
KAFKA_BROKER=
KAFKA_USERNAME=
KAFKA_PASSWORD=
KAFKA_TOPIC=
KAFKA_SERVICE_URI=
KAFKA_HOST=
KAFKA_PORT=
KAFKA_SSL_CA_CERT=
KAFKA_SSL_CERT=
KAFKA_SSL_KEY=
KAFKA_SSL_ENABLED=true

# JWT Configuration
ACCESS_TOKEN_SECRET=
REFRESH_TOKEN_SECRET=
ACCESS_TOKEN_EXPIRY=
REFRESH_TOKEN_EXPIRY=

# Email Configuration
RESEND_KEY=

# Log Configuration
LOG_LEVEL=debug

# S3 Backup Configuration
S3_BACKUP_ENABLED=false
S3_BUCKET_NAME=db-backups
AWS_REGION=us-east-1
S3_PREFIX=mongodb-backups/
BUCKET_NAME=""
BUCKET_REGION="ap-south-1"
ACCESS_KEY=""
SECRET_ACCESS_KEY=""



# Backup Configuration
RUN_BACKUP_ONCE=false



# Google OAuth Configuration
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=GOCSPX-
GOOGLE_REDIRECT_URIS=

# Gemini
GEMINI_API_KEY=


# OpenFGA Configuration
OPENFGA_API_URL=
OPENFGA_API_HOST=
OPENFGA_STORE_ID=
OPENFGA_STORE_NAME=
OPENFGA_MODEL_ID=

# Loki Configuration
LOKI_HOST=http://loki:3100
▢️ Running the Application

Development Mode

docker compose up -d
or
npm run dev

Production Build

npm run build
npm run start
🐳 Docker Deployment

Development

docker build -t auth-service-dev -f docker/dev.Dockerfile .
docker run -p 8000:8000 --env-file .env.development auth-service-dev

Production

docker build -t auth-service-prod -f docker/prod.Dockerfile .
docker run -p 8000:8000 --env-file .env.production auth-service-prod
πŸ“ API Documentation

Once the server is running, access the Swagger documentation at:

http://localhost:8000/api-docs

πŸ“Š Project Structure

πŸ—‚οΈ Folder Organization
backend/
β”œβ”€β”€ docker/                # Docker configuration files
β”‚   β”œβ”€β”€ dev.Dockerfile
β”‚   └── prod.Dockerfile
β”œβ”€β”€ docs/                  # API documentation
β”‚   β”œβ”€β”€ swagger-output.json
β”‚   └── swagger.js
β”œβ”€β”€ logs/                  # Application logs
β”œβ”€β”€ nginx/                 # Nginx configuration for deployment
β”‚   β”œβ”€β”€ http.conf
β”‚   └── https.conf
β”œβ”€β”€ scripts/               # Utility scripts
β”‚   β”œβ”€β”€ cron.sh
β”‚   β”œβ”€β”€ dbBackup.js
β”‚   └── docker.sh
β”œβ”€β”€ src/                   # Source code
β”‚   β”œβ”€β”€ config/            # Configuration files
β”‚   β”œβ”€β”€ connections/       # Database and external service connections
β”‚   β”œβ”€β”€ examples/          # Code examples for various integrations
β”‚   β”œβ”€β”€ features/          # Feature-based modules
β”‚   β”‚   β”œβ”€β”€ auth/          # Authentication feature
β”‚   β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authService.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authRepository.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authRoutes.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authValidation.js
β”‚   β”‚   β”‚   β”œβ”€β”€ authMiddleware.js
β”‚   β”‚   β”‚   β”œβ”€β”€ userModel.js
β”‚   β”‚   β”‚   └── refreshToken.js
β”‚   β”‚   β”œβ”€β”€ health/        # Health check feature
β”‚   β”‚   β”œβ”€β”€ notifications/ # Notification system
β”‚   β”‚   β”œβ”€β”€ payments/      # Payment processing
β”‚   β”‚   β”œβ”€β”€ permissions/   # Authorization & permissions
β”‚   β”‚   β”œβ”€β”€ search/        # Search & analytics
β”‚   β”‚   β”œβ”€β”€ storage/       # File storage (S3)
β”‚   β”‚   └── subscription/  # Subscription management
β”‚   β”œβ”€β”€ helpers/           # Helper utilities
β”‚   β”‚   β”œβ”€β”€ cache/         # Redis caching utilities
β”‚   β”‚   └── messaging/     # Message queue utilities
β”‚   β”œβ”€β”€ middlewares/       # Express middlewares
β”‚   β”œβ”€β”€ utils/             # General utility functions
β”‚   β”œβ”€β”€ app.js             # Express application setup
β”‚   └── index.js           # Application entry point
└── test/                  # Test files
    β”œβ”€β”€ e2e/               # End-to-end tests
    β”œβ”€β”€ unit/              # Unit tests
    β”œβ”€β”€ integration/       # Integration tests
    └── performance/       # Performance tests

βš™οΈ Configuration

πŸ“„ Configuration Files
  • webpack.config.js: Configures bundling for production deployment
  • eslint.config.js: JavaScript linting rules
  • commitlint.config.js: Conventional commit message validation
  • test-runner.js: Test runner configuration
  • prometheus.yml: Prometheus monitoring configuration

πŸ› οΈ Available Scripts

πŸ“‹ NPM Commands
Command Description
npm run dev Start the development server with hot reload
npm run build Build the production bundle
npm run dev:prod Run production build with nodemon
npm start Start the production server
npm run swagger Generate Swagger documentation
npm test Run the test suite
npm run test:watch Run tests in watch mode
npm run test:coverage Run tests with coverage report
npm run lint Check code for linting errors
npm run lint:fix Fix linting errors automatically
npm run format Check code formatting
npm run format:fix Fix formatting issues automatically
npm run migrate:dev Run database migrations in development
npm run migrate:prod Run database migrations in production

πŸ”’ Security Features

πŸ” Security Implementation
  • JWT Authentication: Secure token-based authentication with refresh token rotation
  • Password Security: Bcrypt hashing with appropriate salt rounds
  • Rate Limiting: Protection against brute force attacks
  • Data Validation: Joi schemas for request validation
  • HTTP Security Headers: Using Helmet middleware
  • Cookie Security: HTTP-only, secure cookies with proper domain and path settings
  • MongoDB Sanitization: Protection against NoSQL injection
  • XSS Protection: Sanitization of user input

πŸ§ͺ Testing

🧠 Test Commands

Run all tests:

npm test

Run tests in watch mode:

npm run test:watch

Generate test coverage report:

npm run test:coverage

🀝 Contributing

πŸ“œ Contribution Guidelines
  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the ISC License - see the LICENSE file for details.


⭐ Star this repository if you find it useful! ⭐

Created with ❀️ by Harmeet Singh

⬆️ Back to top ⬆️

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 88.1%
  • HCL 7.8%
  • Shell 3.4%
  • Other 0.7%