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.

Overview

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:

You might also like...
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

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

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

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

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

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

Example resource for alt:V Go module

Example resource for alt:V Go module

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

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

Owner
Vinícius Garcia
Vinícius Garcia
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

Sahitya Roy 3 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

Maksim Dzhangirov 9 Nov 11, 2022
Go.work-workspace-example - Go1.18 workspace example

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

Andrey Burov 0 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

Nico Cesar 5 Aug 29, 2022
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

Classroooms 5 Sep 26, 2022
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

Carl Riis 311 Oct 1, 2022
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

Kishan Kr Sharma 2 May 1, 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,

Akilan 61 Nov 16, 2022
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

Kelsey Hightower 30 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

Darren Parkinson 0 Oct 29, 2021