A production-ready RESTful API built with Node.js, Express, TypeScript, MongoDB, and Redis.
π Live URL: https://task-management-system-api-c0j6.onrender.com
π API Docs: https://task-management-system-api-c0j6.onrender.com/api-docs
π Health Docs: https://task-management-system-api-c0j6.onrender.com/api-docs/root
- Features
- Tech Stack
- Project Structure
- Getting Started
- Environment Variables
- API Documentation
- Authentication
- API Endpoints
- Testing
- CI/CD
- Docker
- License
- JWT-based authentication with access and refresh tokens
- Role-based access control (Admin / User)
- Task CRUD with pagination, filtering, sorting, and search
- Redis caching for performance optimization
- Rate limiting and security headers (Helmet, CORS)
- Request validation with Joi
- Structured logging with Pino
- Swagger UI API documentation
- 87 tests across unit and integration suites
- CI/CD via GitHub Actions
| Layer | Technology |
|---|---|
| Runtime | Node.js 20 |
| Language | TypeScript |
| Framework | Express 5 |
| Database | MongoDB Atlas |
| Cache | Redis (RedisLabs) |
| Auth | JWT (Access + Refresh Tokens) |
| Validation | Joi |
| Logging | Pino |
| Testing | Jest + Supertest + mongodb-memory-server |
| Docs | Swagger UI |
| CI/CD | GitHub Actions |
| Container | Docker |
| Hosting | Render |
src/
βββ config/ # Environment config, Swagger setup
βββ controller/ # Route handlers
βββ lib/ # MongoDB and Redis connections
βββ middleware/ # Auth, CORS, rate limit, cache, error handling
βββ model/ # Mongoose models
βββ routes/ # Express routers with Swagger annotations
βββ seeders/ # Database seeders
βββ service/ # Business logic
βββ types/ # TypeScript type extensions
βββ utils/ # JWT, hash, logger, error, cache utilities
βββ validation/ # Joi validation schemas
βββ app.ts # Express app setup
βββ server.ts # Server entry point
- Node.js 20+
- MongoDB Atlas account
- Redis account (RedisLabs)
git clone https://github.com/sayyedaaman2/task-management-system-api.git
cd task-management-system-api
npm installcp .env.example .env.development
# Fill in your environment variables
npm run devnpm run build
npm startnpm run seedCreate a .env.development file:
PORT=3000
NODE_ENV=development
MONGODB_URI=mongodb+srv://<user>:<password>@cluster0.fwudizk.mongodb.net/task-management?appName=Cluster0
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRES_IN=1h
JWT_REFRESH_SECRET=your_jwt_refresh_secret_key
JWT_REFRESH_EXPIRES_IN=7d
REDIS_USERNAME=default
REDIS_PASSWORD=your_redis_password
REDIS_HOST=redis-xxxxx.c98.us-east-1-4.ec2.cloud.redislabs.com
REDIS_PORT=10839
REDIS_TTL=300Swagger UI is available at:
https://task-management-system-api-c0j6.onrender.com/api-docs
- Register a user via
POST /api/v1/auth/register - Login via
POST /api/v1/auth/login - Copy the
accessTokenfrom the response - Click the Authorize button in Swagger UI
- Paste the token and click Authorize
This API uses JWT-based authentication:
| Token | Expiry | Storage |
|---|---|---|
| Access Token | 1 hour | Response body |
| Refresh Token | 7 days | HttpOnly cookie |
All protected routes require the Authorization: Bearer <accessToken> header.
Base URL: https://task-management-system-api-c0j6.onrender.com/api/v1
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | /register |
Public | Register new user |
| POST | /login |
Public | Login user or admin |
| GET | /refresh-token |
Protected | Refresh access token |
| GET | /profile |
Protected | Get current user profile |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| POST | / |
User | Create task |
| GET | / |
User | Get all tasks (paginated) |
| GET | /:id |
User | Get task by ID |
| PUT | /:id |
User | Update task |
| DELETE | /:id |
User | Delete task |
| Param | Type | Description |
|---|---|---|
| page | integer | Page number (default: 1) |
| limit | integer | Items per page (default: 10, max: 100) |
| search | string | Search by title |
| status | string | pending, in progress, completed |
| priority | string | low, medium, high |
| sortBy | string | createdAt, title, priority, dueDate, status |
| order | string | asc, desc |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /users |
Admin | Get all users (paginated) |
| DELETE | /users/:id |
Admin | Delete user |
| GET | /users/:id/tasks |
Admin | Get tasks for specific user |
| GET | /tasks |
Admin | Get all tasks |
| DELETE | /tasks/:id |
Admin | Delete task |
| GET | /analytics |
Admin | Get system usage stats |
| GET | /analytics/:id |
Admin | Get user activity stats |
| Method | Endpoint | Access | Description |
|---|---|---|---|
| GET | /health |
Public | Health check |
# Run all tests
npm test
# Run with coverage
npm test -- --coverage
# Run specific file
npm test -- --testPathPatterns="auth.test.ts"| Suite | Tests |
|---|---|
| auth.test.ts | 11 |
| task.test.ts | 11 |
| admin.test.ts | 12 |
| hash.test.ts | 4 |
| jwt.test.ts | 13 |
| auth.service.test.ts | 8 |
| task.service.test.ts | 11 |
| admin.service.test.ts | 16 |
| Total | 87 |
| Metric | Threshold |
|---|---|
| Lines | 80% |
| Functions | 80% |
| Branches | 60% |
| Statements | 80% |
GitHub Actions pipeline runs on every push and pull request to main.
- Prettier format check
- Lint check
- Build app
- Run all tests with coverage
- Fail if coverage drops below threshold
JWT_SECRET
JWT_REFRESH_SECRET
JWT_EXPIRES_IN
JWT_REFRESH_EXPIRES_IN
docker build -t task-management-api .
docker run -p 3000:3000 --env-file .env.production task-management-apiThis API is containerized with Docker and deployed on Render using the Dockerfile at the root of the project.
Live: https://task-management-system-api-c0j6.onrender.com
| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Compile TypeScript to JavaScript |
npm start |
Start production server |
npm test |
Run test suite |
npm run lint |
Run ESLint |
npm run lint:fix |
Fix ESLint errors |
npm run format |
Format code with Prettier |
npm run seed |
Seed database with sample data |
ISC Β© Sayyed Aaman