Skip to content

MingPV/clean-go-template

Repository files navigation

go-clean-template

image

go-clean-template is a clean and scalable starter template for building backend applications in Go, following Clean Architecture principles. This template uses:

  • Fiber v2 as a fast and lightweight web framework for building RESTful APIs
  • GORM as the ORM for PostgreSQL database access
  • Redis for caching to improve performance and reduce database load
  • gRPC for high-performance RPC communication
  • Docker Compose for easy setup of PostgreSQL and Redis services

Features

  • Clear separation of concerns with Clean Architecture
  • High-performance HTTP handling with Fiber v2
  • Robust database integration using GORM with PostgreSQL
  • Caching support via Redis
  • REST and gRPC APIs supported
  • Data Transfer Objects (DTO) to manage data structure transformations between layers
  • Swagger API documentation with automatic generation
  • Ready-to-use Docker Compose setup for dependencies

Getting Started

Follow the steps below to set up and run the project:

  1. Clone the repository:

    git clone https://github.com/MingPV/clean-go-template.git
    cd clean-go-template
  2. Install Go module dependencies:

    go mod tidy
  3. Rename the environment file and configure it:

    cp .env.example .env

    Open the .env file and fill in all required configuration values such as PostgreSQL credentials, Redis connection details, and any other environment-specific settings.

  4. Start PostgreSQL and Redis services using Docker Compose:

    docker-compose up -d
  5. Run the application:

    go run ./cmd/app
  6. Test:

    go test ./pkg/routes

Swagger UI for the API documentation is available at: localhost:8080/api/v1/docs

image image

Project structure

/clean-go-template
├── cmd/
│   └── app/
│       └── main.go               
├── docs/
│   └── v1/                 
├── internal/               
│   ├── app/            
│   ├── entities/
│   ├── order/
│   │   ├── handler/ 
│   │   ├── usecase/
│   │   ├── repository/
│   │   └── dto/ 
│   └── user/               
├── pkg/
│   ├── config/
│   ├── database/
│   ├── middleware/
│   ├── redisclient/
│   ├── responses/
│   └── routes/
├── proto/
│   └── order/
├── utils/                
├── .env.example             
├── .gitignore               
├── LICENSE                  
├── README.md             
├── docker-compose.yaml      
└── go.mod

Releases

No releases published

Packages

No packages published

Languages