Domain-Driven Design: Storage layer and MySQL client

  softwareengineering

I’m very new in DDD and I was following one of the videos of GohperCon to structure of my Golang App using DDD with Hexagonal Architecture. At the lowest (deepest) layer is the storage that can be Memory, JSON, SQL …

I’m planning to use MySQL and I structured my storage directory as follow:

app
|
+- storage
   |
   +- mysql
      |
      +- TABLE_NAME_0
         |
         +- model.go
         +- repository.go
      +- TABLE_NAME_1
         |
         +- model.go
         +- repository.go

I used the MySQL table name as the sub-folder of the mysql directory to separate the CRUD for each table.

But now I’m stuck with the MySQL connection. I want to create one connection and use it with both repository.go. I’m seeing 2 options (there might be more):

  1. Create clients directory under the app directory and have mysql.go to create client.
app
|
+- clients
   |
   +- mysql.go
+- storage
   |
   +- mysql
      |
      +- TABLE_NAME_0
         |
         +- model.go
         +- repository.go
      +- TABLE_NAME_1
         |
         +- model.go
         +- repository.go
  1. Create mysql.go under the mysql directory.
app
|
+- storage
   |
   +- mysql
      +- mysql.go
      +- TABLE_NAME_0
         |
         +- model.go
         +- repository.go
      +- TABLE_NAME_1
         |
         +- model.go
         +- repository.go

In either case, main.go uses that to create the MySQL client first and then pass it down to each repository.go.

I’m not sure which path is the right way or is my thinking and the approach for DDD is correct and I was hoping someone here can help me.

3

LEAVE A COMMENT