go-clean-architecture-example
go-clean-architecture-example copied to clipboard
Golang Clean Architecture Example
Complete solution for Clean architecture using go
Clean Architecture
Complete solution template which is built on Clean Architecture with all essential feature using go!
Explore the docs »
Report Bug
·
Request Feature
Give a Star! :star:
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
Support This Project
If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying me a coffee:
👨💻 Full list what has been used:
- go - 1.18 or later, to use generics
- wire - Dependency injection
- fiber - Web framework
- sqlx - Extensions to database/sql.
- pgx - PostgreSQL driver and toolkit for Go
- viper - Go configuration with fangs
- go-redis - Type-safe Redis client for Golang
- go-mongo Golang driver for MongoDB
- zap - Logger
- validator - Go Struct and Field validation
- migrate - Database migrations. CLI and Golang library.
- swag - Swagger
- testify - Testing toolkit
- gomock - Mocking framework
- Docker - Docker
Technology stack
Design Pattern
- [x] CQRS design pattern
- [x] Repository design pattern
- [ ] Mediator design pattern
- [ ] Unit of work
Service
- [x] Web API (Restful service)
- [ ] gRPC
- [ ] Graphql
- [ ] Message Broker (Nats, Kafka)
Feature
- [x] Custom Exceptionn Handler
- [x] Swagger UI
- [x] Advanced Pagination
Monitoring
- [x] Health check
Testing
- [x] Unit testing
- [ ] Integration testing
Caching
- [X] In memory Caching
- [X] Redis Caching
Database
- [X] MongoDb
- [ ] Mysql
- [ ] PostgresSQL
Code Design

Application Overview
Use Cases
As a web client, I want to be able to
- Get all available crags.
- Get a crag by ID.
- Add a crag by providing a name, country, and description.
- Update a crag by providing a name, country, and description.
- Remove a crag by ID.
As an application administrator
- When a new crag is added, I want to receive a notification at a pre-agreed channel.
Technical requirements
- Operations should be exposed via an HTTP restful interface.
- For simplicity purposes,
- The crags should be stored in memory; no need for persistence storage.
- Notifications should be sent in a console application.
Project Structure
-
cmdcontains themain.gofile, the entry point of the application -
docscontains documentation about the application -
internalcontains the main implementation of our application. It consists of the three layers of clean architecture + server- api
- app
- common
- domain
- infrastructure
- middleware
- probes
- router
-
pkgshared utility codeEach of these directories contains its corresponding components, following the group-by-feature approach.
-
vendorcontains the dependencies of our project
Developer's Handbook
make local ## Run the application in local
make setup ## go tidy, install wire and swag
make test ## Run unit tests
make build ## Build the app executable
make swag ## generate api document
make clean ## # remove binary
Inspirations
Licence
See the contents of the LICENSE file for details
Contact
Having any issues or troubles getting started? Drop a mail to [email protected] or Raise a Bug or Feature Request. Always happy to help.

