A reactive REST API built with Spring Boot 3.5.6 and WebFlux for managing product inventory. This project follows Clean Architecture principles and includes comprehensive testing with 100% code coverage.
- Full CRUD Operations: GET, POST, PUT, PATCH, and DELETE for products
- Clean Architecture: Separation of domain, use cases, infrastructure, and presentation layers
- Reactive Programming: Built with Spring WebFlux and Project Reactor
- In-Memory Storage: Pre-loaded with 10 default products
- 100% Test Coverage: Comprehensive unit and integration tests
- Docker Support: Dockerfile and docker-compose for easy deployment
- CI/CD Pipeline: GitHub Actions workflow for automated testing and building
- Java 21
- Spring Boot 3.5.6
- Spring WebFlux (Reactive web framework)
- Project Reactor (Reactive programming)
- Springdoc OpenAPI (Swagger documentation)
- Lombok (Reduce boilerplate)
- JaCoCo (Code coverage)
- JUnit 5 & Mockito (Testing)
The project follows Clean Architecture with the following layers:
src/main/java/com/example/product/api/produc/
├── domain/
│ ├── model/Product.java
│ └── repository/ProductRepository.java
├── usecase/
│ ├── GetAllProducts.java
│ ├── GetProductById.java
│ ├── CreateProduct.java
│ ├── UpdateProduct.java
│ ├── PatchProduct.java
│ └── DeleteProduct.java
├── infrastructure/
│ └── repository/InMemoryProductRepository.java
└── presentation/
├── controller/ProductController.java
└── dto/
├── ProductRequest.java
└── ProductPatchRequest.java
GET /api/v1/productsGET /api/v1/products/{id}POST /api/v1/products
Content-Type: application/json
{
"name": "Product Name",
"description": "Product Description",
"price": 99.99,
"quantity": 10
}PUT /api/v1/products/{id}
Content-Type: application/json
{
"name": "Updated Name",
"description": "Updated Description",
"price": 149.99,
"quantity": 20
}PATCH /api/v1/products/{id}
Content-Type: application/json
{
"price": 149.99
}DELETE /api/v1/products/{id}This API includes Swagger/OpenAPI documentation for easy exploration and testing.
Once the application is running, visit:
- Swagger UI: http://localhost:8080/
- OpenAPI JSON: http://localhost:8080/api-docs
The Swagger UI provides:
- Interactive API documentation
- Try-it-out functionality for all endpoints
- Request/response examples
- Schema documentation
- Java 21
- Maven 3.6+
- Docker (optional)
# Build the project
./mvnw clean install
# Run the application
./mvnw spring-boot:runThe application will start on http://localhost:8080
# Build and run with Docker Compose
docker-compose up --build# Build the image
docker build -t product-api .
# Run the container
docker run -p 8080:8080 product-api./mvnw test./mvnw test -Dtest=ProductControllerTest./mvnw test jacoco:reportView the coverage report at: target/site/jacoco/index.html
The application is pre-loaded with 10 products:
- Laptop - $1,299.99
- Smartphone - $899.99
- Wireless Headphones - $249.99
- 4K Monitor - $449.99
- Mechanical Keyboard - $129.99
- Wireless Mouse - $49.99
- Tablet - $599.99
- HD Webcam - $89.99
- Bluetooth Speaker - $79.99
- USB-C Charger - $39.99
The project includes a GitHub Actions workflow that:
- Runs on push/pull requests to master/main branch
- Builds the project with Maven
- Runs all tests
- Generates and uploads coverage reports
- Builds Docker image
- Tests the Docker image
product-api/
├── .github/
│ └── workflows/
│ └── ci.yml
├── src/
│ ├── main/
│ │ ├── java/
│ │ └── resources/
│ └── test/
│ └── java/
├── Dockerfile
├── docker-compose.yml
├── pom.xml
└── README.md
This project is licensed under the MIT License.
- Fork the repository
- Create your 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