NestJS Starter Kit
A powerful, production-ready NestJS starter template
Create Your Project in Seconds
Generate a new project:
npx nestjs-starter-kit my-project
This will create a new NestJS project with all the features and best practices already configured.
Key Features
Advanced Authentication
Complete authentication system with multiple strategies
- JWT-based authentication with refresh tokens
- Two-factor authentication (2FA) with encrypted secrets
- API key authentication
Security Enhancements
Military-grade security features built-in
- AES-256-CBC encryption for sensitive data
- Secure password handling with bcrypt
- Protection against common web vulnerabilities
- Rate limiting and throttling
Authorization
Fine-grained access control
- Role-based access control
- Public/private route decorators
Database Integration
Powerful ORM setup ready to use
- TypeORM with PostgreSQL
- Entity inheritance with BaseEntity
- Efficient pagination
API Documentation
Comprehensive API docs out of the box
- Swagger/OpenAPI with rich metadata
- Detailed endpoint descriptions
- Authentication examples
Environment Configuration
Robust configuration system
- Environment-specific configurations
- Strong validation with Joi
- Sensible defaults
Security First Approach
🔒 Encrypted 2FA Secrets
This starter kit implements industry-standard encryption for 2FA secrets, addressing a common security vulnerability:
- AES-256-CBC Encryption: Military-grade encryption for 2FA secrets
- Unique Initialization Vectors: Each secret gets a unique IV for enhanced security
- Transparent Encryption/Decryption: Handled automatically by the system
- Error Handling: Robust error handling for cryptographic operations
🛡️ Data Protection
All sensitive data is properly protected following industry best practices:
- Encrypted Data: All sensitive data is properly encrypted or hashed
- Secure Password Storage: Passwords are hashed using bcrypt with proper salt rounds
- Privacy Protection: Personal information is protected according to best practices
- Attack Prevention: Protection against common authentication attacks
- Secure Tokens: Configurable token expiration and secure storage
Security Best Practices
No Plain Text Secrets
All sensitive data is encrypted or hashed
Secure JWT
Properly configured signing and expiration
Rate Limiting
Protection against brute force attacks
Input Validation
All input is validated before processing
Content Security
Headers properly set for security
Database Security
Parameterized queries to prevent SQL injection
Ready to Use
🚀 Quick Start
# Clone the repository
git clone https://github.com/latreon/nest-starter-kit.git
# Install dependencies
cd nest-starter-kit
npm install
# Configure environment variables
cp .env.example .env.development
# Run database migrations
npm run migration:run
# Start development server
npm run start:dev
Access the API documentation: http://localhost:3000/api/docs
📁 Project Structure
src/
├── app/ # Application core
│ ├── common/ # Common utilities and helpers
│ │ ├── decorators/ # Custom decorators
│ │ ├── docs/ # API documentation
│ │ ├── entities/ # Base entities
│ │ ├── dto/ # Common DTOs
│ │ ├── services/ # Common services
│ │ └── exception/ # Exception filters
│ └── modules/ # Feature modules
│ ├── auth/ # Authentication module
│ ├── user/ # User management module
│ └── shared/ # Shared services and utilities
├── config/ # Configuration settings
├── database/ # Database setup and migrations
└── main.ts # Application entry point
A well-organized structure following NestJS best practices and ensuring maintainability.
Authentication Flow
JWT Authentication
- Login with email/password to receive JWT token
- Use token for subsequent authenticated requests
- Automatic handling of token expiration and refresh
Two-Factor Authentication
- Enable 2FA for enhanced security
- 2FA secrets are securely encrypted in the database
- TOTP-based verification (compatible with apps like Google Authenticator)
API Key Authentication
- Alternative authentication for service-to-service communication
- Unique per-user API keys with fine-grained permissions
- Easily integrate with external services
Start Building Secure Applications Today
Get started with NestJS Starter Kit and focus on building your business logic rather than spending time on boilerplate code and security concerns.