A robust NestJS backend application featuring Role-Based Access Control (RBAC), authentication, payment processing, and file management capabilities.
- Authentication & Authorization: JWT-based authentication with role-based access control (RBAC)
- User Management: Complete user lifecycle management with role assignments
- Payment Integration: Stripe integration for one-time and recurring payments
- File Management: AWS S3 integration for secure file uploads and storage
- Email Service: Email notifications with customizable templates using Handlebars
- Job Queues: Background job processing with BullMQ and Redis
- Security: Helmet, CSRF protection, rate limiting, and account lockout mechanisms
- API Documentation: Swagger/OpenAPI documentation
- Webhooks: Stripe webhook handling for payment events
- Database: PostgreSQL with Prisma ORM
- Caching: Redis for performance optimization
- Framework: NestJS v11
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Cache/Queue: Redis, BullMQ
- Authentication: JWT (Passport)
- File Storage: AWS S3
- Payment: Stripe
- Email: Nodemailer with Handlebars templates
- Validation: class-validator, class-transformer
- Testing: Jest
- Code Quality: ESLint, Prettier, Husky
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- Yarn package manager
- PostgreSQL (v14 or higher)
- Redis (v6 or higher)
- AWS account (for S3 storage)
- Stripe account (for payment processing)
git clone <repository-url>
cd aerovex-backendyarn installCopy the example environment file and configure it with your credentials:
cp .env.example .envUpdate the .env file with your configuration:
# Application
PORT=3000
APP_NAME=aerovex-backend
NODE_ENV=development
# Database
DATABASE_URL="postgresql://postgres:password@localhost:5432/aerovex?schema=public"
# Frontend URL (for CORS)
AEROVEX_FRONTEND_URL="http://localhost:5173"
# Super Admin Credentials
SUPER_ADMIN_EMAIL=superadmin@example.com
SUPER_ADMIN_PASSWORD=superadmin12!@
SUPER_ADMIN_NAME=SuperAdmin
# JWT Configuration
JWT_ACCESS_SECRET_KEY=your-access-secret-key
JWT_REFRESH_SECRET_KEY=your-refresh-secret-key
JWT_ACCESS_TOKEN_EXPIRES_IN=5m
JWT_REFRESH_TOKEN_EXPIRES_IN=15d
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# AWS S3
AWS_ACCESS_KEY_ID=your-aws-access-key
AWS_SECRET_ACCESS_KEY=your-aws-secret-key
AWS_REGION=your-aws-region
AWS_BUCKET_NAME=your-aws-bucket-name
# Email Configuration
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_SENDER=noreply@aerovex.com
# Queue Configuration
QUEUE_DEFAULT_ATTEMPTS=3
QUEUE_REMOVE_ON_COMPLETE=true
QUEUE_REMOVE_ON_FAIL=false
QUEUE_BACKOFF_DELAY=5000
# Security
MAX_LOGIN_ATTEMPTS=5
LOCK_DURATION_SECONDS=3600
# Stripe
STRIPE_SECRET_KEY=sk_test_your_secret_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_hereGenerate Prisma client and run migrations:
# Generate Prisma Client
npx prisma generate
# Run database migrations
npx prisma migrate dev
# (Optional) Seed the database
npx prisma db seedMake sure Redis is running on your machine:
# Using Homebrew (macOS)
brew services start redis
# Or run Redis directly
redis-server# Development mode with hot reload
yarn start:dev
# Production mode
yarn build
yarn start:prod
# Debug mode
yarn start:debugThe API will be available at http://localhost:3000
Once the application is running, access the Swagger API documentation at:
http://localhost:3000/api/docs
# Development
yarn start:dev # Start in development mode with watch
yarn start:debug # Start in debug mode
# Build
yarn build # Build the application
# Production
yarn start:prod # Start in production mode
# Code Quality
yarn lint # Run ESLint
yarn format # Format code with Prettier
# Testing
yarn test # Run unit tests
yarn test:watch # Run tests in watch mode
yarn test:cov # Run tests with coverage
yarn test:e2e # Run end-to-end testsaerovex-backend/
├── prisma/ # Prisma schema and migrations
├── src/
│ ├── auth/ # Authentication module
│ ├── billing/ # Payment and billing module
│ ├── common/ # Shared utilities and decorators
│ ├── cron/ # Scheduled tasks
│ ├── external-service/ # Third-party service integrations
│ ├── prisma/ # Prisma service
│ ├── queues/ # BullMQ job queues
│ ├── redis/ # Redis configuration
│ ├── role/ # Role management
│ ├── templates/ # Email templates
│ ├── upload/ # File upload module
│ ├── user/ # User management
│ ├── webhooks/ # Webhook handlers
│ ├── app.module.ts # Root application module
│ └── main.ts # Application entry point
├── test/ # E2E tests
├── .env.example # Environment variables template
└── package.json # Project dependencies
- JWT Authentication: Secure token-based authentication
- CSRF Protection: Cross-Site Request Forgery protection
- Rate Limiting: Throttling to prevent abuse
- Helmet: Security headers configuration
- Account Lockout: Automatic account locking after failed login attempts
- Password Hashing: bcrypt for secure password storage
- Input Validation: class-validator for request validation
To view the database schema:
npx prisma studioThis will open Prisma Studio at http://localhost:5555
# Run all tests
yarn test
# Run tests with coverage
yarn test:cov
# Run E2E tests
yarn test:e2e
# Run tests in watch mode
yarn test:watchyarn buildEnsure all production environment variables are properly configured:
- Use strong, unique secrets for JWT keys
- Configure production database
- Set up production Redis instance
- Configure AWS S3 for production
- Update Stripe keys to live mode
- Configure production email service
# Using Node
node dist/main.js
# Or using yarn
yarn start:prod# Build Docker image
docker build -t aerovex-backend .
# Run container
docker run -p 3000:3000 --env-file .env aerovex-backend- Ensure PostgreSQL is running
- Verify DATABASE_URL in
.envis correct - Check database credentials and permissions
- Ensure Redis is running:
redis-cli pingshould returnPONG - Verify REDIS_HOST and REDIS_PORT in
.env
- Verify SMTP credentials in
.env - Check firewall settings for SMTP ports
- For Gmail, ensure "Less secure app access" is enabled or use App Passwords
- Verify AWS credentials are correct
- Ensure S3 bucket exists and has proper permissions
- Check CORS configuration on S3 bucket
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code style
- Run
yarn lintbefore committing - Ensure all tests pass with
yarn test
UNLICENSED
For issues and questions, please open an issue in the repository.
Aerovex
Built with NestJS