A minimal backend API for task management (TODO application) built with NestJS, TypeORM, and SQLite.
- ✅ Create tasks with text and status
- ✅ Update task status (in progress → completed)
- ✅ Delete tasks
- ✅ Get all tasks with optional status filtering
- ✅ Get single task by ID
- ✅ SQLite database storage
- ✅ Docker containerization
- ✅ Swagger API documentation
- ✅ Input validation and error handling
- Backend: NestJS (Node.js framework)
- Database: SQLite with TypeORM
- Validation: class-validator, class-transformer
- Documentation: Swagger/OpenAPI
- Containerization: Docker
- Docker installed on your machine
- Clone the repository
- Build and run the Docker container:
docker build -t todo-server .
docker run --name todo-server -p 3000:3000 todo-serverThe API will be available at http://localhost:3000
- Install dependencies:
npm install- Start the development server:
npm run start:dev- For production build:
npm run build
npm run start:prod| Method | Endpoint | Description |
|---|---|---|
| GET | /tasks |
Get all tasks (with optional status filter) |
| GET | /tasks/:id |
Get task by ID |
| POST | /tasks |
Create a new task |
| PATCH | /tasks/:id/status |
Update task status |
| DELETE | /tasks/:id |
Delete task |
POST /api/tasks
Content-Type: application/json
{
"text": "Complete the project documentation",
"status": "in_progress" // optional, defaults to "in_progress"
}Response:
{
"id": 1,
"text": "Complete the project documentation",
"status": "in_progress",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}GET /api/tasksWith status filter:
GET /api/tasks?status=completedResponse:
[
{
"id": 1,
"text": "Complete the project documentation",
"status": "in_progress",
"createdAt": "2024-01-15T10:30:00Z",
"updatedAt": "2024-01-15T10:30:00Z"
}
]GET /api/tasks/1PATCH /api/tasks/1/status
Content-Type: application/json
{
"status": "completed"
}DELETE /api/tasks/1in_progress- Task is currently being worked oncompleted- Task has been finished
Once the server is running, you can access the interactive Swagger documentation at:
http://localhost:3000/api/docs
The application uses SQLite database stored in the db/todo.db file. The database is automatically created when the application starts.
CREATE TABLE tasks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
text VARCHAR(500) NOT NULL,
status VARCHAR(20) DEFAULT 'in_progress',
createdAt DATETIME DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME DEFAULT CURRENT_TIMESTAMP
);The API provides comprehensive error handling with appropriate HTTP status codes:
400 Bad Request- Invalid input data or parameters404 Not Found- Task not found500 Internal Server Error- Server errors
All error responses follow a consistent format:
{
"statusCode": 400,
"message": "Validation failed",
"error": "Bad Request"
}npm run start- Start the applicationnpm run start:dev- Start in development mode with hot reloadnpm run start:prod- Start in production modenpm run build- Build the applicationnpm run test- Run testsnpm run lint- Run ESLintnpm run format- Format code with Prettier
src/
├── config/ # Configuration files
├── modules/
│ └── tasks/ # Task module
│ ├── dto/ # Data Transfer Objects
│ ├── entities/ # Database entities
│ ├── types/ # TypeScript types
│ ├── tasks.controller.ts
│ ├── tasks.service.ts
│ └── tasks.module.ts
├── app.module.ts # Root module
└── main.ts # Application entry point