Table of Contents
This project demonstrates a Spring application built under the Hexagonal Architecture, also known as Ports and Adapters Architecture. This approach aims for high cohesion and low coupling, promoting:
Separation of concerns: Business logic resides in the core of the application, isolated from external technologies and frameworks. Improved testability: The focus on the core facilitates the creation of unit and integration tests, ensuring code reliability. Robust maintainability: The modular architecture allows for easy modification and addition of functionalities without affecting the core code. Flexibility: The application easily adapts to different technologies and frameworks, as the core remains independent. Project Highlights:
Docker configurations: Automate the building, testing, and deployment of the application in Docker containers. Postman collection for API testing: Facilitate the testing of the application's REST APIs with pre-configured Postman collections. ArchUnit for Architecture Validation: Use ArchUnit to ensure that the application structure follows the principles of Hexagonal Architecture. Benefits of Hexagonal Architecture:
Cleaner and more robust code: The separation of responsibilities makes the code easier to understand and maintain. Easier testing: The modular architecture facilitates more comprehensive unit and integration tests. Flexibility for change: The application easily adapts to new technologies and requirements. Improved code reusability: Components can be easily reused in other applications.
- Java Development Kit (JDK)
- Docker
- Postman (para testar as chamadas à API)
- Mockoon (para simular a API externa)
- Java 17
- Maven
Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services.
- Clone the repo
git clone git@github.com:pedrop3/hexagonal.git
- Install dependencs
mvn clean install compile
- If you're using Visual Studio Code, you can simply run the project by configuring the
launch.json
- Run Docker Compose to start Kafka and MongoDB services:
cd docker-local docker-compose up -d
-
Import Postman Collection:
- Download the
Hexagonal.postman_collection.json. - Open Postman.
- Import the downloaded collection into Postman.
- Download the
-
Ensure Application is Running:
- Make sure the application is up and running.
-
Test Endpoints:
- Use the endpoints provided in the Postman collection to test the functionality of the application.
-
Install Mockoon:
- Install Mockoon from here.
-
Import Data:
- Download
addresses.json. - Open Mockoon.
- Import
addresses.jsoninto Mockoon to set up the simulation of the external API.
- Download
-
Start Mockoon Server:
- Start the Mockoon server.
-
Configure Application:
- Update the Spring application settings to make calls to the simulated API instead of the real API.
The project includes automated tests using ArchUnit to ensure that the hexagonal architecture is correctly followed. These tests are automatically executed during the compilation phase.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License.