go-clean-arch README

The project's README from github.com/bxcodec/go-clean-arch. As one markdown file: README.md.

go-clean-arch

Changelog

Author's Note

You may notice it diverges from the structures seen in previous versions. I encourage you to explore the branches for each version to select the structure that appeals to you the most. In my recent projects, the code structure has progressed to version 4. However, I do not strictly advocate for one version over another. You may encounter alternative examples on the internet that align more closely with your preferences. Rest assured, the foundational concept will remain consistent or at least bear resemblance. The differences are primarily in the arrangement of directories or the integration of advanced tools directly into the setup.

Description

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

Rule of Clean Architecture by Uncle Bob

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

This project has 4 Domain 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 be 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 is 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

# copy the example.env to .env
$ cp example.env .env

# 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 similar 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.

go-clean-arch (bxcodec/go-clean-arch)

clean-architecture
Searching Database…

What is this?A reference implementation of Uncle Bob's Clean Architecture in Go — a sample project showing how to structure a real backend into layered, framework-independent code.
Is it a framework or a library I can import?Neither — it's a complete example project you clone, read, and adapt as a template for your own services, not a package you add to go.mod.
How do I get it running?Load article.sql into a MySQL database first, keep the source outside GOPATH since it uses Go modules, then run it directly or follow the README's docker-compose steps.
What do I need to have installed?Go and a MySQL instance are required; Docker with docker-compose is offered as an alternative way to run, and mockery generates the mocks used in tests.
Is the structure on master the one I should follow?Master holds v4, whose layout diverges from v1–v3, and the author stays neutral — he recommends exploring each version's branch and picking the structure you like best.
Is this meant for learning or for production use?For learning and as a starting reference — the code itself is the artifact, and the README points to the author's Medium posts for the full architectural explanation.
What are the four layers?Models, Repository, Usecase, and Delivery. The point of the split is that business rules stay independent of frameworks, UI, the database, and any external agency.
Does it lock me into MySQL?No — database independence is one of the core rules. MySQL is just what the demo wires up; the idea is you can swap it for Mongo, CouchDB, or anything else without touching business rules.
What does the sample app actually do?It's an article-serving demo: article.sql seeds the MySQL schema, and requests flow through the four layers to manage articles.
Creator
bxcodec
Size
0.4 MB
Stars
10.2K
Age
9y
Commits · 90 Days