4-hexagonal-architecture

command
v0.0.0-...-2b2e611 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 3 Imported by: 0

README ΒΆ

Hexagonal architecture

We arrive at one of the well-known ways of grouping functionality together - Hexagonal Architecture, also known as Ports & Adapters or the onion architecture. πŸ™‚

This is my favourite way of structuring Go apps, especially when coupled with a microservice architecture. I find that it scales well to problems of different sizes and complexity, and you can add or remove as many layers as you need:

β”œβ”€β”€ main.go
β”œβ”€β”€ dao
β”œβ”€β”€ domain
└── handler

You can also combine many smaller hex structures to form your entire program:

(imagine an app which compiles a restaurant menu by pulling information from three completely different sources)

β”œβ”€β”€ main.go
β”œβ”€β”€ beer
β”‚ β”œβ”€β”€ dao
β”‚ β”œβ”€β”€ domain
β”‚ β”œβ”€β”€ handler
β”‚ └── service.go
β”œβ”€β”€ wine
β”‚ β”œβ”€β”€ dao
β”‚ β”œβ”€β”€ domain
β”‚ β”œβ”€β”€ handler
β”‚ └── service.go
└── food
  β”œβ”€β”€ dao
  β”œβ”€β”€ domain
  β”œβ”€β”€ handler
  └── service.go

This structure is great for:

  • complex projects which require a well-defined structure to stay maintainable and understandable
  • applications which have dependencies such as databases, user interfaces or third party APIs

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL