A clean architecture scalable and maintainable Go boilerplate project using Echo, JWT, GORM, Redis, and more.
This project is a boilerplate template that provides a basic structure with a clean architecture implementation for building scalable and maintainable Go applications. It includes features such as authentication using JWT, database interaction using GORM, and temporary storage using Redis.
You can use this repository for your template project by click use this template
- Go 1.23 (See installation)
- Echo V4 (See documentation)
- JWT V5 (See documentation)
- Postgres/MySQL/SQLServer (See installation of MySQL | Postgresql | SQL Server)
- GORM (See documentation)
- Redis (See documentation)
- Viper (See documentation)
- Logrus (See documentation)
go-echo-boilerplate/
├── cmd/ # Entry point for the application
│ └── api/ # REST API starter
├── internal/ # Internal application logic
│ ├── api/ # REST API core logic
│ │ ├── controller/ # Handles request & response processing
│ │ ├── v1/ # Controller V1 Group
│ │ ├── dto/ # Data transfer objects (request & response)
│ │ ├── middleware/ # Custom middleware implementations
│ │ ├── routes/ # API route definitions
│ │ ├── v1/ # Routes V1 Group
│ ├── config/ # Configuration & dependency injection
│ ├── constants/ # Global constant variables
│ ├── contract/ # Dependency injection contracts
│ │ ├── common/ # Third-party dependencies
│ │ ├── repository/ # Repository layer contracts
│ │ └── service/ # Service layer contracts
│ ├── migrations/ # Database migration files
│ ├── model/ # Database models/entities
│ ├── pkg/ # Utility functions & helpers
│ │ ├── helper/ # Global helper function
│ │ ├── utils/ # Global library used to utility
│ ├── repository/ # Data access layer
│ │ ├── interfaces/ # Repository interface definitions
│ └── service/ # Business logic layer
│ │ ├── interfaces/ # Service interface definitions
│ │ ├── test/ # Service unit test
├── logs/ # Application log files
├── seeder/ # Seeder
├── pkg/ # Shared third party libraries
└── .env # Environment variables
└── Makefile # Command Shortcut
To install this project, clone the repository from GitHub:
git clone https://github.com/marifsulaksono/go-boilerplate.git- Copy file
.env.exampleand rename to.envcp .env.example .env
- Adjust variable
.envfile according to the configuration in your local environment
To run the project, use one of the following commands:
make run(using Makefile)go run cmd/api/main.go(without Makefile)
To build and run the project using Docker, use one of the following commands:
docker build -t go-boilerplate:1.0(using Dockerfile)docker compose up --build(using Docker Compose)
To run your testing, make sure you have generate mock folder and prepared file ./shared/coverage/cover.out to store testing logs. you can use this following command:
make mock (using Makefile)
after generate mock files, use this following command to run all your testings:
make test (using Makefile)
it will be store the testing logs, to generate html version, use this following command:
make coverage (using Makefile)
Note
In this project, we used bou.monkey to patch unmocked function to reach perfect coverage, it will be need some configuration on your computer, please used with your needed or contact me for help.
For more information or to report issues, please contact me at: