ToDo-APIs

Todo API

A professional, production-ready RESTful Todo API built with TypeScript and Express. This application demonstrates best practices in Node.js development including proper project structure, error handling, validation, testing, and code quality tools.

Features

Core Functionality

API & Documentation

Security & Performance

Monitoring & Logging

Development & Quality

DevOps & Deployment

Project Structure

todo-api/
├── src/
│   ├── config/           # Configuration files
│   │   └── env.config.ts
│   ├── controllers/      # Request handlers
│   │   └── todo.controller.ts
│   ├── middleware/       # Express middleware
│   │   ├── error.middleware.ts
│   │   ├── logger.middleware.ts
│   │   └── validation.middleware.ts
│   ├── models/          # Data models
│   │   └── todo.model.ts
│   ├── routes/          # API routes
│   │   ├── index.ts
│   │   └── todo.routes.ts
│   ├── types/           # TypeScript type definitions
│   │   ├── express.types.ts
│   │   └── todo.types.ts
│   ├── utils/           # Utility functions
│   │   └── logger.ts
│   ├── app.ts           # Express app configuration
│   └── server.ts        # Server entry point
├── tests/               # Test files
│   └── todo.test.ts
├── .env.example         # Environment variables template
├── .eslintrc.json       # ESLint configuration
├── .prettierrc          # Prettier configuration
├── jest.config.js       # Jest configuration
├── tsconfig.json        # TypeScript configuration
└── package.json         # Project dependencies and scripts

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/UNC-GDSC/ToDo-APIs.git
    cd ToDo-APIs
    
  2. Install dependencies

    npm install
    
  3. Set up environment variables

    cp .env.example .env
    

    Edit .env file with your configuration:

    NODE_ENV=development
    PORT=3000
    API_PREFIX=/api
    

Usage

Development Mode

Run the application with auto-reload on file changes:

npm run dev

Production Mode

Build and run the compiled application:

npm run build
npm start

The server will start on http://localhost:3000 (or your configured PORT).

Docker

Run the application using Docker:

# Build the Docker image
docker build -t todo-api .

# Run the container
docker run -p 3000:3000 --env-file .env todo-api

# Or use Docker Compose
docker-compose up

# Stop the container
docker-compose down

Access the application at http://localhost:3000.

API Documentation

Interactive Documentation

Access the Swagger UI documentation at:

http://localhost:3000/api-docs

The Swagger UI provides:

Base URL

Base URL: http://localhost:3000/api

Health Check

GET /health

Check if the API is running.

Response:

{
  "success": true,
  "message": "Todo API is running",
  "timestamp": "2025-11-13T12:00:00.000Z"
}

Todo Endpoints

Get All Todos

GET /todos

Response:

{
  "success": true,
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "title": "Buy groceries",
      "description": "Milk, eggs, bread",
      "completed": false,
      "createdAt": "2025-11-13T12:00:00.000Z",
      "updatedAt": "2025-11-13T12:00:00.000Z"
    }
  ],
  "message": "Retrieved 1 todos"
}

Get Todo by ID

GET /todos/:id

Response:

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "Buy groceries",
    "description": "Milk, eggs, bread",
    "completed": false,
    "createdAt": "2025-11-13T12:00:00.000Z",
    "updatedAt": "2025-11-13T12:00:00.000Z"
  }
}

Create Todo

POST /todos

Request Body:

{
  "title": "Buy groceries",
  "description": "Milk, eggs, bread"
}

Validation Rules:

Response: (201 Created)

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "Buy groceries",
    "description": "Milk, eggs, bread",
    "completed": false,
    "createdAt": "2025-11-13T12:00:00.000Z",
    "updatedAt": "2025-11-13T12:00:00.000Z"
  },
  "message": "Todo created successfully"
}

Update Todo

PUT /todos/:id

Request Body:

{
  "title": "Buy groceries and cook dinner",
  "description": "Updated description",
  "completed": true
}

Validation Rules:

Response:

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "Buy groceries and cook dinner",
    "description": "Updated description",
    "completed": true,
    "createdAt": "2025-11-13T12:00:00.000Z",
    "updatedAt": "2025-11-13T12:05:00.000Z"
  },
  "message": "Todo updated successfully"
}

Delete Todo

DELETE /todos/:id

Response:

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "Buy groceries",
    "description": "Milk, eggs, bread",
    "completed": true,
    "createdAt": "2025-11-13T12:00:00.000Z",
    "updatedAt": "2025-11-13T12:05:00.000Z"
  },
  "message": "Todo deleted successfully"
}

Get Statistics

GET /todos/stats

Response:

{
  "success": true,
  "data": {
    "total": 10,
    "completed": 6,
    "pending": 4
  }
}

Error Responses

All error responses follow this format:

{
  "success": false,
  "error": "Error message description"
}

Common HTTP status codes:

Development

Available Scripts

Running Tests

# Run all tests with coverage
npm test

# Run tests in watch mode
npm run test:watch

Test coverage report will be generated in the coverage/ directory.

Code Quality

This project uses ESLint and Prettier for code quality and formatting:

# Check for linting issues
npm run lint

# Fix linting issues
npm run lint:fix

# Format code
npm run format

Architecture

Models

Controllers

Routes

Middleware

Types

Configuration

Environment Variables

Variable Description Default
NODE_ENV Environment (development/production) development
PORT Server port 3000
API_PREFIX API route prefix /api

CI/CD

This project includes automated CI/CD pipelines using GitHub Actions:

Continuous Integration

Security Scanning

Workflows

View the workflows in .github/workflows/:

Future Enhancements

Completed ✅

Planned

Contributing

We welcome contributions! Please see CONTRIBUTING.md for detailed guidelines.

Quick start:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please read our Code of Conduct before contributing.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

GDSC-UNC


Built with TypeScript, Express, and best practices in mind.