HexaGO (A simple ports & adapter architecture example)
LocalAbout HexaGO (A simple ports & adapter architecture example)
HexaGO is a small Go calculator project demonstrating hexagonal (ports and adapters) architecture. It is intended as an example for developers studying how to separate application logic from external systems.
Key features
- 01Demonstrates ports and adapters
- 02Separates core logic from adapters
- 03Organizes interfaces as ports
- 04Includes a calculator app
Use cases
- 01Studying hexagonal architecture in Go
- 02Exploring core and adapter boundaries
- 03Using a small project as an architecture example
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEHexaGO (A simple ports & adapter architecture example)
This is a simple example of a calculator app using the ports & adapter architecture.
How to run
- Clone the repository
- Install air
go install github.com/cosmtrek/air@latest - Install templ
go install github.com/a-h/templ/cmd/templ@latest - Run
airin the root of the project - Open your browser and go to
http://localhost:3000
Inspiration
This project was inspired by the book Hexagonal Architecture by Alistair Cockburn & Juan Manuel Garrido de Paz (RIP).
The prupose of this project is to show a simple example of how to implement the ports & adapter architecture in a Go project.
License
Do with this project whatever you want. It's free and open source. No strings attached.
Introduction
What is hexago?
This is a small implementation of hexagonal architechture (ports and adapters) in golang.
What is hexagonal architecture?
Hexagonal architecture is a software design pattern that separates the application into different layers. This pattern is also known as ports and adapters pattern.
The main parts of the hexagonal architecture are:
- Core: This is the main part of the application. It contains the business logic and the domain model.
- Ports: These are the interfaces that the core uses to communicate with the outside world. They are defined in the core and implemented in the adapters.
- Drivers: These are the implementations of the ports. They are responsible for interacting with the external systems (databases, APIs, etc). -- Driving Adapters: These are the implementations of the drivers. They are responsible for translating the data between the core and the external systems.
- Adapters: These are the implementations of the ports. They are responsible for translating the data between the core and the external systems.
The main advantage of the hexagonal architecture is that it makes the application more testable and maintainable. The core is decoupled from the external systems, so it can be tested in isolation. The ports and adapters can be easily replaced with different implementations, so the application can be easily adapted to new requirements.
How to use hexago?
I like to separate the internal layer into multiple hexagon. Each hexagon lives in its own folder and has a folder structure like this:
<HexagonName>
├── core
│ ├── <HexagonName>.go
│ └── <HexagonName>_test.go
├── ports
│ ├── driven
│ │ ├── for<Verb><Action>.go // e.g forCreatingUser.go
│ │ └── for<Verb><Action>_test.go
│ └── driving
│ ├── for<Verb><Action>.go // e.g forCreatingUser.go
│ └── for<Verb><Action>_test.go
└── adapters
├── db.go
└── calculatorHTTP.go
The core folder contains the business logic and the domain model of the hexagon.
The ports folder contains the interfaces that the core uses to communicate with the outside world.
The adapters folder contains the implementations of the ports.
The ports are a collection of interfaces that limits the interaction between the core and the external systems.
How to start
- Clone the repository
- Install air
go install github.com/cosmtrek/air@latest - Install templ
go install github.com/a-h/templ/cmd/templ@latest - Run
airin the root of the project - Open your browser and go to
http://localhost:3000
Dockerization Todo steps
- Change
compose.ymlimage name to your image name - Change
nginx.confdomain name to your domain name - Change
.github/workflows/deploy.ymldocker image name to this same name
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.