Skip to content

savindaJ/TaskManager-BE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧩 Task Manager Backend API

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


πŸš€ Features

  • βœ… 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

πŸ›  Tech Stack

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

πŸ“‚ Project Structure

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.md

βš™οΈ Installation & Setup

1️⃣ Prerequisites

Make sure you have the following installed:

  • Node.js v18 or higher
  • npm v9 or higher
  • MongoDB Atlas account (or local MongoDB)

2️⃣ Clone the Repository

git clone https://github.com/savindaJ/task-manager-backend.git
cd task-manager-backend

3️⃣ Install Dependencies

npm install

4️⃣ Environment Variables

Create a .env file in the root directory:

touch .env

Add 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"

πŸ”‘ Environment Variables Explained

Variable Description Required Default
PORT Server port number No 5000
NODE_ENV Environment mode (development, production) No development
MONGODB_URI MongoDB connection string Yes -

5️⃣ Setup MongoDB Atlas

  1. Go to MongoDB Atlas
  2. Create a free cluster
  3. Click "Connect" β†’ "Connect your application"
  4. Copy the connection string
  5. Replace <username>, <password>, and <database> in your .env file

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


6️⃣ Generate Prisma Client

npm run prisma:generate

7️⃣ Push Schema to Database

npm run prisma:push

8️⃣ Start the Server

Development mode (with hot reload):

npm run dev

Production mode:

npm run build
npm start

🎯 API Endpoints

Base URL: http://localhost:8080/api

Health Check

Method Endpoint Description
GET /health Check server status

Tasks

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

Query Parameters (GET /tasks)

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

πŸ“ Task Model

{
  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
}

πŸ“‹ Available Scripts

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)

πŸ§ͺ API Examples

Create a Task

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"]
  }'

Get All Tasks with Pagination

curl "http://localhost:8080/api/tasks?page=1&limit=10&status=TODO"

Update Task Status

curl -X PUT http://localhost:8080/api/tasks/YOUR_TASK_ID \
  -H "Content-Type: application/json" \
  -d '{
    "status": "IN_PROGRESS"
  }'

Delete a Task

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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors