{"id":23821231,"url":"https://github.com/rinosukmandityo/hexagonal-login","last_synced_at":"2025-10-04T03:14:55.994Z","repository":{"id":230500682,"uuid":"238090895","full_name":"rinosukmandityo/hexagonal-login","owner":"rinosukmandityo","description":"Sample of hexagonal architecture to handle login logic and user CRUD","archived":false,"fork":false,"pushed_at":"2020-03-26T01:16:05.000Z","size":1815,"stargazers_count":16,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T17:51:26.325Z","etag":null,"topics":["go","golang","hexagonal","hexagonal-architecture"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/rinosukmandityo.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}},"created_at":"2020-02-04T00:30:16.000Z","updated_at":"2024-02-10T19:39:51.000Z","dependencies_parsed_at":"2024-03-30T05:34:39.620Z","dependency_job_id":"219f5f46-4e28-4faa-b06e-6ed58ddde2f9","html_url":"https://github.com/rinosukmandityo/hexagonal-login","commit_stats":null,"previous_names":["rinosukmandityo/hexagonal-login"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rinosukmandityo/hexagonal-login","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinosukmandityo%2Fhexagonal-login","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinosukmandityo%2Fhexagonal-login/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinosukmandityo%2Fhexagonal-login/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinosukmandityo%2Fhexagonal-login/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rinosukmandityo","download_url":"https://codeload.github.com/rinosukmandityo/hexagonal-login/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rinosukmandityo%2Fhexagonal-login/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260639179,"owners_count":23040455,"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":["go","golang","hexagonal","hexagonal-architecture"],"created_at":"2025-01-02T08:33:10.670Z","updated_at":"2025-10-04T03:14:50.959Z","avatar_url":"https://github.com/rinosukmandityo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hexagonal-login\nSample of hexagonal architecture to handle login logic and user CRUD\n\nHow to run\n---\n#### Set Environment Variable\nThis application support 2 kind of database MySQL and MongoDB to prove our ports is completely agnostic from the implementation.  \nBy default it will connect into our mongo DB database with default host \u0026 port `localhost:27017` and collection `local`  \nTo connect into different database we need to set database information in environment variable  \n\n1. MongoDB\n\n```cli\nset url=mongodb://localhost:27017/local  \nset timeout=30  \nset db=local  \nset driver=mongo  \n```\n\n2. MySQL\n\n```cli\nset url=root:Password.1@tcp(127.0.0.1:3306)/tes\nset timeout=10\nset db=tes\nset driver=mysql\n```\n\nAfter setting the database information we only need to run the main.go file  \n`go run main.go`  \n\n#### API List \u0026 Payloads\nHere is our API List and its payload:  \n\n1. [GET] **/user/{_user\\_id_}**  \n`/user/userid01`\n2. [POST] **/user**  \n`/user`\n```javascript\n{\n\tName:     \"Name\",  \n\tUsername: \"username\",  \n\tPassword: \"Password.User\",  \n\tID:       \"userid01\",  \n\tEmail:    \"usermail01@gmail.com\",  \n\tAddress:  \"User Address 01\",  \n\tIsActive: false  \n}\n```\n3. [PUT] **/user/{_user\\_id_}**  \n`/user/userid01`\n```javascript\n{\n\tName:     \"Name\",  \n\tUsername: \"username\",  \n\tPassword: \"Password.User\",  \n\tID:       \"userid01\",  \n\tEmail:    \"usermail01@gmail.com\",  \n\tAddress:  \"User Address 01\",  \n\tIsActive: false  \n}\n```\n4. [DELETE] **/user/{_user\\_id_}**  \n`/user/userid01`\n\n5. [POST] **/auth**  \n```javascript\n{  \n\tUsername: \"username\",  \n\tPassword: \"Password.User\"\n}\n```\n\n\nHexagonal Architecture Concept\n---\nThe concept of **Hexagonal Architecture** is to make sure that we divide our software in such a way that each piece of the software maintains its separation of concerns so that our application is modular.  \n\n#### Domain Logic \n_**App \u0026 Domain Logic**_ needs to be completely separated from the infrastructure like database or web service.  \nIn the figure below, we have _**Domain Logic**_ in the middle and _**Ports \u0026 Adapters**_ layer on the outside which connect the _**Domain Logic**_ to outside things like a user interface, Repository, REST API, External API or Message Queue.  \nSo whenever our _**Domain Logic**_ needs some infrastructure then we need to make our _**Domain Logic**_ to depend on _**Ports**_.\n\n#### Ports\nPorts are simply interfaces that represent what that infrastructure needs to do.  \nFor example if we need to get user data from a database, a port can be an interface that has a method that returns a list of users.  \nThese ports are completely agnostic from the implementation.\n\n#### Adapters\nAdapters do the concrete action and talk to the infrastructure  \nIn the figure we can see that these Adapters are outside of the Domain Logic so that we keep our Domain Logic completely ignorant about infrastructure  \nYou can refer to below images to gain more clarity, I got [this image from medium post](https://medium.com/@msmechatronics/hexagonal-architecture-in-java-5b21ebea849d)\n :\n\n![alt hexagonal-architecture](https://miro.medium.com/max/1689/1*dayDz6OTNc2qSS3QhppATA.png)\n\nBy using this architecture we can make sure that the _**Business Logic**_ itself is independent of any kind of framework.  \nSo if we rely on framework to one of our _**Ports \u0026 Adapters**_, if the framework become depreciated or if want to use a different framework we could just take our _**Business Logic**_ and move it over to that other framework.  \nWe also can make sure that our _**Domain Logic**_ are testable without any of the _**Port \u0026 Adapters**_, so if we don't have a database or an API we can still test the _**Business Logic**_ and make sure that it actually works properly\n\n#### The service that we are going to build  \n\nSo we have our service which is a user management and login and it will connect to serializer which will either serialize the data into json or message pack before serving it through REST API  \nAnd then on the other side we have our repository which will either choose to use MongoDB or MySQL based on how we start the application from command line.  \nSo basically our API will be able to accept JSON or message pack format and also our repository is able to use both MongoDB and MySQL and it won't really affect our service\n\nProject Structure\n---\nBy implementing Hexagonal Architecture we also implement Dependency Inversion and Dependency Injection. Here is some explanations about project structure:\n\n1. **api**  \ncontains handler for API\n2. **models**  \ncontains data models\n3. **repositories**  \ncontains **Port** interface for repository adapter\n   - **mongodb**  \ncontains mongo **Adapter** that implement UserRepository interface. This package will store mongo client and connect to mongoDB database to handle database query or command\n   - **mysql**  \ncontains MySQL **Adapter** that implement UserRepository interface. This package will store MySQL client and connect to MySQL server to handle database query or data manipulation\n4. **serializer**  \ncontains **Port** interface for decode and encode serializer. It will be used in our API to decode and encode data.\n   - **json**  \ncontains json **Adapter** that implement serializer interface to encode and decode data\n   - **msgpack**  \ncontains message pack **Adapter** that implement serializer interface to encode and decode data\n5. **services**  \ncontains **Port** interface for our domain service and logic \n6. **logic**  \ncontains service **Adapter** that implement service interface to handle service logic like constructing repository parameter and calling repository interface to do data manipulation or query","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frinosukmandityo%2Fhexagonal-login","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frinosukmandityo%2Fhexagonal-login","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frinosukmandityo%2Fhexagonal-login/lists"}