This is an example of a keep-it-simple directory layout for Go projects that was created using DDD principles, please copy and share if you like it.

DDD Go Template

This project was created to illustrate a great architectural structure I developed together with @fabiorodrigues in the period I was working for Dito, they both deserve as much credit as me here.

This very powerful, but yet flat and simple, template is organized in 3 directories:

  • cmd/: Each subdirectory is an entrypoint for the project, e.g. a worker, an API or a CLI interface, each of these packages are responsible for decoding the configurations, performing the dependency injection and setting any Frameworks that might need to be setup (in our case we are using the fasthttp as an HTTP framework).

  • domain/: This package contains the domain language and is meant to be imported by all other packages in order to allow a decoupled comunication between them.

    Each subpackage of the domain is a Service, and its where we should concentrate the domain logic.

  • infra/: each subdirectory contains either an adapter pattern making an external functionality available to the domain in the form of an interface (check the memorycache package for an example on this) or simple packages that extract logic that is unrelated to the to domain in order to move as much code away from the services as possible.

    One other thing that we keep here are the repositories, which are the often the only infra packages that actually use the entities directly, althought this is not prohibited by DDD.

    The idea here is that the Services contain the most complex and important parts of the project, thus, by moving any logic that is not related to the domain away from the Services we can keep the Services as simple as they can possibly be, which makes the code a lot easier to maintain.

For portuguese readers we have a more descriptive explanation of this architecture here:

And if you prefer to watch a presentation (also in portuguese) we have this one:

Similar Resources

Questions and answers example project.

Question Answer Service REST Service for questions and answers Database modeling Directory tree pkg: Here is the main source code. sql: Here are all t

Dec 17, 2021

At this example project, I'm trying to learn Golang with Clean structure and come up with a reusable

Learning Golang Language In Clean Structure At this example project, I'm trying to learn Golang with Clean structure and come up with a reusable, nice

Sep 25, 2022

Learn-Nakama - An example project template on how to set up and write custom logic in Nakama server

Nakama Project Template An example project template on how to set up and write c

Apr 18, 2022

Example repository for embedding Litestream in a Go application.

Litestream as Library This repository is an example of embedding Litestream as a library in a Go application. The Litestream API is not stable so you

Dec 6, 2022

go mev-geth example. signTx,send transaction to relay.

go-mev-geth go mev-geth example. signTx,send transaction to relay. sample smart contract /eth/contract/mevtransfer/mevtransfer.sol pragma solidity 0.6

Dec 9, 2022

Example code for my Cadence Intro Workshop

Temporal Intro Workshop This repository contains example code for my Temporal Intro Workshop. Prerequisites Git, Make, etc. Make sure you have the lat

Dec 18, 2022

Example resource for alt:V Go module

Example resource for alt:V Go module

Dec 9, 2022

Example go clean architecture folder pattern

Golang Clean Architecture (Maintenance) Berikut ini adalah folder structure pattern yang biasa saya gunakan, walaupun tidak semua nya saya terapkan di

Dec 21, 2022

Go realworld example

TODOs Users and Authentication POST /user/login: Existing user login POST /users: Register a new user GET /user: Get current user PUT /user: Update cu

Dec 8, 2022
I will be uploading some basic programming in Golang so if you want to contribute please Fork this repo and contriute.
I will be uploading some basic programming in Golang so if you want to contribute please Fork this repo and contriute.

Go-language I will be uploading some basic programming in Golang so if you want to contribute please Fork this repo and contriute. This repo is for pr

Jan 21, 2022
Practical DDD in Golang

DDD на практике в Golang Russian translation of article series: "Practical DDD in Golang". Practical DDD in Golang: Value Object Practical DDD in Gola

Dec 20, 2022
Go.work-workspace-example - Go1.18 workspace example

Go.work-workspace-example - Go1.18 workspace example

Jan 20, 2022
This is a brief tutorial I created for a couple friends to show how to do some stuff in go and ethereum. Feel free to do any PRs with suggestions

golang-tutorial This is a brief tutorial I created for a couple friends to show how to do some stuff in Go and Ethereum. Milestones Create the environ

Aug 29, 2022
Learn Golang in-depth by solving 15 Quizzes, 10 Exercises and 4 Projects
Learn Golang in-depth by solving 15 Quizzes, 10 Exercises and 4 Projects

Modern Go (Golang) - The Complete Beginners Guide 2021 Learn Go (Golang) in-dept

Jan 1, 2023
Getting better at Linux with 10 mini-projects.

10 things Linux How do you advance your Linux skills when you are already comfortable with the basics? My solution was to come up with 10 subjects to

Dec 25, 2022
Learning GO language by building projects
Learning GO language by building projects

GoLangProjects Projects list Helloworld Variables Userinput Conversion Math, crypto & random Time & Date Pointers Arrays Slices Maps Structures If-Els

Dec 5, 2022
Here is the collection of beginner friendly golang projects

Golang Mini Projects for Beginners Here is the collection of beginner friendly golang projects Mini Projects Book Store cli app to list, add, update,

Dec 29, 2022
This tutorial walks you through using the Cloud Functions minimal instances feature to mitigate cold starts.
This tutorial walks you through using the Cloud Functions minimal instances feature to mitigate cold starts.

Tutorial This tutorial walks you through using the Cloud Functions minimal instances feature to mitigate cold starts. Let’s take a deeper look at min

Jun 1, 2022
Example skills and a cli utility written in Go for interacting with Webex Assistant Skills

Webex Assistant Skills - Go This repository holds example skills and a cli utility written in Go for interacting with Webex Assistant Skills. It is in

Oct 29, 2021