{"id":20828814,"url":"https://github.com/perty/hex","last_synced_at":"2025-03-12T07:44:41.250Z","repository":{"id":137743956,"uuid":"591890102","full_name":"perty/hex","owner":"perty","description":"An attempt to implement the hexagonal architecture using Spring Boot with Qualify to pick adapters.","archived":false,"fork":false,"pushed_at":"2023-01-22T15:59:34.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-18T18:40:27.937Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perty.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-22T08:29:23.000Z","updated_at":"2023-01-22T08:29:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"99ffdf41-cf83-444f-9de1-05eaed30897e","html_url":"https://github.com/perty/hex","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perty%2Fhex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perty%2Fhex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perty%2Fhex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perty%2Fhex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perty","download_url":"https://codeload.github.com/perty/hex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243179814,"owners_count":20249179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T23:18:31.136Z","updated_at":"2025-03-12T07:44:41.230Z","avatar_url":"https://github.com/perty.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hexagonal architecture, ports and adapters\n\nThis is a (third) attempt to implement the Hexagonal architecture with Spring Boot.\n\n## Goals\n\n### Obvious\n\nThe package structure and class names should make it obvious where in the architecture you are when reading the code. It\nshould be obvious where to add new code.\n\nThe first part of the package name, is one of `domain`, `config`, `in` or `out`.\n\nThe architecture has two sides, in and out, hence they are put on top. For each side, there are ports and adapters, so\nthose are the next level.\n\n### Configurable\n\nThe architecture promises that we can swap adapters as we please. To prove that, at least two adapters should support\nthe same port.\n\nFor outgoing port to persistence, Spring Boot injection with `@Qualify` is used. It would have been great if a property\ncould be used as argument but sadly not. Instead, a level of indirection had to be added where every possible\nqualification is represented. [See `DbConfig`](src/main/java/se/artcomputer/edu/hex/config/DbConfig.java) for details\nwhere a database or stub adapter is selected, based on the property `se.artcomputer.edu.db`\nin [application.properties](src/main/resources/application.properties).\n\n### Dependency control\n\nThe architecture has a clear idea about how dependencies go. The code must not take shortcuts and become tangled.\nTherefore, there is a test that scans the import statements and verifies that the rules are obeyed.\n[See`DependencyTest`](src/test/java/se/artcomputer/edu/hex/DependencyTest.java).\n\n#### Allowed dependencies\n\nThe rule is that the `domain` logic should be in the center and independent of technical aspects such as persistence mechanisms. \n\nIt is easy to believe that `in` and `out` are symmetric but `in` is the driving side while `out` is the driven side.\n\nAs an example, when a REST request arrives, the REST adapter uses the in port to call into the domain. The domain logic reaches for an outgoing port and the configuration controls which adapter will be selected for the outgoing port.\n\nThe config package only needs to know the `out` port, the adapters are injected by Spring.\n\n````mermaid\nclassDiagram\n    InAdapter --\u003e Domain\n    InAdapter --\u003e InPort\n    OutAdapter --\u003e OutPort\n    OutPort --\u003e Domain\n    OutAdapter --\u003e Domain\n    InPort --\u003e Domain\n    InPort --\u003e Config\n    Config --\u003e OutPort\n````\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperty%2Fhex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperty%2Fhex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperty%2Fhex/lists"}