Personal exploration project to implement Hexagonal Architecture (Clean Architecture) alongside modern automation tools in the Spring Boot ecosystem.
- Description
- Architecture
- Tech Stack
- Project Structure
- Installation and Execution
- API Endpoints
- Technical Features
- Key Learnings
This project implements a product management system using Hexagonal Architecture, with the goal of exploring clean architecture patterns and code automation tools. The system exposes a complete REST API for CRUD operations on products.
- Implement Hexagonal Architecture with clear separation of concerns
- Automate API code generation using OpenAPI Generator
- Explore modern tools in the Spring Boot ecosystem
- Apply development and testing best practices
The project follows Hexagonal Architecture principles by organizing code into the following layers:
βββββββββββββββββββββββββββββββββββββββββββ
β π API Layer β
β (Controllers, DTOs) β
βββββββββββββββββββββββββββββββββββββββββββ€
β π§ Application Layer β
β (Services, Use Cases) β
βββββββββββββββββββββββββββββββββββββββββββ€
β π Domain Layer β
β (Entities, Business Rules) β
βββββββββββββββββββββββββββββββββββββββββββ€
β π Infrastructure Layer β
β (Repositories, Database, JPA) β
βββββββββββββββββββββββββββββββββββββββββββ
- Port:
ProductRepository(domain interface) - Adapter:
ProductRepositoryAdapter(JPA implementation)
| Technology | Version | Purpose |
|---|---|---|
| Java | 17 | Base language |
| Spring Boot | 3.x | Main framework |
| Spring Data JPA | - | Data persistence |
| PostgreSQL | - | Database |
| OpenAPI Generator | - | Automatic API generation |
| MapStruct | - | Layer mapping |
| Lombok | - | Boilerplate reduction |
| Maven | - | Dependency management |
| Hibernate Validator | - | Data validation |
barcodehub/
βββ domain/ # π Domain Layer
β βββ src/main/java/
β β βββ model/
β β β βββ Product.java
β β βββ exception/
β β βββ NotFoundException.java
β β βββ BusinessErrorCodes.java
β βββ pom.xml
βββ app-service/ # π§ Application Layer
β βββ src/main/java/
β β βββ service/
β β βββ port/
β β β βββ ProductRepository.java
β β βββ mapper/
β β βββ ProductMapper.java
β βββ pom.xml
βββ infrastructure/ # π Infrastructure Layer
β βββ src/main/java/
β β βββ adapter/
β β β βββ ProductRepositoryAdapter.java
β β βββ entity/
β β β βββ ProductEntity.java
β β βββ repository/
β β β βββ JpaProductRepository.java
β β βββ controller/
β β β βββ ProductController.java
β β βββ mapper/
β β βββ ProductEntityMapper.java
β βββ src/main/resources/
β β βββ openapi.yaml
β β βββ application.properties
β βββ pom.xml
βββ pom.xml # Parent POM
- Java 17+
- Maven 3.8+
- PostgreSQL 12+
-
Clone the repository
git clone <repository-url> cd barcodehub
-
Setup database
CREATE DATABASE productdb;
-
Configure properties (optional)
# src/main/resources/application.properties spring.datasource.url=jdbc:postgresql://localhost:5432/productdb spring.datasource.username=your_user_postgre spring.datasource.password=your_password_postgre
-
Compile the project
mvn clean compile
-
Run the application
mvn spring-boot:run -pl infrastructure
The application will be available at http://localhost:8080
| Method | Endpoint | Description |
|---|---|---|
GET |
/products |
Get all products |
POST |
/products |
Create a new product |
GET |
/products/{id} |
Get product by ID |
PUT |
/products/{id} |
Update existing product |
DELETE |
/products/{id} |
Delete product |
{
"name": "Dell XPS Laptop",
"price": 1299.99
}- OpenAPI Generator automatically generates:
- Controller interfaces (
ProductApi) - API DTOs (
ProductDto,DataProductListDto) - Validation annotations
- API documentation
- Controller interfaces (
- MapStruct handles mapping between:
Product(Domain) βProductEntity(JPA)Product(Domain) βProductDto(API)
- OpenAPI Generator Plugin: Compile-time generation
- Build Helper Plugin: Generated code integration
- Annotation Processing: Lombok + MapStruct
- Clear separation of responsibilities facilitates testing and maintenance
- Ports and adapters allow changing implementations without affecting domain
- Dependency inversion makes code more testable and flexible
- OpenAPI Generator significantly reduces boilerplate code
- YAML specifications as single source of truth for API
- Build-time generation keeps code and documentation synchronized
- Spring Data JPA simplifies persistence operations
- MapStruct is incredibly efficient for object mapping
- Maven multi-module better organizes complex projects
- Domain validation keeps business rules centralized
- Custom exceptions improve error handling
- Layer-specific DTOs avoid coupling
This is a personal learning project, but if you find improvements or have suggestions, feel free to:
- Fork the project
- Create a feature branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -am 'Add new improvement') - Push to the branch (
git push origin feature/improvement) - Create a Pull Request
β If you found this project useful, don't forget to give it a star
π¬ Have questions? Feel free to open an issue or contact me directly.
Developed with β€οΈ to explore modern architectures and development best practices