A RESTful API for managing todos built with NestJS. This API provides CRUD operations for todo items with filtering capabilities and Swagger documentation.
- NestJS (v11.0.1) - Progressive Node.js framework for building efficient and scalable server-side applications
- TypeScript (v5.7.3) - Typed superset of JavaScript
- Express (via @nestjs/platform-express) - Web framework
- @nestjs/swagger (v11.2.3) - API documentation with Swagger/OpenAPI
- class-validator (v0.14.3) - Validation decorators for DTOs
- class-transformer (v0.5.1) - Object transformation utilities
- RxJS (v7.8.1) - Reactive programming library
- Biome (v2.3.8) - Fast formatter and linter
- Jest (v30.0.0) - Testing framework
- TypeScript ESLint - TypeScript linting
- ✅ Create, read, update, and delete todos
- 🔍 Filter todos by status (all, active, completed)
- 📝 Input validation using class-validator
- 📚 Swagger/OpenAPI documentation
- 🏗️ Modular architecture with NestJS modules
- 🧪 Test infrastructure with Jest
# Install dependencies
npm install
# Start development server
npm run start:dev
# Build for production
npm run build
# Start production server
npm run start:prodOnce the server is running, access the Swagger documentation at:
- URL:
http://localhost:3000/docs
| Method | Route | Description | Query Params |
|---|---|---|---|
GET |
/todos |
Get all todos | filter (optional): 'all' | 'active' | 'completed' |
GET |
/todos/:id |
Get a todo by ID | - |
POST |
/todos |
Create a new todo | - |
PUT |
/todos/:id |
Update a todo | - |
DELETE |
/todos/:id |
Delete a todo | - |
POST /todos
Content-Type: application/json
{
"title": "Complete the project"
}PUT /todos/:id
Content-Type: application/json
{
"title": "Updated title",
"completed": true
}GET /todos?filter=activegraph TB
Client[Client Request] --> Validation[Global ValidationPipe]
Validation --> Router[Express Router]
Router -->|GET /todos| GetAll[GET /todos<br/>Get All Todos]
Router -->|GET /todos/:id| GetOne[GET /todos/:id<br/>Get Todo by ID]
Router -->|POST /todos| Create[POST /todos<br/>Create Todo]
Router -->|PUT /todos/:id| Update[PUT /todos/:id<br/>Update Todo]
Router -->|DELETE /todos/:id| Delete[DELETE /todos/:id<br/>Delete Todo]
GetAll --> Controller[TodosController]
GetOne --> Controller
Create --> Controller
Update --> Controller
Delete --> Controller
Controller --> Service[TodosService]
Service -->|findAllTodos| FilterLogic[Filter Logic<br/>all/active/completed]
Service -->|findTodoById| FindLogic[Find by ID Logic]
Service -->|newTodo| CreateLogic[Create Logic<br/>Generate UUID & Date]
Service -->|updateTodo| UpdateLogic[Update Logic<br/>Merge DTO]
Service -->|deleteTodo| DeleteLogic[Delete Logic<br/>Filter Array]
FilterLogic --> Memory[In-Memory Storage<br/>Todo Array]
FindLogic --> Memory
CreateLogic --> Memory
UpdateLogic --> Memory
DeleteLogic --> Memory
Memory --> Response[Response]
Response --> Client
style Client fill:#e1f5ff
style Controller fill:#fff4e6
style Service fill:#f0f9ff
style Memory fill:#ffe6e6
style Response fill:#e8f5e9
src/
├── app.module.ts # Root application module
├── main.ts # Application entry point
├── common/
│ └── interfaces/
│ └── todo.model.ts # Todo interface and Filter type
└── todos/
├── todos.module.ts # Todos feature module
├── todos.controller.ts # Todos HTTP handlers
├── todos.service.ts # Todos business logic
└── dto/
├── create-todo.dto.ts # Create todo DTO
├── update-todo.dto.ts # Update todo DTO
└── todos-response.dto.ts # Response DTO
npm run build- Build the applicationnpm run format- Format code with Prettiernpm run start- Start the applicationnpm run start:dev- Start in development mode (watch mode)npm run start:debug- Start in debug modenpm run start:prod- Start production servernpm run lint- Run ESLintnpm run test- Run unit testsnpm run test:watch- Run tests in watch modenpm run test:cov- Run tests with coveragenpm run test:e2e- Run end-to-end tests
interface Todo {
id: string // UUID
title: string // Todo title
completed: boolean // Completion status
createdAt: Date // Creation timestamp
}type Filter = 'all' | 'active' | 'completed'- CreateTodoDto: Requires
title(string, min length 1) - UpdateTodoDto: Optional
title(string, min length 1) andcompleted(boolean)
All validation is handled automatically by the global ValidationPipe.
- Port: 3000 (configurable via
PORTenvironment variable) - Documentation:
/docs
UNLICENSED