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.
- 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
- Framework: NestJS - Progressive Node.js framework
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT with Passport.js
- Password Hashing: Argon2
- Validation: Class-validator and class-transformer
- Documentation: Swagger/OpenAPI
- Testing: Jest
- Package Manager: pnpm
- Node.js (v18 or higher)
- pnpm
- Docker and Docker Compose
- PostgreSQL (or use Docker)
git clone https://github.com/devrapture/todo-list-api
cd todo-list-apipnpm installCreate a .env file in the root directory:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/todo_db?schema=public"
JWT_SECRET="your-super-secret-jwt-key"
PORT=3000# Start PostgreSQL with Docker
pnpm db:dev:up
# Apply database migrations
pnpm prisma:dev:deploy# Development mode
pnpm start:dev
# Production mode
pnpm start:prodThe API will be available at http://localhost:3000
Once the application is running, you can access the interactive API documentation at:
Swagger UI: http://localhost:3000/api/v1/docs
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/v1/auth/signup |
Register a new user |
| POST | /api/v1/auth/signin |
Login user |
All todo endpoints require JWT authentication. Include the token in the Authorization header: Bearer <your-jwt-token>
| 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 |
curl -X POST http://localhost:3000/api/v1/auth/signup \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X POST http://localhost:3000/api/v1/auth/signin \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "password123"
}'curl -X POST http://localhost:3000/api/v1/todos \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-jwt-token>" \
-d '{
"todo": "Buy groceries",
"dueDate": "2024-01-15T10:00:00Z"
}'id: UUID (Primary Key)email: String (Unique)password: String (Hashed with Argon2)createdAt: DateTimeupdatedAt: DateTime
id: UUID (Primary Key)todo: String (Task description)completed: Boolean (Default: false)dueDate: DateTime (Optional)userId: String (Foreign Key to User)createdAt: DateTimeupdatedAt: DateTime
# Unit tests
pnpm test
# E2E tests
pnpm test:e2e
# Test coverage
pnpm test:covThe project includes separate test database configuration:
- Test database runs on port 5433
- Automatically managed by test scripts
- Isolated from development database
# Start PostgreSQL
docker-compose up postgres -d
# Start the application
pnpm start:devpnpm db:dev:restart| 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 |
| Variable | Description | Default |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Required |
JWT_SECRET |
Secret key for JWT tokens | Required |
PORT |
Application port | 3000 |
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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
If you encounter any issues or have questions:
- Check the API documentation when the server is running
- Review the test files for usage examples
- Open an issue on GitHub
Built with β€οΈ using NestJS