A comprehensive task management API built with NestJS, featuring authentication, CRUD operations, background job processing, and comments system.
- Authentication: JWT-based user registration and login
- Task Management: Full CRUD operations with advanced pagination and filtering
- Comments System: Add, update, delete comments on tasks with search functionality
- Background Jobs: Redis-based job processing for task completion notifications
- API Documentation: Interactive Swagger UI documentation
- Database: PostgreSQL with Prisma ORM
- Security: Input validation, authorization guards, and secure password hashing
- Framework: NestJS (Node.js)
- Database: PostgreSQL
- ORM: Prisma
- Authentication: JWT with Passport.js
- Background Jobs: Redis with Bull/BullMQ
- Validation: class-validator & class-transformer
- Documentation: Swagger/OpenAPI
- Containerization: Docker & Docker Compose
- Node.js 20+ or Docker
- PostgreSQL 15+
- Redis 7+
- npm or yarn
-
Clone the repository
git clone <repository-url> cd task-manager-api
-
Run with Docker Compose
docker-compose up -d
Migrations run automatically on startup
-
Install dependencies
npm install
-
Environment setup
cp .env.example .env # Edit .env with your database and Redis configurations
-
Database setup
npx prisma migrate dev npx prisma generate
-
Start the application
# Development npm run start:dev # Production npm run build npm run start:prod
Create a .env
file in the root directory:
# Database
DATABASE_URL="postgresql://username:password@postgres:5432/taskmanager"
# Redis
REDIS_URL="redis://localhost:6379"
# JWT
JWT_SECRET="your-super-secret-jwt-key-change-in-production"
# Application
NODE_ENV="production"
PORT=3000
Once the application is running, access the interactive API documentation:
- Swagger UI: http://localhost:3000/api
- OpenAPI JSON: http://localhost:3000/api-json
All endpoints except registration and login require JWT authentication:
# Register a new user
POST /api/v1/auth/register
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}
# Login
POST /api/v1/auth/login
{
"email": "john@example.com",
"password": "password123"
}
GET /api/v1/tasks
- List tasks with pagination and filteringPOST /api/v1/tasks
- Create a new taskGET /api/v1/tasks/:id
- Get task by IDPATCH /api/v1/tasks/:id
- Update taskDELETE /api/v1/tasks/:id
- Delete taskGET /api/v1/tasks/stats
- Get task statisticsGET /api/v1/tasks/queue-stats
- Get background job statistics
POST /api/v1/tasks/:taskId/comments
- Add comment to taskGET /api/v1/tasks/:taskId/comments
- Get task comments with paginationGET /api/v1/tasks/:taskId/comments/stats
- Get comment statisticsGET /api/v1/comments/:id
- Get specific commentPATCH /api/v1/comments/:id
- Update commentDELETE /api/v1/comments/:id
- Delete comment
Tasks & Comments Pagination:
?page=1&limit=10&order=desc&search=keyword&status=PENDING
# Start all services (production - default)
docker-compose up -d
# Start in development mode
NODE_ENV=development docker-compose up -d
# View application logs
docker-compose logs -f app
# Access application shell
docker-compose exec app sh
# Stop all services
docker-compose down
# Reset database (removes all data)
docker-compose down -v
# Rebuild and start
docker-compose up --build
- Production (default): Uses optimized settings, minimal logging
- Development: Uses development settings via
NODE_ENV=development
- Environment variables: Loaded from
.env
file automatically
- Single optimized build works for both development and production
- Migrations run automatically on container startup
- Environment behavior controlled by
NODE_ENV
variable - Database and Redis included in Docker Compose setup
id
(String) - Primary keyemail
(String) - Unique email addressname
(String?) - Optional user namepassword
(String) - Hashed passwordcreatedAt
(DateTime)updatedAt
(DateTime)
id
(String) - Primary keytitle
(String) - Task titledescription
(String?) - Optional descriptionstatus
(TaskStatus) - PENDING | IN_PROGRESS | COMPLETEDuserId
(String) - Foreign key to UsercreatedAt
(DateTime)updatedAt
(DateTime)
id
(String) - Primary keycontent
(String) - Comment textuserId
(String) - Foreign key to UsertaskId
(String) - Foreign key to TaskcreatedAt
(DateTime)updatedAt
(DateTime)
The application uses Redis for background job processing:
- Task Completion Notifications: Triggered when task status changes to COMPLETED
- Job Logging: All notifications are logged to
logs/notifications.json
- Queue Statistics: Monitor job processing through
/tasks/queue-stats
- JWT Authentication: Secure stateless token-based authentication
- Password Hashing: bcrypt with salt rounds 12 for secure password storage
- Authorization Guards: Route-level access control with JwtAuthGuard
- Ownership Validation: Multi-layered ownership checks ensuring users only access their own data
- Input Validation: Comprehensive validation using class-validator and class-transformer
- Type Safety: TypeScript throughout for compile-time safety
- Request Sanitization: Automatic whitelist filtering and transformation
- SQL Injection Prevention: Prisma ORM with parameterized queries
- CORS Protection: Configurable cross-origin resource sharing with environment-based origins
- Helmet Security Headers: CSP, XSS protection, and other security headers
- Rate Limiting: Multi-tier throttling (3 req/sec, 20 req/10sec, 100 req/min)
- Compression: Gzip compression for reduced bandwidth usage
- Content Security Policy: Restricts resource loading to prevent XSS
- X-Frame-Options: DENY to prevent clickjacking
- X-Content-Type-Options: nosniff to prevent MIME-type sniffing
- X-XSS-Protection: Browser XSS filter enabled
- Referrer Policy: Strict origin policy for privacy
- Security Logging: Request tracking with IP, user agent, and response times
- Error Monitoring: Automated logging of failed requests and slow responses
- Performance Tracking: Response time monitoring with alerts for slow requests
- Audit Trail: Complete request/response logging for security analysis
- Environment Variables: Externalized secrets and configuration
- Production Security: HTTPS enforcement, secure cookies (configurable)
- HSTS Support: HTTP Strict Transport Security for production
- Configure proper JWT secrets in production
- Set up SSL/TLS certificates
- Configure environment-specific CORS origins
- Enable secure cookies and HSTS
- Application:
GET /api/v1/
- Database: Automatic Prisma health checks
- Redis: Background job processing status
docker-compose down -v && docker-compose up --build
docker-compose ps
docker-compose logs -f app
Built with NestJS, PostgreSQL, Redis, and Docker