Comments (6)
Sure, Building Go microservices in a monorepo with the Hexagon architecture can be a powerful way to organize your codebase and achieve modularity while keeping related services together. I think that we can organize the following structure:
├── go.mod
├── go.sum
├── microservice1
│ ├── cmd
│ │ └── main.go
│ ├── internal
│ │ ├── app
│ │ │ ├── controller
│ │ │ │ └── user_controller.go
│ │ │ ├── dto
│ │ │ │ └── user_dto.go
│ │ │ ├── entity
│ │ │ ├── model
│ │ │ │ ├── request
│ │ │ │ │ └── user_request.go
│ │ │ │ └── response
│ │ │ │ └── user_response.go
│ │ │ ├── port
│ │ │ │ ├── repository
│ │ │ │ │ ├── db_user_repository.go
│ │ │ │ │ └── user_repository.go
│ │ │ │ └── service
│ │ │ │ └── user_service.go
│ │ │ └── server
│ │ │ └── http_server.go
│ │ └── infra
│ │ ├── config
│ │ │ └── config.go
│ │ └── repository
│ │ ├── db.go
│ │ └── user_persistence.go
│ └── go.mod
├── microservice2
│ ├── cmd
│ │ └── main.go
│ ├── internal
│ │ ├── app
│ │ │ ├── controller
│ │ │ │ └── order_controller.go
│ │ │ ├── dto
│ │ │ │ └── order_dto.go
│ │ │ ├── entity
│ │ │ ├── model
│ │ │ │ ├── request
│ │ │ │ │ └── order_request.go
│ │ │ │ └── response
│ │ │ │ └── order_response.go
│ │ │ ├── port
│ │ │ │ ├── repository
│ │ │ │ │ ├── db_order_repository.go
│ │ │ │ │ └── order_repository.go
│ │ │ │ └── service
│ │ │ │ └── order_service.go
│ │ │ └── server
│ │ │ └── http_server.go
│ │ └── infra
│ │ ├── config
│ │ │ └── config.go
│ │ └── repository
│ │ ├── db.go
│ │ └── order_persistence.go
│ └── go.mod
...
By structuring the monorepo this way, you can maintain clear separation of concerns, keep each microservice's components organized, and ensure a clean and modular codebase following the Hexagonal architecture principles.
from go-experienced-series.
Yes, I want to be isolated between them. We need to isolate resources (entities, structs, helper functions, etc.), it's a good practice to organize them within the project's directory structure. Each microservice or module should have its own directory, and resources specific to that microservice should reside within that directory. By organizing the resources within the respective microservice's directory, it ensures that each microservice has its own dedicated space, and it's less likely to introduce conflicts or confusion.
from go-experienced-series.
That's right. Creating a separate module or package for common logic is a good practice. However, it's essential to keep the shared package focused on truly common and reusable functionality. Avoid adding too many unrelated functionalities, as it may increase the package's complexity and make it harder to manage.
I often separate them to another repo as library, then importing this lib to my project.
from go-experienced-series.
Hmmm, What do you think about go workspace, I see in root folder you have the go.mod file. Or you want the resource like (entity, struct, helper func, etc) should be isolated?
from go-experienced-series.
What do you think about some reuseable code something like the database connection with the retry connect logic in the function make connection to the database: mysql, redis, postgresql, etc, I think this will be better if I have 1 module for common logic I just mention about (maybe not include entity, struct as well)
from go-experienced-series.
Thanks @phamtai97
from go-experienced-series.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-experienced-series.