• Stars
    star
    7,739
  • Rank 4,918 (Top 0.1 %)
  • Language
    Go
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go (Golang) Clean Architecture based on Reading Uncle Bob's Clean Architecture

go-clean-arch

Changelog

Description

This is an example of implementation of Clean Architecture in Go (Golang) projects.

Rule of Clean Architecture by Uncle Bob

  • Independent of Frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.
  • Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.
  • Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.
  • Independent of Database. You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database.
  • Independent of any external agency. In fact your business rules simply don’t know anything at all about the outside world.

More at https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html

This project has 4 Domain layer :

  • Models Layer
  • Repository Layer
  • Usecase Layer
  • Delivery Layer

The diagram:

golang clean architecture

The original explanation about this project's structure can read from this medium's post : https://medium.com/@imantumorang/golang-clean-archithecture-efd6d7c43047.

It may different already, but the concept still the same in application level, also you can see the change log from v1 to current version in Master.

How To Run This Project

Make Sure you have run the article.sql in your mysql

Since the project already use Go Module, I recommend to put the source code in any folder but GOPATH.

Run the Testing

$ make tests

Run the Applications

Here is the steps to run it with docker-compose

#move to directory
$ cd workspace

# Clone into your workspace
$ git clone https://github.com/bxcodec/go-clean-arch.git

#move to project
$ cd go-clean-arch

# Run the application
$ make up

# The hot reload will running

# Execute the call in another terminal
$ curl localhost:9090/articles

Tools Used:

In this project, I use some tools listed below. But you can use any simmilar library that have the same purposes. But, well, different library will have different implementation type. Just be creative and use anything that you really need.

More Repositories

1

faker

Go (Golang) Fake Data Generator for Struct. [Notes]This repository is archived, moved to the new repository https://github.com/go-faker/faker
Go
2,077
star
2

dbresolver

Golang Database Resolver and Wrapper for any multiple database connections topology, e.g. master-slave replication database, cross-region application, and for separated ReadWrite (RW) and ReadOnly (RO) database connections
Go
124
star
3

go-clean-arch-grpc

Go clean Architecture with GRPC
Go
106
star
4

httpcache

Get a working HTTP Cache in Go (Golang) with only 3 lines of code!!!!
Go
58
star
5

go-postgres-pagination-example

An example project for pagination in Postgres with Golang
PLpgSQL
57
star
6

github-readme-medium-recent-article

Add Your Recently Published Medium Articles to Your GitHub Readme
TypeScript
54
star
7

gotcha

gotcha: inmemory-cache in Go (Golang) with customizable algorithm
Go
21
star
8

integration-testing

Go
18
star
9

simpleshell

Read about this repository here
Go
15
star
10

Article-Management-REST-API

Articles Management API
Go
8
star
11

sample-client-grpc

Client GRPC
Go
7
star
12

saint

Go (Golang) Math Library for Integer Operations
Go
7
star
13

goson

⚑️[WIP] Golang JSON Schema extractor from raw-json string
Go
7
star
14

tweetor

This project is a simple tutorial how to deploy golang application to Kubernetes
Go
4
star
15

Go-Simple-Flatbuffer

Read post about this project here:
Go
4
star
16

images_hosting

My Personal Image Hosting
1
star
17

AndroidPagination-ListView-Next-prev-

Example of pagination in ListView
Java
1
star
18

SMS-Gateway-Android

Sender-receiver of SMS using android Apps
Java
1
star
19

gomodtrial

Trying Go Module - new feature in Go 1.11
Go
1
star
20

gomodmultiplies

Go
1
star