A high-performance, production-ready REST API built with NestJS. This project provides a robust foundation with enterprise-grade features including security hardening, rate limiting, structured logging, and comprehensive API documentation.
- ⚡ High Performance - Optimized for low-latency responses with response compression
- 🔒 Security First - Helmet.js integration with API-focused security headers
- 📊 Structured Logging - Pino.js for high-performance JSON logging
- 📖 API Documentation - Auto-generated Swagger/OpenAPI documentation
- 🎯 API Versioning - URI-based versioning (
/v1,/v2, etc.) - ✅ Request Validation - Class-validator powered DTO validation
- 🛡️ Rate Limiting - Multi-tier throttling protection (short/medium/long)
- 🐳 Docker Ready - Containerized with optimized multi-stage builds
- 🔄 Hot Reload - Fast development iteration with watch mode
- 📝 Conventional Commits - Enforced via Commitlint
- 🎨 Code Quality - ESLint, Prettier, and CSpell integration
- 🧪 Testing Ready - Jest configuration for unit and e2e tests
- 📦 Path Aliases - Clean imports with
@app/*aliases
- 🔄 Graceful Shutdown - Proper container lifecycle management
- 📈 Auto Versioning - Semantic versioning based on commits
- 🔧 Environment Config - Flexible configuration via environment variables
- 🚦 HSTS Support - Strict Transport Security in production
- Node.js >= 24
- npm or yarn
- Docker & Docker Compose (optional)
# Clone the repository
git clone <repository-url>
cd realtime-translator-api
# Install dependencies
npm install
# Copy environment variables
cp .env.sample .envConfigure the application via environment variables:
| Variable | Description | Default |
|---|---|---|
APP_NAME |
Application name | nestjs-api |
APP_ENV |
Environment (development, production) |
development |
HTTP_PORT |
Server port | 3003 |
HTTP_VERSION |
API version number | 1 |
HTTP_VERSIONING_ENABLE |
Enable API versioning | false |
# Start with hot-reload
npm run start:dev
# Start with debug mode
npm run start:debug# Build and run with Docker Compose
docker compose up --build
# Run in detached mode
docker compose up -d --build# Build the application
npm run build:prod
# Start production server
npm run start:prodOnce the application is running, access the Swagger documentation at:
http://localhost:3003/docs
# Run unit tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run e2e tests
npm run test:e2esrc/
├── config/ # Configuration modules
│ ├── app.config.ts # Application settings
│ └── doc.config.ts # Swagger documentation config
├── helpers/ # Utility functions and interceptors
├── main.module.ts # Root application module
├── main.ts # Application entry point
└── swagger.ts # Swagger setup
This API implements several security best practices:
- Helmet.js - Sets various HTTP headers for security
- HSTS - Enforces HTTPS in production (1-year max-age)
- Rate Limiting - Three-tier protection:
- Short: 3 requests/second
- Medium: 20 requests/10 seconds
- Long: 100 requests/minute
- Input Validation - Whitelist-based DTO validation
- No MIME Sniffing - Prevents content-type attacks
The application uses Pino for high-performance structured logging:
// In your service
import { Logger } from '@nestjs/common';
private readonly logger = new Logger(YourService.name);
// Log messages
this.logger.log('Operation completed', 'context');
this.logger.error('Something went wrong', error.stack);Use the NestJS CLI to scaffold new resources:
# Generate a complete CRUD resource
nest g resource modules/your-resource
# Generate individual components
nest g controller modules/your-resource
nest g service modules/your-resource
nest g module modules/your-resourceThis project enforces Conventional Commits. Common prefixes:
| Prefix | Description | Version Bump |
|---|---|---|
feat: |
New feature | Minor |
fix: |
Bug fix | Patch |
docs: |
Documentation only | - |
refactor: |
Code refactoring | - |
test: |
Adding tests | - |
chore: |
Maintenance | - |
feat!: / fix!: |
Breaking change | Major |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.