Sample Go REST API implementation with DDD using Clean Architecture.

Overview

Folder Design

├── api
│   └── configs
│   └── controllers
│       └── v1
├── application
│   └── consts
│   └── users
│       └── consumers
│       └── mappers
│       └── models
├── domain
│   └── common
│   └── users
├── infrastructure
│   └── common
│       └── event-dispatcher
│       └── persistance
│   └── users

Api (Presentation Layer)

This layer is a part developed for client-side (mobile, web, etc.) applications to access our domain. It will forward the requests from this layer to the application layer and expose the response it receives from the application layer.

As you can see in the example project, our project will be accessible from the outside world using HTTP protocol over the controllers classes. Here is the sample code snippet that forwards the request received by HTTP to the Application Layer and return the result it receives.

func CreateGuestUser(group *echo.Group, userService users.UserService) {
    path := fmt.Sprintf("%s/GuestUser", _prefix)
    group.POST(path, func(context echo.Context) error {
        var (
            user *models.NewUserModel
            err  error
        )
        
        if user, err = userService.AddNewGuestUser(context2.Background()); err != nil {
            return err
        }
        
        return context.JSON(http.StatusCreated, user)
    })
}

Application Layer

Application layer currently has application services, event consumers, mappers and data transfer objects. However, it can also contain cross-cutting concerns such as transaction management, logging, caching and exception handling. (soon)

Application layer only call a aggregate root from domain layer and just may use its funcs. After It can be save all of changed that has been on aggregate-root to any database system.

As you can see in the sample code block, a new guest user is created in the application service and then saved to the database. Then, the related user information created is mapped to the user-created-model and sent to the upper layer.

func (service userService) AddNewGuestUser(ctx context.Context) (*models.NewUserModel, error) {
    user := users.NewGuestUser()
    
    if err := service.Repository.Add(ctx, user); err != nil {
        return nil, err
    }
    
    return mappers.MapNewUserModel(user), nil
}

Domain Layer

Will be completed soon..

Infrastructure Layer

Will be completed soon..

You might also like...
Rest API Product using Postgre as RDBMS
Rest API Product using Postgre as RDBMS

API Specification General info This is Rest API Product using Postgre as RDBMS. Tools? Please read the go.mod file. DDL CREATE TABLE products ( id bp

REST API for a shoe store using Go and Gin Web Framework

REST API for a shoe store using Go and Gin Web Framework This API uses a local PostgreSQL database that's set through the /gopostgres/driverConfig.go

GinGoExample - Implement rest api using gin and go and mongodb

GinGoExample Implement rest api using gin and go and mongodb Optimizations using Singlton pattern to avoid repetetive commiunication with mongodb . Fe

Demo application to implement a REST api backend service for an android app using the Go aah framework.

aah-recycleview-backend This tutorial is based on the aah framework to implement a REST API form of CRUD application services, taking "IN-MEMORY" stor

Ecommerce-api - Rest api of e-commerce web application
Ecommerce-api - Rest api of e-commerce web application

E-commerce Rest API Swagger documentation to test api Domain diagram

Compose sample application Go server with an Nginx proxy and a Postgres database

Compose sample application Go server with an Nginx proxy and a Postgres database Project

A sample url shortener app to test Keploy integration capabilities
A sample url shortener app to test Keploy integration capabilities

Example URL Shortener A sample url shortener app to test Keploy integration capabilities Installation git clone https://github.com/keploy/example-url-

WriteFreely is a clean, minimalist publishing platform made for writers
WriteFreely is a clean, minimalist publishing platform made for writers

WriteFreely is a clean, minimalist publishing platform made for writers. Start a blog, share knowledge within your organization, or build a community

Golang gin clean

Dependency go get github.com/gin-gonic/gin go get github.com/jinzhu/gorm go get

Owner
Rıdvan
Senior Software Engineer
Rıdvan
Implementation of clean architecture in golang with gin-gonic & gorm

Boilerplate API Boilerplate API template includes all the common packages and setup used for API development in this Company. Development Copy .env.ex

null 10 Feb 15, 2022
Go Server/API boilerplate using best practices DDD CQRS ES gRPC

Go Server/API boilerplate using best practices DDD CQRS ES gRPC

Rafał Lorenz 693 Nov 28, 2022
Clean Architecture using Golang with Gin framework

Clean Architecture using Golang with Gin framework Template Structure Gin is a web framework written in Go (Golang). It features a martini-like API wi

Thanakorn Ariyagusolsuthi 10 Nov 9, 2022
Go sql layer architecture sample

go-sql-rest-api-template To run the application go run main.go API Design Common HTTP methods GET: retrieve a representation of the resource POST: cre

null 0 Jan 15, 2022
Clean Architecture template for Golang services

Go Clean template Clean Architecture template for Golang services Overview The purpose of the template is to show: how to organize a project and preve

Mada Satya Bayu Ambika 5 Oct 19, 2022
Go (Golang) API REST with Gin FrameworkGo (Golang) API REST with Gin Framework

go-rest-api-aml-service Go (Golang) API REST with Gin Framework 1. Project Description Build REST APIs to support AML service with the support of exte

Tony Aizize 1 Nov 21, 2021
The source code for workshop Scalable architecture using Redis as backend database using Golang + Redis

The source code for workshop Scalable architecture using Redis as backend database using Golang + Redis

3DS INTERACTIVE 6 Sep 23, 2022
Instagram Backend HTTP REST API using GO Lang and Mongo DB

Instagram Backend HTTP REST API using GO Lang and Mongo DB Project for Appointy Summer Internship . Project built within 25 hrs, with no prior knowled

Chandru S Raghavan 1 Oct 10, 2021
A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

A Golang REST API to handle users and posts for a simple instagram backend. Uses MongoDB as the database. Tested using golang-testing and Postman.

Nitin Narayanan 1 Oct 10, 2021
REST API of Instagram's functionalities; developed using GO (and Mongo).

Instagram-backend-api REST API of Instagram's functionalities; developed using GO (and Mongo). Constraints: Complete API has been developed using Go M

Srishti Lodha 0 Oct 9, 2021