Giter Club home page Giter Club logo

hex-arch-books's Introduction

Hexagonal architecture example: Books catalogue

Architecture

Project is divided into 3 main parts:

  • domain - contains business domain objects and business logic and ports as interfaces
  • adapter - contains adapter layer with ports implementations so called adapters
  • application - which is a Spring Boot application, configuration, logic needed for Spring boot working etc

It also contains some technical folders such:

  • e2e-tests-rest-client contains usefull rest client (IntelliJ) with some e2e tests
  • buildSrc which is a technical folder with gradle common configuration

Domain

Contains business objects and logic (not many use cases are now implemented, see BookValidator.java).

Domain logic and data is exposed outside by the primary ports called api. This kind of ports are used for to serve business cases as a REST API, SOAP, notification pushes to 3rd parties, etc.

For internal (business purposes) it uses secendary ports called spi to reach the external information needed for the business (like goodreads.com integration for fetching pics) or internal interactions and side effects (like DB or Elasticsearch etc).

Should not contain any dependencies (only libs allowed for dev convenience like lombok, commons etc).

Adapter

Implementation of ports from the domain. It contains both, internal and external, communication like DB communication, goodreads (outside world), ES, and REST api endpoints (Spring rest controllers).

It also contains mappers from domain to dto (adapter and case specific) objects.

Local run

DB

Application needs a DB to run:

docker compose up

The database (Postgres) is filed up with a data with automatic schema creation, each time the context is started. So after app restart the data will be lost.

There should be a migration mechanism like flyway or liquibase but I had no time to configure it.

Spring Boot

Start the app as a normal Spring boot application with some endpoints available

GET http://localhost:8080/actuator/health

POST http://localhost:8080/api/book
GET http://localhost:8080/api/book/list

Rest client implemented

e2e-tests-rest-client folder contains a simple client.rest which can be run on the IntelliJ IDEA.

Just tweak the POST payload and push "play" button. It also works as a simple test with assertions.

You can of course use other rest clients like Postman etc.

hex-arch-books's People

Contributors

lstolowski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.