[go: up one dir, main page]

Skip to content

truanguyenvan/go-clean-architecture-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Complete solution for Clean architecture using go


Logo

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! ⭐

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:

Logo Buy 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

  • CQRS design pattern
  • Repository design pattern
  • Mediator design pattern
  • Unit of work

Service

  • Web API (Restful service)
  • gRPC
  • Graphql
  • Message Broker (Nats, Kafka)

Feature

  • Custom Exceptionn Handler
  • Swagger UI
  • Advanced Pagination

Monitoring

  • Health check

Testing

  • Unit testing
  • Integration testing

Caching

  • In memory Caching
  • Redis Caching

Database

  • MongoDb
  • Mysql
  • PostgresSQL

Code Design

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

  • cmd contains the main.go file, the entry point of the application

  • docs contains documentation about the application

  • internal contains the main implementation of our application. It consists of the three layers of clean architecture + server

    • api
    • app
    • common
    • domain
    • infrastructure
    • middleware
    • probes
    • router
  • pkg shared utility code

    Each of these directories contains its corresponding components, following the group-by-feature approach.

  • vendor contains 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

Clean Architecture in Go

Licence

GitHub license

See the contents of the LICENSE file for details

Contact

Having any issues or troubles getting started? Drop a mail to truanguyenvan@gmail.com or Raise a Bug or Feature Request. Always happy to help.