Skip to content

AtomicShadow04/Task-Management-API

Repository files navigation

Task Management API

A RESTful API for managing tasks and projects, built with TypeScript, Express, Prisma, and SQLite.

Features

  • User authentication and authorization with JWT
  • Task management (CRUD operations)
  • Project management (CRUD operations)
  • Secure logout with token blacklisting
  • Input validation with Zod
  • Error handling middleware
  • SQLite database with Prisma ORM

Tech Stack

  • Backend: Node.js, TypeScript, Express
  • Database: SQLite with Prisma ORM
  • Authentication: JWT (JSON Web Tokens)
  • Validation: Zod
  • Password Hashing: bcryptjs

Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • npm or pnpm

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd task-management-api
  2. Install dependencies:

    npm install
    # or
    pnpm install
  3. Set up the database:

    npx prisma migrate dev
    npx prisma generate
  4. Start the development server:

    npm run dev

The server will start on http://localhost:3000.

Environment Variables

Create a .env file in the root directory with the following variables:

DATABASE_URL="file:./taskmanagement.db"
jwt_secret="your_jwt_secret_key"
JWT_SECRET="your_jwt_secret_key"  # Used in utils/jwt.ts
JWT_EXPIRES_IN="1d"

API Endpoints

Authentication

  • POST /users/register - Register a new user
  • POST /users/login - Login user
  • POST /users/logout - Logout user (requires auth)
  • GET /users/:id - Get user profile
  • PUT /users/:id - Update user profile
  • DELETE /users/:id - Delete user profile

Tasks

All task endpoints require authentication.

  • GET /tasks - Get all tasks for the authenticated user
  • GET /tasks/:name - Get task by name
  • POST /tasks - Create a new task
  • PUT /tasks/:id - Update a task
  • DELETE /tasks/:id - Delete a task

Projects

All project endpoints require authentication.

  • GET /projects - Get all projects for the authenticated user
  • GET /projects/:name - Get project by name
  • POST /projects - Create a new project
  • PUT /projects/:id - Update a project
  • DELETE /projects/:id - Delete a project

Request/Response Examples

Register User

POST /users/register
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com",
  "password": "password123"
}

Create Task

POST /tasks
Authorization: Bearer <jwt-token>
Content-Type: application/json

{
  "title": "Complete project",
  "description": "Finish the API development",
  "priority": "High",
  "dueDate": "2025-12-31"
}

Database Schema

User

  • id: String (CUID)
  • email: String (unique)
  • password: String (hashed)
  • name: String
  • tasks: Task[]
  • projects: Project[]
  • createdAt: DateTime

Task

  • id: String (CUID)
  • title: String
  • description: String?
  • status: String (TODO, IN_PROGRESS, DONE)
  • dueDate: DateTime?
  • priority: String (LOW, MEDIUM, HIGH)
  • userId: String
  • projectId: String?
  • createdAt: DateTime
  • updatedAt: DateTime

Project

  • id: String (CUID)
  • name: String
  • description: String?
  • userId: String
  • tasks: Task[]
  • createdAt: DateTime
  • updatedAt: DateTime

BlacklistedToken

  • id: String (CUID)
  • token: String (unique)
  • createdAt: DateTime

Scripts

  • npm run dev - Start development server with nodemon
  • npm start - Build and start production server
  • npx prisma migrate dev - Run database migrations
  • npx prisma generate - Generate Prisma client
  • npx prisma studio - Open Prisma Studio for database management

Project Structure

src/
├── controllers/     # Route handlers
├── middleware/      # Express middleware
├── routes/         # API routes
├── schema/         # Zod validation schemas
├── types/          # TypeScript type definitions
├── utils/          # Utility functions
├── index.ts        # Application entry point
└── server.ts       # Server configuration

prisma/
├── schema.prisma   # Database schema
└── migrations/     # Database migrations

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published