Example clean-architecture backend implemented with Go and Gin.
go-gin-pattern is a small example backend demonstrating a clean architecture style using the Gin web framework. It provides a minimal, opinionated layout for configuration, logging, middleware, handlers, services, repositories, and seeding.
- Structured project layout following a clean architecture pattern
- Configuration via
viper - Structured logging with
logrus - Request middleware (request ID, logging)
- Simple health check handler and service
- Seeder support and repository/service layers
The project separates responsibilities into clear packages: configuration (app/), handlers (handler/), services (service/), repositories (repository/), models (model/), middleware (middleware/), and helpers (helper/). This keeps HTTP, business logic, and persistence concerns decoupled.
Prerequisites:
- Go 1.20+ installed
Clone the repository and run:
go run main.goBy default the server reads configuration from the app/config files (Viper). Adjust settings there or via environment variables as needed.
Configuration is centralized in app/config and loaded with viper. Common settings include server port, database connection, and logging level. See app/config/app.go and app/config/viper.go for details.
app/— application bootstrap and confighandler/— HTTP handlersservice/— business logicrepository/— data accessmodel/— data modelsmiddleware/— HTTP middlewarehelper/— shared helpers (pagination, response, validator)logs/— runtime logs
Logging is implemented with logrus and configured in app/logrus.go. Logs are written to the logs/ folder by default.
Seeders live in seeder/ and can be extended to populate initial data into the database when needed.
Contributions are welcome. Open an issue or submit a pull request with a clear description of the change.
This project is provided as-is. Add a license file if you intend to publish or share under a specific license.