A comprehensive, production-ready REST API for task management with advanced features including user management, RBAC, workflows, notifications, webhooks, and API key management.
- User Management: Complete user lifecycle with Auth0 integration
- Role-Based Access Control (RBAC): Fine-grained permissions system
- Task Management: Full CRUD operations with state machine workflows
- Notifications: Multi-channel notifications (Email, In-App, Push)
- Webhooks: Event-driven integrations with external services
- API Keys: Programmatic access with scoped permissions
- Authentication: Auth0 OAuth2/OIDC integration
- Database: PostgreSQL with TypeORM
- Caching: Redis integration with graceful degradation
- API Documentation: Interactive Swagger/OpenAPI documentation
- Monitoring: Health checks, metrics, and distributed tracing
- Security: Rate limiting, input validation, SQL injection prevention
- Testing: Unit tests, integration tests, and property-based testing
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Documentation
- Authentication
- Database
- Testing
- Architecture
- Contributing
- License
- Node.js: v18+ (recommended: v20+)
- PostgreSQL: v14+
- Redis: v6+ (optional, for caching)
- Auth0 Account: For authentication
- npm or yarn: Package manager
git clone https://github.com/yourusername/task-management-api.git
cd task-management-apinpm install# Create database
createdb task_management
# Or using psql
psql -U postgres
CREATE DATABASE task_management;Copy the example environment file:
cp .env.example .envUpdate .env with your configuration (see Configuration section).
npm run migration:runnpm run seedCreate a .env file in the root directory:
# Server Configuration
NODE_ENV=development
PORT=3001
HOST=0.0.0.0
# Database Configuration
DATABASE_HOST=localhost
DATABASE_PORT=5434
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=task_management
DATABASE_SSL=false
# Auth0 Configuration
AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_CLIENT_ID=your_client_id
AUTH0_CLIENT_SECRET=your_client_secret
AUTH0_AUDIENCE=https://api.task-management.com
AUTH0_ISSUER=https://your-tenant.auth0.com/
# Redis Configuration (Optional)
REDIS_HOST=localhost
REDIS_PORT=6379
CACHE_TTL=300
# Security
JWT_SECRET=your-secret-key-min-256-bits
RATE_LIMIT_DEFAULT_POINTS=1000
RATE_LIMIT_DEFAULT_DURATION=3600
# Features
ENABLE_SWAGGER_DOCS=true
LOG_LEVEL=debug
TRACING_ENABLED=false-
Create Auth0 Account: Sign up at auth0.com
-
Create API:
- Go to Applications β APIs β Create API
- Name: Task Management API
- Identifier:
https://api.task-management.com - Signing Algorithm: RS256
-
Create Application:
- Go to Applications β Applications β Create Application
- Name: Task Management Client
- Type: Machine to Machine
- Authorize for Task Management API
-
Enable Password Grant (for user authentication):
- Go to Application Settings β Advanced Settings β Grant Types
- Enable "Password" grant type
- Save Changes
-
Set Default Directory (if using password grant):
- Go to Settings (tenant level) β API Authorization Settings
- Default Directory:
Username-Password-Authentication - Save
-
Enable Management API Access (for user creation):
- Go to Applications β Your M2M App β APIs
- Authorize for "Auth0 Management API"
- Grant permissions:
create:users,read:users,update:users
npm run start:devThe API will be available at: http://localhost:3001
# Build the application
npm run build
# Start production server
npm run start:prod# Build and start containers
docker-compose up -d
# View logs
docker-compose logs -f
# Stop containers
docker-compose downInteractive API documentation is available at:
http://localhost:3001/api/docs
POST /api/v1/users/register- Register new userGET /api/v1/users/me- Get current user profile
GET /api/v1/users- List all usersGET /api/v1/users/:id- Get user by IDPUT /api/v1/users/:id- Update userDELETE /api/v1/users/:id- Soft delete user
POST /api/v1/tasks- Create taskGET /api/v1/tasks- List tasks (with filters)GET /api/v1/tasks/:id- Get task detailsPUT /api/v1/tasks/:id- Update taskPATCH /api/v1/tasks/:id/transition- Transition task stateDELETE /api/v1/tasks/:id- Delete task
GET /api/v1/workflows- List workflowsGET /api/v1/workflows/default- Get default workflowGET /api/v1/workflows/:id- Get workflow details
POST /api/v1/notifications- Send notificationGET /api/v1/notifications- Get user notificationsGET /api/v1/notifications/unread/count- Get unread countPUT /api/v1/notifications/:id/read- Mark as readPUT /api/v1/notifications/read-all- Mark all as read
POST /api/v1/api-keys- Create API keyGET /api/v1/api-keys- List API keysGET /api/v1/api-keys/:id- Get API key detailsPOST /api/v1/api-keys/:id/revoke- Revoke API key
POST /api/v1/webhooks/subscriptions- Create webhook subscriptionGET /api/v1/webhooks/subscriptions- List subscriptionsGET /api/v1/webhooks/deliveries/:id- Get delivery details
GET /api/health- Liveness checkGET /api/ready- Readiness checkGET /api/health/deep- Deep health checkGET /api/metrics- Prometheus metrics
curl --request POST \
--url https://your-tenant.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"audience": "https://api.task-management.com",
"grant_type": "client_credentials"
}'curl --request POST \
--url https://your-tenant.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{
"grant_type": "password",
"username": "[email protected]",
"password": "SecurePass123!",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"audience": "https://api.task-management.com",
"realm": "Username-Password-Authentication"
}'Include the token in the Authorization header:
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
http://localhost:3001/api/v1/tasksThe application uses PostgreSQL with the following main tables:
users- User accountsroles- Role definitionspermissions- Permission definitionsuser_roles- User-role assignmentsrole_permissions- Role-permission assignmentsteams- Team organizationtasks- Task recordsworkflows- Workflow definitionsworkflow_states- Workflow state definitionsworkflow_transitions- Valid state transitionsnotifications- Notification recordsnotification_preferences- User notification settingswebhook_subscriptions- Webhook configurationswebhook_deliveries- Webhook delivery historyapi_keys- API key management
# Run migrations
npm run migration:run
# Revert last migration
npm run migration:revert
# Generate new migration
npm run migration:generate -- MigrationName# Run seed data
npm run seedSeeds include:
- 2 default users (Alice, Bob)
- Default workflow (To Do β In Progress β Done)
- Sample tasks
npm testnpm run test:covnpm run test:e2enpm run test:pbtsrc/
βββ common/ # Shared utilities
β βββ decorators/ # Custom decorators
β βββ filters/ # Exception filters
β βββ guards/ # Authorization guards
β βββ interceptors/ # Request/response interceptors
β βββ pipes/ # Validation pipes
β βββ infrastructure/ # Infrastructure services
β βββ cache/ # Cache service
β βββ database/ # Database configuration
β βββ health/ # Health checks
β βββ logger/ # Logging service
β βββ metrics/ # Metrics collection
β βββ tracing/ # Distributed tracing
βββ modules/ # Feature modules
β βββ user-domain/ # User management
β β βββ user/ # User CRUD
β β βββ role/ # Role management
β β βββ permission/ # Permission system
β β βββ team/ # Team organization
β β βββ guards/ # Auth guards
β β βββ adapters/ # Auth0 adapter
β βββ task-domain/ # Task management
β β βββ task/ # Task CRUD
β β βββ workflow/ # Workflow engine
β β βββ comment/ # Task comments
β β βββ attachment/ # File attachments
β βββ notification-domain/ # Notifications
β β βββ notification/ # Notification service
β β βββ preference/ # User preferences
β β βββ template/ # Templates
β β βββ log/ # Delivery logs
β βββ integration-domain/ # External integrations
β βββ webhook/ # Webhook system
β βββ api-key/ # API key management
βββ migrations/ # Database migrations
βββ seeds/ # Database seeds
βββ main.ts # Application entry point
- Domain-Driven Design (DDD): Organized by business domains
- Repository Pattern: Data access abstraction
- Service Layer: Business logic separation
- DTO Pattern: Data validation and transformation
- Adapter Pattern: External service integration
- Strategy Pattern: Pluggable notification channels
- State Machine: Workflow state transitions
- Framework: NestJS (Node.js framework)
- Language: TypeScript
- ORM: TypeORM
- Database: PostgreSQL
- Cache: Redis
- Authentication: Auth0 (OAuth2/OIDC)
- Validation: class-validator
- Documentation: Swagger/OpenAPI
- Testing: Jest
- Monitoring: OpenTelemetry (optional)
- Authentication: OAuth2/OIDC with Auth0
- Authorization: RBAC with fine-grained permissions
- Rate Limiting: Configurable request throttling
- Input Validation: class-validator with DTOs
- SQL Injection Prevention: Parameterized queries (TypeORM)
- XSS Prevention: Output encoding
- CORS: Configurable cross-origin policies
- API Keys: Hashed storage with scoped permissions
- Webhook Security: HMAC signature verification
- Secrets Management: Environment variables
- Passwords are never stored (Auth0 handles authentication)
- API keys are hashed before storage
- Soft deletes for user data
- Audit trails for sensitive operations
- Secure session management
- Regular dependency updates
/api/health- Basic liveness check/api/ready- Readiness check (DB, cache connectivity)/api/health/deep- Comprehensive health check
Prometheus-compatible metrics at /api/metrics:
- HTTP request duration
- HTTP request count
- Active connections
- Database query performance
- Cache hit/miss rates
Structured JSON logging with configurable levels:
LOG_LEVEL=debug # debug, info, warn, errorContributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Use ESLint and Prettier (run
npm run lint) - Write tests for new features
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- NestJS - Progressive Node.js framework
- Auth0 - Authentication platform
- TypeORM - ORM for TypeScript
- PostgreSQL - Database
For questions or issues:
- Open an issue on GitHub
- Check the API Documentation
- Review the Architecture section
- GraphQL API support
- Real-time notifications with WebSockets
- File upload and storage (S3 integration)
- Advanced analytics and reporting
- Mobile SDK (iOS/Android)
- Kubernetes deployment manifests
- Performance benchmarks
Built with β€οΈ using NestJS and TypeScript