Go-Clean-Arch gives a Clean Architecture template that is commonly used in Crescendo’s Go projects. We will introduce the proposed architecture and related designs through a tutorial on building a sample application – Crescendo Barter.
The proposed clean architecture is inspired by DDD (Domain-Driven Design), Uncle Bob’s Clean Architecture, and a Go Clean Architecture project Wild Workouts, trying to balance feature development speed and maintenance efforts.
Our proposed clean architecture tries to provide the following features:
- Testable. Critical logic is well protected and validated.
- Ubiquitous language. No communication barrier between business and engineering people.
- First-class-citizen errors. Handle errors throughout the application in handy.
- Traceable requests. Internal behaviors of a request could be observed through API and system logs.
- Product-ready. Teams could use the architecture template in their new projects directly.
- Simple and straight. Any new member could pick up the architecture within days.
The proposed architecture can be separated into 4 layers, including
Domainhandles domain models and critical business logic.
Applicationhandles use cases (orchestration of business rules), compositing functionalities of
Routerhandles input request things, such as HTTP request routing, authentication, access control, and parameter validation.
Adapterhandle output requests, such as accessing DB, communicate with other services, emit events.
Its dependency rules are:
Crescendo Barter is a second-hand goods exchange application in which people can post their old goods and exchange them with others.
- As a client, I want to register a trader account.
- As a client, I want to log in to the application through the registered trader account.
- As a trader, I want to post my old goods to the application so that others can see what I have.
- As a trader, I want to see all my posted goods.
- As a trader, I want to see others’ posted goods.
- As a trader, I want to remove some of my goods from the application.
- As a trader, I want to exchange my own goods with others.