A production-ready Task Management REST API built with TypeScript, Express.js, Prisma ORM, and MongoDB.
This project is designed to showcase modern backend development skills, including clean architecture, Prisma with MongoDB, centralized error handling, and scalable API design.
π¨βπ» Author: Savinda Jayasekara
π GitHub: github.com/savindaJ
- β Create, Read, Update, Delete (CRUD) Tasks
- π Task Statistics API
- π Search, Filter & Pagination
- π§ Prisma ORM with MongoDB Adapter
- π‘ Centralized Error Handling Middleware
- π§± Layered Architecture (Controller β Service β DB)
- π Environment-based Configuration
- π§ͺ Fully Type-safe with TypeScript
- π Clean & Scalable Project Structure
| Technology | Description |
|---|---|
| Node.js | JavaScript runtime |
| Express.js | Web framework |
| TypeScript | Type-safe JavaScript |
| Prisma ORM | Database ORM |
| MongoDB Atlas | Cloud database |
| dotenv | Environment variables |
taskmanager-be/
βββ prisma/
β βββ schema.prisma # Database schema & models
βββ src/
β βββ config/ # Environment & server configuration
β β βββ index.ts
β βββ controllers/ # HTTP request handlers
β β βββ index.ts
β β βββ task.controller.ts
β βββ lib/ # Prisma client initialization
β β βββ prisma.ts
β βββ middleware/ # Error handling & validation
β β βββ index.ts
β β βββ errorHandler.ts
β β βββ notFound.ts
β βββ routes/ # API route definitions
β β βββ index.ts
β β βββ task.routes.ts
β βββ services/ # Business logic & database queries
β β βββ index.ts
β β βββ task.service.ts
β βββ types/ # TypeScript interfaces & types
β β βββ index.ts
β β βββ task.types.ts
β βββ utils/ # Helper functions & utilities
β β βββ index.ts
β β βββ ApiError.ts
β β βββ asyncHandler.ts
β βββ app.ts # Express app configuration
β βββ server.ts # Application entry point
βββ .env # Environment variables (create this)
βββ .gitignore
βββ package.json
βββ tsconfig.json
βββ README.mdMake sure you have the following installed:
- Node.js v18 or higher
- npm v9 or higher
- MongoDB Atlas account (or local MongoDB)
git clone https://github.com/savindaJ/task-manager-backend.git
cd task-manager-backendnpm installCreate a .env file in the root directory:
touch .envAdd the following environment variables:
# =================================
# Server Configuration
# =================================
PORT=8080
NODE_ENV=development
# =================================
# Database Configuration
# =================================
# MongoDB Connection String
# Replace with your MongoDB Atlas connection string
MONGODB_URI="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/<database>?retryWrites=true&w=majority"| Variable | Description | Required | Default |
|---|---|---|---|
PORT |
Server port number | No | 5000 |
NODE_ENV |
Environment mode (development, production) |
No | development |
MONGODB_URI |
MongoDB connection string | Yes | - |
- Go to MongoDB Atlas
- Create a free cluster
- Click "Connect" β "Connect your application"
- Copy the connection string
- Replace
<username>,<password>, and<database>in your.envfile
Example:
MONGODB_URI="mongodb+srv://myuser:mypassword123@cluster0.abc123.mongodb.net/taskmanager?retryWrites=true&w=majority"
β οΈ Important: Add your IP to the Network Access whitelist in MongoDB Atlas
npm run prisma:generatenpm run prisma:pushDevelopment mode (with hot reload):
npm run devProduction mode:
npm run build
npm startBase URL: http://localhost:8080/api
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Check server status |
| Method | Endpoint | Description |
|---|---|---|
GET |
/tasks |
Get all tasks (with pagination) |
GET |
/tasks/:id |
Get task by ID |
POST |
/tasks |
Create a new task |
PUT |
/tasks/:id |
Update a task |
DELETE |
/tasks/:id |
Delete a task |
GET |
/tasks/stats |
Get task statistics |
| Parameter | Type | Description | Example |
|---|---|---|---|
page |
number | Page number | ?page=1 |
limit |
number | Items per page | ?limit=10 |
status |
string | Filter by status | ?status=TODO |
priority |
string | Filter by priority | ?priority=HIGH |
search |
string | Search in title/description | ?search=bug |
sortBy |
string | Sort field | ?sortBy=createdAt |
sortOrder |
string | Sort direction | ?sortOrder=desc |
{
id: string; // Auto-generated MongoDB ObjectId
title: string; // Task title (required)
description: string; // Task description (optional)
status: TaskStatus; // TODO | IN_PROGRESS | COMPLETED | CANCELLED
priority: TaskPriority; // LOW | MEDIUM | HIGH | URGENT
dueDate: DateTime; // Due date (optional)
tags: string[]; // Array of tags
createdAt: DateTime; // Auto-generated
updatedAt: DateTime; // Auto-updated
}| Script | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Build for production |
npm start |
Start production server |
npm run prisma:generate |
Generate Prisma client |
npm run prisma:push |
Push schema to database |
npm run prisma:studio |
Open Prisma Studio (DB GUI) |
curl -X POST http://localhost:8080/api/tasks \
-H "Content-Type: application/json" \
-d '{
"title": "Complete project documentation",
"description": "Write README and API docs",
"priority": "HIGH",
"status": "TODO",
"tags": ["documentation", "urgent"]
}'curl "http://localhost:8080/api/tasks?page=1&limit=10&status=TODO"curl -X PUT http://localhost:8080/api/tasks/YOUR_TASK_ID \
-H "Content-Type: application/json" \
-d '{
"status": "IN_PROGRESS"
}'curl -X DELETE http://localhost:8080/api/tasks/YOUR_TASK_ID- GitHub: @savindaJ
- LinkedIn: Savinda Jayasekara
β If you found this project helpful, please give it a star!