Skip to content

Repository files navigation

Task Management API (Assignment 3)

Secure REST API with event-driven reminders, category/tag management, and simulated external webhook integration.

Tech Stack

  • Node.js + Express.js
  • PostgreSQL (pg) for users
  • MongoDB (mongodb) for tasks, categories, tags
  • JWT auth (jsonwebtoken), password hashing (bcryptjs)
  • Validation with joi

Features

Core Auth + Task Management

  • Register/login with hashed password and JWT.
  • Authenticated profile endpoint.
  • Task CRUD scoped by userId (no cross-user access).

Real-time Task Reminders (Simulated)

  • On task create/update with dueDate (due_date alias supported), system schedules in-memory reminder.
  • Reminder fires REMINDER_LEAD_MINUTES before due date (default 60).
  • If due date updated, old reminder canceled and new one scheduled.
  • If task marked completed or deleted, reminder canceled.
  • Reminder event logs to console + logs/notifications.log.
  • Optional reminder webhook call if REMINDER_WEBHOOK_URL exists.

Categories + Tags

  • Dynamic user-owned categories (/api/categories CRUD).
  • Dynamic user-owned tags (/api/tags CRUD), tag text is free-form.
  • Task supports category (string) and tags (array of strings).
  • Filter endpoint supports category/tags/status: GET /api/tasks/filter.

External Analytics Webhook (Simulated)

  • When task status transitions to completed, API emits event.
  • Event handler sends POST webhook to ANALYTICS_WEBHOOK_URL.
  • Retry logic: up to 3 retries, exponential backoff (1s, 2s, 4s).
  • Delivery logs written to console + logs/notifications.log.

Setup

1) Install

npm install

2) Configure env

Create .env (or copy from .env.example):

PORT=3001
POSTGRES_URI=postgres://taskuser:taskpassword@localhost:5433/taskdb
MONGODB_URI=mongodb://localhost:27017/taskapp
JWT_SECRET=replace_with_strong_secret

# Reminder config
REMINDER_LEAD_MINUTES=60
REMINDER_WEBHOOK_URL=

# Analytics webhook on task completion
ANALYTICS_WEBHOOK_URL=

3) Run option A (Dockerized app + databases)

docker-compose up --build

App runs on http://localhost:3001.

4) Run option B (Local Node app + Docker databases)

Run databases first:

docker-compose up -d postgres mongodb

Run API locally:

npm run dev

or

npm start

Folder Structure

  • src/config/ DB connection config.
  • src/controllers/ route handlers.
  • src/events/ event bus + event handler registration.
  • src/middlewares/ auth + global error handler.
  • src/models/ DB collection/table wrappers.
  • src/routes/ API route definitions.
  • src/services/ reminder scheduler, notifications, webhook retry logic.
  • src/validators/ Joi schemas.

Design Choices

Categories

  • Chosen dynamic user-defined categories.
  • Reason: flexible for personal/team workflows, no hardcoded enum migration.
  • Category rename/delete cascades into user tasks for consistency.

Tags

  • Tags stored as free-form strings in task docs.
  • Separate tag CRUD endpoints maintain reusable tag list per user.
  • Tag rename/delete propagates to existing user tasks.

Reminder Scheduling

  • In-memory setTimeout scheduler for simplicity.
  • taskId -> timeout map enables cancellation/reschedule.
  • Scheduler rehydrates on server boot by scanning pending tasks with due date.
  • Tradeoff: in-memory jobs lost if process restarts; acceptable for simulation scope.

Webhook Retry

  • Event-driven completion webhook (decoupled from request/response path).
  • fetch + retry loop with exponential backoff.
  • Logs every retry/success/failure to file + console.

API Documentation

All endpoints below require Authorization: Bearer <token> except register/login.

Auth

POST /api/auth/register

{
  "email": "user@example.com",
  "password": "password123"
}

POST /api/auth/login

{
  "email": "user@example.com",
  "password": "password123"
}

GET /api/auth/profile

Tasks

POST /api/tasks

{
  "title": "Finish report",
  "description": "Quarterly report",
  "dueDate": "2026-04-12T20:00:00.000Z",
  "status": "pending",
  "category": "Work",
  "tags": ["High Priority", "Client A"]
}

Notes:

  • due_date also accepted (converted to dueDate).
  • status default = pending.

GET /api/tasks

Get all user tasks.

GET /api/tasks/filter?category=Work&tags=High%20Priority,Client%20A&status=pending

Filter by any combination of category, comma-separated tags (all tags must match), and status.

GET /api/tasks/:id

PUT /api/tasks/:id

Partial updates allowed.

DELETE /api/tasks/:id

Categories

POST /api/categories

{ "name": "Work" }

GET /api/categories

GET /api/categories/:id

PUT /api/categories/:id

{ "name": "Personal" }

DELETE /api/categories/:id

Tags

POST /api/tags

{ "name": "High Priority" }

GET /api/tags

GET /api/tags/:id

PUT /api/tags/:id

{ "name": "Bug Fix" }

DELETE /api/tags/:id

Error Handling

  • 400 validation or malformed IDs.
  • 401 missing/invalid JWT.
  • 404 not found.
  • 500 internal errors.

Demo Checklist (for 7-min video)

  • Setup (docker + npm run dev).
  • Register/login.
  • Create task with due date and show reminder log line.
  • Create categories/tags and create tasks using them.
  • Filter tasks with /api/tasks/filter.
  • Mark task completed and show webhook payload delivery on webhook.site.
  • Show reminder cancel/reschedule by updating due date and completing task.

About

Basic Task Management API with authentication.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages