https://github.com/devrapture/todo-list-api
Todo List API
https://github.com/devrapture/todo-list-api
Last synced: 9 months ago
JSON representation
Todo List API
- Host: GitHub
- URL: https://github.com/devrapture/todo-list-api
- Owner: devrapture
- Created: 2025-08-12T16:22:49.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-08-18T18:12:38.000Z (10 months ago)
- Last Synced: 2025-08-18T20:23:19.251Z (10 months ago)
- Language: TypeScript
- Homepage: https://todo-list-api-c1r8.onrender.com/api/v1/docs
- Size: 270 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Todo List API
A robust and scalable REST API for managing todo tasks, built with NestJS, PostgreSQL, and Prisma. Features user authentication, JWT authorization, and comprehensive CRUD operations for todo management.
## ๐ Features
- **User Authentication**: Secure signup and signin with JWT tokens
- **Todo Management**: Full CRUD operations for todo tasks
- **User-specific Todos**: Each user can only access their own todos
- **Task Filtering**: Filter todos by completion status
- **Due Date Support**: Optional due dates for tasks
- **Database**: PostgreSQL with Prisma ORM
- **API Documentation**: Swagger/OpenAPI documentation
- **Testing**: Comprehensive unit and e2e tests
- **Docker Support**: Easy development setup with Docker Compose
## ๐ ๏ธ Tech Stack
- **Framework**: [NestJS](https://nestjs.com/) - Progressive Node.js framework
- **Database**: PostgreSQL with [Prisma](https://www.prisma.io/) ORM
- **Authentication**: JWT with Passport.js
- **Password Hashing**: Argon2
- **Validation**: Class-validator and class-transformer
- **Documentation**: Swagger/OpenAPI
- **Testing**: Jest
- **Package Manager**: pnpm
## ๐ Prerequisites
- Node.js (v18 or higher)
- pnpm
- Docker and Docker Compose
- PostgreSQL (or use Docker)
## ๐ Quick Start
### 1. Clone the repository
```bash
git clone https://github.com/devrapture/todo-list-api
cd todo-list-api
```
### 2. Install dependencies
```bash
pnpm install
```
### 3. Set up environment variables
Create a `.env` file in the root directory:
```env
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/todo_db?schema=public"
JWT_SECRET="your-super-secret-jwt-key"
PORT=3000
```
### 4. Start the database
```bash
# Start PostgreSQL with Docker
pnpm db:dev:up
# Apply database migrations
pnpm prisma:dev:deploy
```
### 5. Run the application
```bash
# Development mode
pnpm start:dev
# Production mode
pnpm start:prod
```
The API will be available at `http://localhost:3000`
## ๐ API Documentation
Once the application is running, you can access the interactive API documentation at:
**Swagger UI**: `http://localhost:3000/api/v1/docs`
### Authentication Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| POST | `/api/v1/auth/signup` | Register a new user |
| POST | `/api/v1/auth/signin` | Login user |
### Todo Endpoints
All todo endpoints require JWT authentication. Include the token in the Authorization header: `Bearer `
| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/api/v1/todos` | Get all todos (with optional filtering) |
| GET | `/api/v1/todos/:id` | Get a specific todo |
| POST | `/api/v1/todos` | Create a new todo |
| PATCH | `/api/v1/todos/:id` | Update a todo |
| DELETE | `/api/v1/todos/:id` | Delete a specific todo |
| DELETE | `/api/v1/todos` | Delete all todos |
### Example Usage
#### 1. Register a new user
```bash
curl -X POST http://localhost:3000/api/v1/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'
```
#### 2. Login
```bash
curl -X POST http://localhost:3000/api/v1/auth/signin \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'
```
#### 3. Create a todo (with JWT token)
```bash
curl -X POST http://localhost:3000/api/v1/todos \
-H "Content-Type: application/json" \
-H "Authorization: Bearer " \
-d '{
"todo": "Buy groceries",
"dueDate": "2024-01-15T10:00:00Z"
}'
```
## ๐๏ธ Database Schema
### User Model
- `id`: UUID (Primary Key)
- `email`: String (Unique)
- `password`: String (Hashed with Argon2)
- `createdAt`: DateTime
- `updatedAt`: DateTime
### Todos Model
- `id`: UUID (Primary Key)
- `todo`: String (Task description)
- `completed`: Boolean (Default: false)
- `dueDate`: DateTime (Optional)
- `userId`: String (Foreign Key to User)
- `createdAt`: DateTime
- `updatedAt`: DateTime
## ๐งช Testing
### Run all tests
```bash
# Unit tests
pnpm test
# E2E tests
pnpm test:e2e
# Test coverage
pnpm test:cov
```
### Test database setup
The project includes separate test database configuration:
- Test database runs on port 5433
- Automatically managed by test scripts
- Isolated from development database
## ๐ณ Docker
### Development with Docker
```bash
# Start PostgreSQL
docker-compose up postgres -d
# Start the application
pnpm start:dev
```
### Reset development database
```bash
pnpm db:dev:restart
```
## ๐ Available Scripts
| Script | Description |
|--------|-------------|
| `pnpm start` | Start the application |
| `pnpm start:dev` | Start in development mode with hot reload |
| `pnpm start:debug` | Start in debug mode |
| `pnpm start:prod` | Start in production mode |
| `pnpm build` | Build the application |
| `pnpm test` | Run unit tests |
| `pnpm test:e2e` | Run e2e tests |
| `pnpm test:cov` | Run tests with coverage |
| `pnpm lint` | Run ESLint |
| `pnpm format` | Format code with Prettier |
| `pnpm db:dev:up` | Start development database |
| `pnpm db:dev:restart` | Restart development database |
| `pnpm prisma:generate` | Generate Prisma client |
## ๐ง Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `DATABASE_URL` | PostgreSQL connection string | Required |
| `JWT_SECRET` | Secret key for JWT tokens | Required |
| `PORT` | Application port | 3000 |
## ๐ Project Structure
```
src/
โโโ auth/ # Authentication module
โ โโโ auth.controller.ts
โ โโโ auth.service.ts
โ โโโ dto/
โ โโโ guard/
โ โโโ strategy/
โโโ todos/ # Todo management module
โ โโโ todos.controller.ts
โ โโโ todos.service.ts
โ โโโ dto/
โโโ prisma/ # Database configuration
โ โโโ prisma.service.ts
โ โโโ prisma.module.ts
โโโ app.module.ts # Root module
โโโ main.ts # Application entry point
```
## ๐ค Contributing
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
## ๐ License
This project is licensed under the MIT License.
## ๐ Support
If you encounter any issues or have questions:
1. Check the [API documentation](http://localhost:3000/api/v1/docs) when the server is running
2. Review the test files for usage examples
3. Open an issue on GitHub
---
Built with โค๏ธ using NestJS