explaingit

bxcodec/go-clean-arch

10,091GoAudience · developerComplexity · 2/5Setup · moderate

TLDR

A Go codebase that demonstrates how to structure a backend application using Clean Architecture, separating business logic from databases and web frameworks so each layer can be tested and swapped independently.

Mindmap

mindmap
  root((go-clean-arch))
    What it does
      Architecture demo
      Clean layers pattern
      Backend reference
    Layers
      Models
      Repository
      Usecase
      Delivery
    Tech Stack
      Go
      MySQL
      Docker
    Audience
      Go developers
      Backend engineers
      Architecture learners
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Use as a reference when structuring a new Go backend project so that business logic is isolated from database and HTTP code.

USE CASE 2

Learn how to write unit tests for business logic without needing a live database by following the layered architecture pattern.

USE CASE 3

Swap the MySQL database layer for a different storage backend without rewriting any business rules.

USE CASE 4

Study the evolution of Clean Architecture patterns in Go across four versions from 2017 to the current release.

Tech stack

GoMySQLDocker

Getting it running

Difficulty · moderate Time to first run · 30min

Requires Docker and MySQL to run locally, a SQL schema file is included to set up the database.

In plain English

go-clean-arch is a Go codebase that demonstrates how to structure a backend application using Clean Architecture, a design philosophy popularized by software author Robert C. Martin (often called Uncle Bob). The goal of Clean Architecture is to keep the core business logic of an application isolated from the specific frameworks, databases, and delivery mechanisms it uses. That isolation makes the business logic easier to test and means you can swap out a database or a web server without rewriting the core code. The project organizes code into four layers. The Models layer holds the data structures. The Repository layer defines how data is stored and retrieved. The Usecase layer contains the actual business rules, with no knowledge of how data gets to or from the outside world. The Delivery layer is what users and other systems interact with, such as an HTTP API. Each layer depends only on the layers below it, not above. The repository has gone through four versions since 2017, each refining the directory structure and conventions. The current master branch (v4) introduces a few newer patterns: interfaces declared on the consuming side rather than the providing side, an internal package for code that should not be imported externally, and a service-focused package organization. Earlier versions are preserved on separate branches if you prefer a simpler layout. To run the project locally, you clone the repository, copy the example environment file, and run docker-compose. A MySQL database is required, and a SQL file is included to set up the schema. The README describes this as a learning reference rather than a prescriptive template, and the author notes that different arrangements of the same core ideas are equally valid.

Copy-paste prompts

Prompt 1
Based on the go-clean-arch pattern, help me create a new Go service for managing customer orders with the four Clean Architecture layers: Model, Repository, Usecase, and Delivery.
Prompt 2
Show me how to write a unit test for a Usecase function in go-clean-arch that does not require a real database connection.
Prompt 3
I want to add a new API endpoint to go-clean-arch. Walk me through creating the HTTP handler, usecase method, and repository function in the correct layers.
Prompt 4
How does go-clean-arch v4 differ from v1? What new patterns does it introduce and why were those changes made?
Open on GitHub → Explain another repo

← bxcodec on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.