Skip to content

A production-ready Task Manager REST API built with TypeScript, Express, PostgreSQL, Prisma, and Redis — featuring secure auth, role-based access, task management, comments, user controls, and Cloudinary uploads.

License

Notifications You must be signed in to change notification settings

shasbinas/task-manager-api-ts

Repository files navigation

⚙️ Task Manager API (TypeScript + Express + PostgreSQL + Prisma + Redis)


📖 Introduction

A production-ready Task Manager REST API built using TypeScript, Express, PostgreSQL, Prisma, and Redis.

Designed for scalability, security, and clean architecture with:

  • Secure Auth (JWT + Redis blacklist)
  • Role-based access
  • Full Task management (CRUD + Assign + Complete)
  • Comment system
  • User management (Admin-only)
  • Cloudinary file upload
  • Type-safe Prisma ORM
  • Centralized validation with Joi
  • Enterprise security stack

🧭 Table of Contents


⚙ Tech Stack

Technology Purpose
Node.js JavaScript Runtime
TypeScript Type Safety
Express.js HTTP Server Framework
PostgreSQL Primary Database
Prisma ORM Type-safe DB operations
Redis Caching + Token invalidation
JWT Authentication mechanism
argon2 Password hashing
Joi Validation library
Cloudinary Media uploads
Multer File handling
Helmet / CORS / Rate Limit Security
Jest + Supertest Testing

🔋 Features

🔐 Authentication & Authorization

  • JWT authentication
  • Redis token invalidation (logout)
  • Argon2 password hashing
  • Role-based access control (Admin/User)

👤 User Management

  • Admin-only user operations
  • Update roles
  • Upload profile picture
  • Delete users

📋 Task Management

  • CRUD operations
  • Assign tasks to users
  • Mark as completed
  • Owner/Role-based filtering

💬 Comments

  • Add task comments
  • Fetch comments
  • Delete comments

🌍 Environment Variables

Copy env.example to .env and update the values for your environment:

cp env.example .env

Key settings:

  • DATABASE_URL — Prisma/PostgreSQL connection string for local dev or production (set this on Railway/Render to the managed DB URL).
  • COMPOSE_DATABASE_URL — override used only by docker-compose.yml (defaults to the internal postgres service so containers can talk to each other).
  • REDIS_HOST / REDIS_PORT — Redis connection (set redis when using Compose).
  • JWT_SECRET, CLOUDINARY_* — secrets for auth and file uploads.
  • PORT — API port (defaults to 3000).

📦 Quick Start

1️⃣ Clone Repo

git clone https://github.com/shasbinas/task-manager-api-ts.git
cd task-manager-api-ts

2️⃣ Install Dependencies

npm install

3️⃣ Setup Database

npm run prisma:migrate
npx prisma generate

4️⃣ Start Development

npm run dev

🐳 Docker (API + PostgreSQL + Redis)

This repo includes a production-ready Dockerfile and docker-compose.yml that bootstraps the API, PostgreSQL, and Redis together.

  1. Copy env.example.env and set your secrets (compose defaults already point the API to the in-cluster Postgres/Redis).
  2. Build and start everything:
docker compose up --build

Compose will:

  • create persistent postgres / redis volumes,
  • run Prisma migrations before the API boots,
  • expose the API at http://localhost:3000,
  • expose PostgreSQL (localhost:5432) and Redis (localhost:6379) for local tools.

To stop and remove containers + volumes:

docker compose down -v

Deployments can reuse the provided Dockerfile; platforms like Railway/Render only need the same env vars that work locally.

Railway/Render tip: make sure DATABASE_URL is set to the managed Postgres connection string (never localhost) and that REDIS_HOST/REDIS_PORT point to the managed cache if you’re not using the in-cluster Redis.

If you’re on Railway and forget to set DATABASE_URL, the entrypoint will try to construct one from Railway’s default PG* environment variables (with sslmode=require). Still, it’s best to add DATABASE_URL explicitly so Prisma Studio, migrations, and local tooling all share the same value.


🧱 API Modules Overview

🔐 Auth Routes — /api/auth

Method Endpoint Description
POST /register Register a new user
POST /login Login and receive JWT token
POST /logout Logout and invalidate session

👤 User Routes — /api/users (Admin Only)

Method Endpoint Description
GET / Get all users
GET /:id Get user by ID
PUT /:id/role Update user role
DELETE /:id Delete user

📋 Task Routes — /api/tasks

Method Endpoint Description
POST / Create a new task
GET / Get all tasks (filtered by user)
GET /:id Get task by ID
PUT /:id Update task
DELETE /:id Delete task
PUT /:id/complete Mark task as complete
PUT /:id/assign Assign task to user

💬 Comment Routes — /api/comments

Method Endpoint Description
POST /tasks/:taskId/comments Add comment to task
GET /tasks/:taskId/comments Get all comments for task
DELETE /comments/:id Delete comment

🧪 Testing

Run all tests:

npm test

Watch mode:

npm run test:watch

🛠️ Migration Commands

npx prisma migrate dev
npx prisma generate
npx prisma studio

🚀 Deployment on Render

  1. Add environment variables
  2. Use build command:
npm run build && npx prisma migrate deploy
  1. Start command:
npm start

📜 Scripts

"dev": "tsx watch src/server.ts",
"build": "tsc -p tsconfig.build.json",
"start": "node dist/server.js",
"lint": "eslint src --ext .ts",
"lint:fix": "eslint src --ext .ts --fix",
"format": "prettier --write src",
"prisma:migrate": "prisma migrate dev",
"test": "cross-env NODE_ENV=test jest",
"test:watch": "cross-env NODE_ENV=test jest --watch"

🔒 Security

  • Helmet
  • CORS
  • Rate Limiter
  • Redis token blacklist
  • Joi request validation
  • Argon2 password hashing

📄 License

MIT License — Free to use and mo

About

A production-ready Task Manager REST API built with TypeScript, Express, PostgreSQL, Prisma, and Redis — featuring secure auth, role-based access, task management, comments, user controls, and Cloudinary uploads.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published