A robust, production-ready RESTful API for managing tasks built with Spring Boot. This project demonstrates modern Java development practices, clean architecture, and enterprise-level features including pagination, filtering, DTO mapping, and database versioning.
- CRUD Operations: Complete Create, Read, Update, and Delete operations for tasks
- Pagination: Efficient pagination support with customizable page size (default: 5 tasks per page)
- Filtering: Advanced filtering capabilities by:
- Priority (LOW, MEDIUM, HIGH)
- Status (NOT_STARTED, PENDING, IN_PROGRESS, COMPLETED)
- Combined priority and status filters
- Sorting: Automatic sorting by task title in ascending order
- Task Management:
- Create tasks with title, description, priority, status, and due date
- Update existing tasks
- Retrieve tasks by ID or with pagination
- Delete tasks
- DTO Pattern: Separation of concerns using Data Transfer Objects (DTOs) for API responses
- MapStruct Integration: Type-safe, compile-time entity-to-DTO mapping with zero runtime overhead
- Input Validation: Comprehensive validation using Jakarta Bean Validation
- Exception Handling: Custom exception handling with
ResourceNotFoundexception - Global Response Wrapper: Consistent API response structure with
ApiResponsewrapper - Database Versioning: Liquibase integration for database schema and data migration management
- JPA Auditing: Automatic timestamp management for entity creation dates
- HATEOAS Support: Spring HATEOAS integration for RESTful API design
- Spring Boot 3.5.7: Modern Java application framework
- Java 25: Latest Java features and performance improvements
- Spring Data JPA: Simplified database access and repository pattern
- PostgreSQL: Robust relational database management system
- Liquibase: Database schema versioning and migration tool
- MapStruct 1.6.3: Compile-time code generation for object mapping
- Jakarta Bean Validation: Input validation and constraint enforcement
- Lombok: Reduced boilerplate code with annotations
- Gradle: Modern build automation and dependency management
- Spring Boot DevTools: Enhanced development experience with hot reload
- JUnit 5: Comprehensive testing framework
/api/tasks
GET /api/tasks?page={pageNumber}&priority={priority}&status={status}Query Parameters:
page(optional, default: 0): Page number (0-indexed)priority(optional): Filter by priority (LOW, MEDIUM, HIGH)status(optional): Filter by status (NOT_STARTED, PENDING, IN_PROGRESS, COMPLETED)
Response:
{
"content": [
{
"id": 1,
"title": "Complete project documentation",
"description": "Write comprehensive README",
"status": "IN_PROGRESS",
"priority": "HIGH",
"due_date": "2024-12-31",
"created_at": "2024-11-09"
}
],
"page_number": 0,
"page_size": 5,
"total_elements": 10,
"total_pages": 2,
"last": false
}GET /api/tasks/{id}Response:
{
"id": 1,
"title": "Complete project documentation",
"description": "Write comprehensive README",
"status": "IN_PROGRESS",
"priority": "HIGH",
"due_date": "2024-12-31",
"created_at": "2024-11-09"
}POST /api/tasks
Content-Type: application/jsonRequest Body:
{
"title": "New Task",
"description": "Task description",
"status": "NOT_STARTED",
"priority": "MEDIUM",
"due_date": "2024-12-31"
}Validation Rules:
title: Required, max 100 charactersstatus: Requiredpriority: Requireddue_date: Must be today or in the future
PUT /api/tasks/{id}
Content-Type: application/jsonRequest Body: Same as Create Task
DELETE /api/tasks/{id}Response: true on successful deletion
CREATE TABLE tasks (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
description TEXT,
status VARCHAR(50),
priority VARCHAR(50),
due_date DATE,
created_at DATE DEFAULT CURRENT_DATE
);Priority:
LOWMEDIUMHIGH
TaskStatus:
NOT_STARTEDPENDINGIN_PROGRESSCOMPLETED
βββββββββββββββββββββββββββββββββββ
β REST Controller Layer β (TaskRestController)
βββββββββββββββββββββββββββββββββββ€
β Service Layer β (TaskService, TaskServiceImpl)
βββββββββββββββββββββββββββββββββββ€
β Repository Layer β (TaskRepository)
βββββββββββββββββββββββββββββββββββ€
β Entity Layer β (Task)
βββββββββββββββββββββββββββββββββββ
-
Controller Layer (
TaskRestController)- Handles HTTP requests and responses
- Input validation
- DTO conversion using MapStruct
-
Service Layer (
TaskServiceImpl)- Business logic implementation
- Pagination and filtering logic
- Exception handling
-
Repository Layer (
TaskRepository)- Extends Spring Data JPA
JpaRepository - Custom query methods for filtering
- Database abstraction
- Extends Spring Data JPA
-
Entity Layer (
Task)- JPA entity with Lombok annotations
- JPA Auditing for automatic timestamp management
-
DTO Layer (
TaskDTO)- Data Transfer Objects for API communication
- Validation constraints
- Separation from entity layer
-
Mapper Layer (
TaskMapper)- MapStruct interface for entity-DTO conversion
- Extends
BaseMapperfor reusable mapping logic - Compile-time code generation
src/
βββ main/
β βββ java/
β β βββ com/kyra/TaskManager/
β β βββ TaskManagerApplication.java
β β βββ controllers/
β β β βββ TaskRestController.java
β β βββ service/
β β β βββ TaskService.java
β β β βββ impl/
β β β βββ TaskServiceImpl.java
β β βββ repository/
β β β βββ TaskRepository.java
β β βββ db/
β β β βββ Task.java
β β β βββ enums/
β β β βββ Priority.java
β β β βββ TaskStatus.java
β β βββ dto/
β β β βββ TaskDTO.java
β β β βββ PagedResponse.java
β β βββ converters/
β β β βββ BaseMapper.java
β β β βββ TaskMapper.java
β β βββ exceptions/
β β β βββ ResourceNotFound.java
β β βββ advice/
β β βββ ApiResponse.java
β β βββ GlobalResponseHandler.java
β βββ resources/
β βββ application.properties
β βββ db/
β βββ changelog/
β βββ main-changelog.xml
β βββ schema/
β β βββ 01-create-task-table.sql
β βββ data/
β βββ 01-insert-starter-values.sql
βββ test/
βββ java/
βββ com/kyra/TaskManager/
βββ TaskManagerApplicationTests.java
- Java 25 or higher
- PostgreSQL 12 or higher
- Gradle 9.2 or higher
-
Clone the repository
git clone <repository-url> cd TaskManager
-
Set up PostgreSQL database
CREATE DATABASE taskmgr;
-
Configure database connection
Update
src/main/resources/application.properties:spring.datasource.url=jdbc:postgresql://localhost:5432/taskmgr spring.datasource.username=your_username spring.datasource.password=your_password
-
Run Liquibase migrations
The database schema will be automatically created on application startup via Liquibase.
-
Build the project
./gradlew build
-
Run the application
./gradlew bootRun
Or using the JAR:
java -jar build/libs/TaskManager-0.0.1-SNAPSHOT.jar
-
Access the API
The application will start on
http://localhost:8080Test the API:
curl http://localhost:8080/api/tasks
Run tests using Gradle:
./gradlew testKey configuration options in application.properties:
- Database: PostgreSQL connection settings
- Liquibase: Database migration configuration
- Jackson: JSON property naming strategy (SNAKE_CASE)
- JPA: Hibernate DDL auto mode (set to
nonefor production)
- β Clean Architecture: Separation of concerns with layered architecture
- β DTO Pattern: Prevents entity exposure and provides API versioning flexibility
- β MapStruct: Zero-overhead object mapping at compile-time
- β Input Validation: Comprehensive validation using Jakarta Bean Validation
- β Exception Handling: Custom exceptions with proper error handling
- β Database Versioning: Liquibase for schema and data migration management
- β Pagination: Efficient data retrieval with Spring Data pagination
- β Filtering: Dynamic query methods for flexible data retrieval
- β Code Generation: Lombok for reducing boilerplate code
- β RESTful Design: Proper HTTP methods and status codes
- Compile-time code generation (MapStruct, Lombok)
- Efficient pagination to reduce memory footprint
- Database indexing on frequently queried fields
- JPA query optimization with custom repository methods
- Input validation on all endpoints
- SQL injection prevention through JPA parameterized queries
- Proper exception handling to avoid information leakage
# Clean build
./gradlew clean build
# Run application
./gradlew bootRun
# Run tests
./gradlew test
# Generate MapStruct implementations
./gradlew compileJava- MapStruct: Generated implementations in
src/main/generated/ - Lombok: Compile-time code generation for getters, setters, builders
| Technology | Version | Purpose |
|---|---|---|
| Spring Boot | 3.5.7 | Application framework |
| Spring Data JPA | 3.5.7 | Data access layer |
| PostgreSQL | Latest | Database |
| Liquibase | Latest | Database migrations |
| MapStruct | 1.6.3 | Object mapping |
| Lombok | Latest | Code generation |
| Jakarta Validation | Latest | Input validation |
| Spring HATEOAS | 3.5.7 | RESTful API support |
This is a personal project, but suggestions and improvements are welcome!
This project is open source and available for educational purposes.
Kyra
- Built with Spring Boot and modern Java best practices
- Demonstrates enterprise-level RESTful API development
Note: This project demonstrates proficiency in:
- Spring Boot and Spring ecosystem
- RESTful API design and implementation
- Database design and migration management
- Object-oriented programming and design patterns
- Build tools and dependency management
- Code quality and best practices