title | keywords | description | |||
---|---|---|---|---|---|
Hexagonal Architecture |
|
A Hexagonal Software Architecture in Golang and MongoDB. |
This project presents a simple product catalogue microservice to demonstrate the principles of a hexagonal software architecture. The microservice exposes a RESTful API that allows consuming applications to perform CRUD operations on a product catalogue. The microservice is developed in Golang, and the product catalogue data is persisted in a MongoDB repository.
- Go 1.18 or higher
- MongoDB
- Go modules
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/hexagonal
-
Install dependencies:
go mod tidy
-
Configure the MongoDB connection in the
config.json
file:{ "DB_URI": "your_mongodb_uri", "DB_Name": "your_db_name" }
-
Run the application:
go run main.go
-
The server will start on
http://localhost:3000
.
Method | URL | Description |
---|---|---|
GET | /api/v1/products | Retrieves all products |
GET | /api/v1/product/:id | Retrieves a product by ID |
POST | /api/v1/product | Creates a new product |
PUT | /api/v1/product/:id | Updates an existing product |
DELETE | /api/v1/product/:id | Deletes a product |
curl -X GET http://localhost:3000/api/v1/products
curl -X GET http://localhost:3000/api/v1/product/1
curl -X POST http://localhost:3000/api/v1/product -d '{"name": "New Product", "price": 100}' -H "Content-Type: application/json"
curl -X PUT http://localhost:3000/api/v1/product/1 -d '{"name": "Updated Product", "price": 150}' -H "Content-Type: application/json"
curl -X DELETE http://localhost:3000/api/v1/product/1
Hexagonal architecture, also known as ports and adapters architecture, is a design pattern used to create loosely coupled application components that can be easily connected to their software environment by means of ports and adapters. This architecture allows an application to be equally driven by users, programs, automated tests, or batch scripts, and to be developed and tested in isolation from its eventual runtime devices and databases.
For more information on hexagonal architecture, you can refer to the following resources: