A robust, feature-rich Task Management REST API built with NestJS, TypeScript, and MySQL. This application provides complete task management functionality with advanced features like Redis caching, rate limiting, JWT authentication, and comprehensive API documentation.
- β Complete CRUD Operations - Create, Read, Update, Delete tasks
- π JWT Authentication - Secure user authentication and authorization
- π€ User Management - User registration and profile management
- π Advanced Filtering - Filter tasks by status and search terms
- π Task Status Management - OPEN, IN_PROGRESS, DONE status workflow
- π Redis Caching - High-performance caching for improved response times
- π‘οΈ Rate Limiting - Multi-tier throttling protection against abuse
- π‘ Real-time Updates - Redis Pub/Sub for real-time notifications
- π Swagger Documentation - Complete API documentation with interactive UI
- β¨ Input Validation - Comprehensive request validation with class-validator
- π§ Email Notifications - Automated weekly task summaries with HTML templates
- β° Scheduled Jobs - Cron-based task scheduling for automated operations
- π§ͺ Comprehensive Testing
- π JWT Token Security - Stateless authentication with configurable expiration
- π Rate Limiting - Multiple throttling tiers (per-second, per-minute)
- ποΈ Database Security - Parameterized queries and ORM protection
- β‘ Optimized Caching - Smart cache invalidation and refresh strategies
- NestJS - Progressive Node.js framework
- TypeScript - Type-safe JavaScript
- MySQL - Primary database
- TypeORM - Object-Relational Mapping
- Redis - Caching and Pub/Sub messaging
- JWT - JSON Web Tokens
- bcrypt - Password hashing
- Passport - Authentication middleware
- class-validator - Input validation
- Jest - Testing framework
- Swagger - API documentation
- ESLint - Code linting
- Prettier - Code formatting
- Husky - Git hooks
- @nestjs-modules/mailer - Email service integration
- Nodemailer - Email transport layer
- Handlebars - HTML email templates
- @nestjs/schedule - Cron job scheduling
- Node.js >= 16.0.0
- npm >= 8.0.0
- MySQL >= 8.0
- Redis >= 6.0
git clone <repository-url>
cd task-manager-crudnpm installCreate environment files:
.env.stage.dev
# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=your_password
DB_DATABASE=task_manager_dev
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-here
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=0
# Email Configuration
EMAIL_USER=your-gmail@gmail.com
EMAIL_PASS=your-app-password
# Application
PORT=3001
STAGE=dev# Create MySQL database
mysql -u root -p
CREATE DATABASE task_manager_dev;- Enable 2-Factor Authentication on your Gmail account
- Generate App Password:
- Go to Google Account settings
- Security β App passwords
- Generate password for "Mail"
- Update environment variables with Gmail credentials
# Start Redis (if using local Redis)
redis-server
# Start MySQL service
# On macOS: brew services start mysql
# On Linux: sudo systemctl start mysql# Development mode with hot reload
npm run start:dev
# Production mode
npm run start:prod
# Debug mode
npm run start:debugThe API will be available at http://localhost:3001
The application automatically sends weekly task summaries to users every Monday at 8:00 AM:
- Recipients: All registered users with email addresses
- Content: List of OPEN tasks for each user
- Format: HTML email with professional styling
- Template: Handlebars-based customizable templates
- Provider: Gmail SMTP (configurable)
- Authentication: App passwords (secure)
- Templates: Located in
src/modules/tasks/templates/ - Scheduling: Cron-based automated delivery
Edit the Handlebars template at src/modules/tasks/templates/weekly-tasks.hbs:
// In TaskMailerService
async sendTestEmail(userEmail: string) {
await this.mailerService.sendMail({
to: userEmail,
subject: 'Test Email',
template: 'weekly-tasks',
context: { user: { username: 'Test User' }, tasks: [] }
});
}Visit http://localhost:3001/api for Swagger UI with interactive API documentation.
All task endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
POST /auth/signin # Sign in userGET /users/:id # Get user by ID
POST /users # Create new userGET /tasks # Get all tasks (with optional filters)
GET /tasks/:id # Get specific task
POST /tasks # Create new task
PATCH /tasks/:id/status # Update task status
DELETE /tasks/:id # Delete taskcurl -X POST http://localhost:3000/users \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "password123"
}'curl -X POST http://localhost:3000/auth/signin \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "password123"
}'curl -X POST http://localhost:3000/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-token>" \
-d '{
"title": "Complete project documentation",
"description": "Write comprehensive README and API docs"
}'# Filter by status
GET /tasks?status=OPEN
# Search tasks
GET /tasks?search=documentation
# Combined filters
GET /tasks?status=IN_PROGRESS&search=project# Unit tests
npm test
# E2E tests
npm run test:e2e
# Test coverage
npm run test:cov
# Watch mode
npm run test:watch
# Specific test files
npm test -- --testPathPatterns="auth|users|tasks"- 27 Unit Tests - Services and controllers
- 100% Core Functionality - All modules covered
- Authentication Flow - Complete auth testing
- Caching Logic - Redis cache hit/miss scenarios
- Email Service - Mailing functionality testing
- Scheduled Jobs - Cron job execution testing
- Error Handling - 401, 404, 400 responses
- Rate Limiting - Throttling verification
src/
βββ app.module.ts # Root application module
βββ main.ts # Application entry point
βββ common/ # Shared utilities
β βββ decorators/ # Custom decorators
β βββ enums/ # Application enums
β βββ interfaces/ # TypeScript interfaces
βββ config/ # Configuration files
β βββ redis.config.ts # Redis configuration
βββ modules/ # Feature modules
β βββ auth/ # Authentication module
β β βββ auth.controller.ts
β β βββ auth.controller.spec.ts
β β βββ auth.service.ts
β β βββ auth.service.spec.ts
β β βββ auth.module.ts
β β βββ dto/ # Data Transfer Objects
β β βββ strategies/ # Passport strategies
β βββ users/ # User management module
β β βββ users.controller.ts
β β βββ users.controller.spec.ts
β β βββ users.service.ts
β β βββ users.service.spec.ts
β β βββ users.module.ts
β β βββ user.entity.ts
β β βββ user.repository.ts
β β βββ dto/
β βββ tasks/ # Task management module
β β βββ tasks.controller.ts
β β βββ tasks.controller.spec.ts
β β βββ tasks.service.ts
β β βββ tasks.service.spec.ts
β β βββ tasks-mailer.service.ts
β β βββ tasks.module.ts
β β βββ tasks.entity.ts
β β βββ tasks.repository.ts
β β βββ dto/
β β βββ templates/
β β βββ weekly-tasks.hbs
β βββ redis/ # Redis module
β βββ redis.service.ts
β βββ redis.module.ts
β βββ redis-pubsub.service.ts
# Lint code
npm run lint
# Format code
npm run format
# Type checking
npm run buildPre-commit hooks automatically run:
- ESLint for code quality
- Prettier for formatting
The application uses different configurations for different environments:
- Development:
.env.stage.dev - Production:
.env.stage.prod - Test: Uses in-memory/test configurations
- Cache Strategy: Cache-first with fallback to database
- Smart Invalidation: Automatic cache cleanup on data changes
- Performance Gain: faster response times for cached data
- Multi-tier Protection:
- Short: 3 requests/second
- Medium: 20 requests/10 seconds
- Long: 100 requests/minute
- Schedule: Every Monday at 8:00 AM
- Cron Expression:
'00 08 * * 1' - Function: Sends task summaries to all users
- Conditions: Only sends if user has OPEN tasks
Add new scheduled jobs using NestJS Schedule:
@Cron('0 0 * * *') // Daily at midnight
async dailyCleanup() {
// Your cleanup logic here
}
@Interval(10000) // Every 10 seconds
async healthCheck() {
// Health check logic
}- Password Hashing: bcrypt with salt rounds
- JWT Security: Configurable expiration and refresh
- Input Validation: Comprehensive DTO validation
- SQL Injection Protection: Parameterized queries via TypeORM
- Rate Limiting: Multi-tier request throttling
- Email Security: App passwords and secure SMTP
| Feature | Description | Technology |
|---|---|---|
| π Task Management | Complete CRUD operations | NestJS + TypeORM |
| π Authentication | JWT-based secure auth | Passport + JWT |
| π Caching | High-performance caching | Redis |
| π§ Email Notifications | Automated weekly reports | Nodemailer + Handlebars |
| β° Scheduled Jobs | Cron-based automation | @nestjs/schedule |
| π‘οΈ Rate Limiting | Multi-tier protection | @nestjs/throttler |
| π API Docs | Interactive documentation | Swagger |
| π§ͺ Testing | Comprehensive test suite | Jest |
β‘ Built with NestJS, TypeScript, Redis, and automated email notifications for maximum performance and user engagement.