[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71445":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":23,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":33,"readmeContent":34,"aiSummary":35,"trendingCount":16,"starSnapshotCount":16,"syncStatus":36,"lastSyncTime":37,"discoverSource":38},71445,"go-clean-template","evrone\u002Fgo-clean-template","evrone","Clean Architecture template for Golang services","",null,"Go",7589,656,46,1,0,7,11,24,21,39.45,"MIT License",false,"master",[26,27,28,29,30,31,32],"clean-architecture","dependency-injection","example","go","golang","microservices","template","2026-06-12 02:02:52","![Go Clean Template](docs\u002Fimg\u002Flogo.svg)\n\n# Go Clean template\n\n[🇨🇳 中文](README_CN.md)\n[🇷🇺 RU](README_RU.md)\n\nClean Architecture template for Golang services\n\n[![Release](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fv\u002Frelease\u002Fevrone\u002Fgo-clean-template.svg)](https:\u002F\u002Fgithub.com\u002Fevrone\u002Fgo-clean-template\u002Freleases\u002F)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-success)](https:\u002F\u002Fgithub.com\u002Fevrone\u002Fgo-clean-template\u002Fblob\u002Fmaster\u002FLICENSE)\n[![Go Report Card](https:\u002F\u002Fgoreportcard.com\u002Fbadge\u002Fgithub.com\u002Fevrone\u002Fgo-clean-template)](https:\u002F\u002Fgoreportcard.com\u002Freport\u002Fgithub.com\u002Fevrone\u002Fgo-clean-template)\n[![codecov](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fevrone\u002Fgo-clean-template\u002Fbranch\u002Fmaster\u002Fgraph\u002Fbadge.svg?token=XE3E0X3EVQ)](https:\u002F\u002Fcodecov.io\u002Fgh\u002Fevrone\u002Fgo-clean-template)\n\n[![Web Framework](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FFiber-Web%20Framework-blue)](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber)\n[![API Documentation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSwagger-API%20Documentation-blue)](https:\u002F\u002Fgithub.com\u002Fswaggo\u002Fswag)\n[![Validation](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FValidator-Data%20Integrity-blue)](https:\u002F\u002Fgithub.com\u002Fgo-playground\u002Fvalidator)\n[![JSON Handling](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGo--JSON-Fast%20Serialization-blue)](https:\u002F\u002Fgithub.com\u002Fgoccy\u002Fgo-json)\n[![Query Builder](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSquirrel-SQL%20Query%20Builder-blue)](https:\u002F\u002Fgithub.com\u002FMasterminds\u002Fsquirrel)\n[![Database Migrations](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMigrations-Seamless%20Schema%20Updates-blue)](https:\u002F\u002Fgithub.com\u002Fgolang-migrate\u002Fmigrate)\n[![Logging](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FZeroLog-Structured%20Logging-blue)](https:\u002F\u002Fgithub.com\u002Frs\u002Fzerolog)\n[![Metrics](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPrometheus-Metrics%20Integration-blue)](https:\u002F\u002Fgithub.com\u002Fansrivas\u002Ffiberprometheus)\n[![Testing](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FTestify-Testing%20Framework-blue)](https:\u002F\u002Fgithub.com\u002Fstretchr\u002Ftestify)\n[![Mocking](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMock-Mocking%20Library-blue)](https:\u002F\u002Fgo.uber.org\u002Fmock)\n\n## Overview\n\nThe purpose of the template is to show:\n\n- how to organize a project and prevent it from turning into spaghetti code\n- where to store business logic so that it remains independent, clean, and extensible\n- how not to lose control when a microservice grows\n\nUsing the principles of Robert Martin (aka Uncle Bob).\n\n[Go-clean-template](https:\u002F\u002Fevrone.com\u002Fgo-clean-template?utm_source=github&utm_campaign=go-clean-template) is created &\nsupported by [Evrone](https:\u002F\u002Fevrone.com\u002F?utm_source=github&utm_campaign=go-clean-template).\n\nThis template implements four types of servers:\n\n- AMQP RPC (based on RabbitMQ as [transport](https:\u002F\u002Fgithub.com\u002Frabbitmq\u002Famqp091-go)\n  and [Request-Reply pattern](https:\u002F\u002Fwww.enterpriseintegrationpatterns.com\u002Fpatterns\u002Fmessaging\u002FRequestReply.html))\n- MQ RPC (based on NATS as [transport](https:\u002F\u002Fgithub.com\u002Fnats-io\u002Fnats.go)\n  and [Request-Reply pattern](https:\u002F\u002Fwww.enterpriseintegrationpatterns.com\u002Fpatterns\u002Fmessaging\u002FRequestReply.html))\n- gRPC ([gRPC](https:\u002F\u002Fgrpc.io\u002F) framework based on protobuf)\n- REST API ([Fiber](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber) framework)\n\nThe template includes three domains to demonstrate multi-service architecture:\n\n- **User Authentication** — registration, login, JWT-based authorization\n- **Task Management** — CRUD operations with status transitions (todo, in_progress, done)\n- **Translation** — text translation with history tracking\n\nAll domains are available across all four transports (REST, gRPC, AMQP RPC, NATS RPC).\n\n## Content\n\n- [Domains](#domains)\n- [Quick start](#quick-start)\n- [Project structure](#project-structure)\n- [Dependency Injection](#dependency-injection)\n- [Clean Architecture](#clean-architecture)\n\n## Domains\n\nThe template includes three fully implemented domains, each available across all four transports (REST, gRPC, AMQP RPC, NATS RPC).\n\n### User Authentication\n\nRegistration, login, and JWT-based authorization.\n\n| Operation   | REST                     | gRPC                     |\n|-------------|--------------------------|--------------------------|\n| Register    | `POST \u002Fv1\u002Fauth\u002Fregister` | `AuthService\u002FRegister`   |\n| Login       | `POST \u002Fv1\u002Fauth\u002Flogin`    | `AuthService\u002FLogin`      |\n| Get profile | `GET \u002Fv1\u002Fuser\u002Fprofile`   | `AuthService\u002FGetProfile` |\n\n- Passwords hashed with bcrypt\n- JWT tokens with configurable expiry\n- Auth middleware on all transports\n\n### Task Management\n\nCRUD operations with a status state machine.\n\n| Operation  | REST                         | gRPC                         |\n|------------|------------------------------|------------------------------|\n| Create     | `POST \u002Fv1\u002Ftasks`             | `TaskService\u002FCreateTask`     |\n| List       | `GET \u002Fv1\u002Ftasks`              | `TaskService\u002FListTasks`      |\n| Get        | `GET \u002Fv1\u002Ftasks\u002F:id`          | `TaskService\u002FGetTask`        |\n| Update     | `PUT \u002Fv1\u002Ftasks\u002F:id`          | `TaskService\u002FUpdateTask`     |\n| Transition | `PATCH \u002Fv1\u002Ftasks\u002F:id\u002Fstatus` | `TaskService\u002FTransitionTask` |\n| Delete     | `DELETE \u002Fv1\u002Ftasks\u002F:id`       | `TaskService\u002FDeleteTask`     |\n\n- Status transitions: `todo` → `in_progress` → `done` (and `in_progress` → `todo`)\n- Pagination with `limit`\u002F`offset` and optional status filter\n- Tasks scoped to the authenticated user\n\n### Translation\n\nText translation via external API with history tracking.\n\n| Operation | REST                                | gRPC                                    |\n|-----------|-------------------------------------|-----------------------------------------|\n| Translate | `POST \u002Fv1\u002Ftranslation\u002Fdo-translate` | `TranslationHistoryService\u002FDoTranslate` |\n| History   | `GET \u002Fv1\u002Ftranslation\u002Fhistory`       | `TranslationHistoryService\u002FShowHistory` |\n\n## Quick start\n\n### Local development\n\n```sh\n# Postgres, RabbitMQ, NATS\nmake compose-up\n# Run app with migrations\nmake run\n```\n\n### Integration tests (can be run in CI)\n\n```sh\n# DB, app + migrations, integration tests\nmake compose-up-integration-test\n```\n\n### Full docker stack with reverse proxy\n\n```sh\nmake compose-up-all \n```\n\nCheck services:\n\n- AMQP RPC:\n  - URL: `amqp:\u002F\u002Fguest:guest@127.0.0.1:5672\u002F`\n  - Client Exchange: `rpc_client`\n  - Server Exchange: `rpc_server`\n- NATS RPC:\n  - URL: `nats:\u002F\u002Fguest:guest@127.0.0.1:4222\u002F`\n  - Server Exchange: `rpc_server`\n- REST API:\n  - http:\u002F\u002Fapp.lvh.me\u002Fhealthz | http:\u002F\u002F127.0.0.1:8080\u002Fhealthz\n  - http:\u002F\u002Fapp.lvh.me\u002Fmetrics | http:\u002F\u002F127.0.0.1:8080\u002Fmetrics\n  - http:\u002F\u002Fapp.lvh.me\u002Fswagger | http:\u002F\u002F127.0.0.1:8080\u002Fswagger\n- gRPC:\n  - URL: `tcp:\u002F\u002Fgrpc.lvh.me:8081` | `tcp:\u002F\u002F127.0.0.1:8081`\n  - [v1\u002Fauth.proto](docs\u002Fproto\u002Fv1\u002Fauth.proto)\n  - [v1\u002Ftask.proto](docs\u002Fproto\u002Fv1\u002Ftask.proto)\n  - [v1\u002Ftranslation.history.proto](docs\u002Fproto\u002Fv1\u002Ftranslation.history.proto)\n- PostgreSQL:\n  - `postgres:\u002F\u002Fuser:myAwEsOm3pa55@w0rd@127.0.0.1:5432\u002Fdb`\n- RabbitMQ:\n  - http:\u002F\u002Frabbitmq.lvh.me | http:\u002F\u002F127.0.0.1:15672\n  - Credentials: `guest` \u002F `guest`\n- NATS monitoring:\n  - http:\u002F\u002Fnats.lvh.me | http:\u002F\u002F127.0.0.1:8222\u002F\n  - Credentials: `guest` \u002F `guest`\n\n## Project structure\n\n### `cmd\u002Fapp\u002Fmain.go`\n\nConfiguration and logger initialization. Then the main function \"continues\" in\n`internal\u002Fapp\u002Fapp.go`.\n\n### `config`\n\nThe twelve-factor app stores config in environment variables (often shortened to `env vars` or `env`). Env vars are easy\nto change between deploys without changing any code; unlike config files, there is little chance of them being checked\ninto the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System\nProperties, they are a language- and OS-agnostic standard.\n\nConfig: [config.go](config\u002Fconfig.go)\n\nExample: [.env.example](.env.example)\n\n[docker-compose.yml](docker-compose.yml) uses `env` variables to configure services.\n\n### `docs`\n\nSwagger documentation. Auto-generated by [swag](https:\u002F\u002Fgithub.com\u002Fswaggo\u002Fswag) library.\nYou don't need to correct anything by yourself.\n\n#### `docs\u002Fproto`\n\nProtobuf files. They are used to generate Go code for gRPC services.\nThe proto files are also used to generate documentation for gRPC services.\nYou don't need to correct anything by yourself.\n\n### `integration-test`\n\nIntegration tests.\nThey are launched as a separate container, next to the application container.\n\n### `internal\u002Fapp`\n\nThere is always one _Run_ function in the `app.go` file, which \"continues\" the _main_ function.\n\nThis is where all the main objects are created.\nDependency injection occurs through the \"New ...\" constructors (see Dependency Injection).\nThis technique allows us to layer the application using the [Dependency Injection](#dependency-injection) principle.\nThis makes the business logic independent from other layers.\n\nNext, we start the server and wait for signals in _select_ for graceful completion.\nIf `app.go` starts to grow, you can split it into multiple files.\n\nFor a large number of injections, [wire](https:\u002F\u002Fgithub.com\u002Fgoogle\u002Fwire) can be used.\n\nThe `migrate.go` file is used for database auto migrations.\nIt is included if an argument with the _migrate_ tag is specified.\nFor example:\n\n```sh\ngo run -tags migrate .\u002Fcmd\u002Fapp\n```\n\n### `internal\u002Fcontroller`\n\nServer handler layer (MVC controllers). The template shows 4 servers:\n\n- AMQP RPC (based on RabbitMQ as transport)\n- NATS RPC (based on NATS as transport)\n- gRPC ([gRPC](https:\u002F\u002Fgrpc.io\u002F) framework based on protobuf)\n- REST API ([Fiber](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber) framework)\n\nServer routers are written in the same style:\n\n- Handlers are grouped by area of application (by a common basis)\n- For each group, its own router structure is created, the methods of which process paths\n- The structure of the business logic is injected into the router structure, which will be called by the handlers\n\n#### `internal\u002Fcontroller\u002Famqp_rpc`\n\nSimple RPC versioning.\nFor v2, we will need to add the `amqp_rpc\u002Fv2` folder with the same content.\nAnd in the file `internal\u002Fcontroller\u002Famqp_rpc\u002Frouter.go` add the line:\n\n```go\nroutes := make(map[string]server.CallHandler)\n\n{\n    v1.NewRoutes(routes, t, u, tk, j, l)\n}\n\n{\n    v2.NewTranslationRoutes(routes, t, l)\n}\n```\n\n#### `internal\u002Fcontroller\u002Fgrpc`\n\nSimple gRPC versioning.\nFor v2, we will need to add the `grpc\u002Fv2` folder with the same content.\nAlso add the `v2` folder to the proto files in `docs\u002Fproto`.\nAnd in the file `internal\u002Fcontroller\u002Fgrpc\u002Frouter.go` add the line:\n\n```go\n{\n    v1.NewAuthRoutes(app, u, l)\n    v1.NewTaskRoutes(app, tk, l)\n    v1.NewTranslationRoutes(app, t, l)\n}\n\n{\n    v2.NewAuthRoutes(app, u, l)\n    v2.NewTaskRoutes(app, tk, l)\n    v2.NewTranslationRoutes(app, t, l)\n}\n\nreflection.Register(app)\n```\n\n#### `internal\u002Fcontroller\u002Fnats_rpc`\n\nSimple RPC versioning.\nFor v2, we will need to add the `nats_rpc\u002Fv2` folder with the same content.\nAnd in the file `internal\u002Fcontroller\u002Fnats_rpc\u002Frouter.go` add the line:\n\n```go\nroutes := make(map[string]server.CallHandler)\n\n{\n    v1.NewRoutes(routes, t, u, tk, j, l)\n}\n\n{\n    v2.NewTranslationRoutes(routes, t, l)\n}\n```\n\n#### `internal\u002Fcontroller\u002Frestapi`\n\nSimple REST versioning.\nFor v2, we will need to add the `restapi\u002Fv2` folder with the same content.\nAnd in the file `internal\u002Fcontroller\u002Frestapi\u002Frouter.go` add the line:\n\n```go\napiV1Group := app.Group(\"\u002Fv1\")\n{\n\tv1.NewRoutes(apiV1Group, t, u, tk, jwtManager, l)\n}\napiV2Group := app.Group(\"\u002Fv2\")\n{\n\tv2.NewRoutes(apiV2Group, t, u, tk, jwtManager, l)\n}\n```\n\nInstead of [Fiber](https:\u002F\u002Fgithub.com\u002Fgofiber\u002Ffiber), you can use any other http framework.\n\nIn `router.go` and above the handler methods, there are comments for generating swagger documentation\nusing [swag](https:\u002F\u002Fgithub.com\u002Fswaggo\u002Fswag).\n\n### `internal\u002Fentity`\n\nEntities of business logic (models) can be used in any layer.\nThere can also be methods, for example, for validation.\n\n### `internal\u002Fusecase`\n\nBusiness logic.\n\n- Methods are grouped by area of application (on a common basis)\n- Each group has its own structure\n- One file - one structure\n\nRepositories, webapi, rpc, and other business logic structures are injected into business logic structures\n(see [Dependency Injection](#dependency-injection)).\n\n#### `internal\u002Frepo\u002Fpersistent`\n\nA repository is an abstract storage (database) that business logic works with.\n\n#### `internal\u002Frepo\u002Fwebapi`\n\nIt is an abstract web API that business logic works with.\nFor example, it could be another microservice that business logic accesses via the REST API.\nThe package name changes depending on the purpose.\n\n### `pkg\u002Frabbitmq`\n\nRabbitMQ RPC pattern:\n\n- There is no routing inside RabbitMQ\n- Exchange fanout is used, to which 1 exclusive queue is bound, this is the most productive config\n- Reconnect on the loss of connection\n\n## Dependency Injection\n\nIn order to remove the dependence of business logic on external packages, dependency injection is used.\n\nFor example, through the New constructor, we inject the dependency into the structure of the business logic.\nThis makes the business logic independent (and portable).\nWe can override the implementation of the interface without making changes to the `usecase` package.\n\n```go\npackage usecase\n\nimport (\n\u002F\u002F Nothing!\n)\n\ntype Repository interface {\n\tGet()\n}\n\ntype UseCase struct {\n\trepo Repository\n}\n\nfunc New(r Repository) *UseCase {\n\treturn &UseCase{\n\t\trepo: r,\n\t}\n}\n\nfunc (uc *UseCase) Do() {\n\tuc.repo.Get()\n}\n```\n\nIt will also allow us to do auto-generation of mocks (for example with [go.uber.org\u002Fmock](https:\u002F\u002Fgo.uber.org\u002Fmock)) and\neasily write unit tests.\n\n> We are not tied to specific implementations in order to always be able to change one component to another.\n> If the new component implements the interface, nothing needs to be changed in the business logic.\n\n## Clean Architecture\n\n### Key idea\n\nProgrammers realize the optimal architecture for an application after most of the code has been written.\n\n> A good architecture allows decisions to be delayed to as late as possible.\n\n### The main principle\n\nDependency Inversion (the same one from SOLID) is the principle of dependency injection.\nThe direction of dependencies goes from the outer layer to the inner layer.\nDue to this, business logic and entities remain independent from other parts of the system.\n\nSo, the application is divided into 2 layers, internal and external:\n\n1. **Business logic** (Go standard library).\n2. **Tools** (databases, servers, message brokers, any other packages and frameworks).\n\n![Clean Architecture](docs\u002Fimg\u002Flayers-1.png)\n\n**The inner layer** with business logic should be clean. It should:\n\n- Not have package imports from the outer layer.\n- Use only the capabilities of the standard library.\n- Make calls to the outer layer through the interface (!).\n\nThe business logic doesn't know anything about Postgres or a specific web API.\nBusiness logic has an interface for working with an _abstract_ database or _abstract_ web API.\n\n**The outer layer** has other limitations:\n\n- All components of this layer are unaware of each other's existence. How to call another from one tool? Not directly,\n  only through the inner layer of business logic.\n- All calls to the inner layer are made through the interface (!).\n- Data is transferred in a format that is convenient for business logic (`internal\u002Fentity`).\n\nFor example, you need to access the database from HTTP (controller).\nBoth HTTP and database are in the outer layer, which means they know nothing about each other.\nThe communication between them is carried out through `usecase` (business logic):\n\n```\n    HTTP > usecase\n           usecase > repository (Postgres)\n           usecase \u003C repository (Postgres)\n    HTTP \u003C usecase\n```\n\nThe symbols > and \u003C show the intersection of layer boundaries through Interfaces.\nThe same is shown in the picture:\n\n![Example](docs\u002Fimg\u002Fexample-http-db.png)\n\nOr more complex business logic:\n\n```\n    HTTP > usecase\n           usecase > repository\n           usecase \u003C repository\n           usecase > webapi\n           usecase \u003C webapi\n           usecase > RPC\n           usecase \u003C RPC\n           usecase > repository\n           usecase \u003C repository\n    HTTP \u003C usecase\n```\n\n### Layers\n\n![Example](docs\u002Fimg\u002Flayers-2.png)\n\n### Clean Architecture Terminology\n\n- **Entities** are structures that business logic operates on.\n  They are located in the `internal\u002Fentity` folder.\n  In MVC terms, entities are models.\n- **Use Cases** is business logic located in `internal\u002Fusecase`.\n\nThe layer with which business logic directly interacts is usually called the _infrastructure_ layer.\nThese can be repositories `internal\u002Frepo\u002Fpersistent`, external webapi `internal\u002Frepo\u002Fwebapi`, any pkg, and other\nmicroservices.\nIn the template, the _infrastructure_ packages are located inside `internal\u002Frepo`.\n\nYou can choose how to call the entry points as you wish. The options are:\n\n- controller (in our case)\n- delivery\n- transport\n- gateways\n- entrypoints\n- primary\n- input\n\n### Additional layers\n\nThe classic version\nof [Clean Architecture](https:\u002F\u002Fblog.cleancoder.com\u002Funcle-bob\u002F2012\u002F08\u002F13\u002Fthe-clean-architecture.html) was designed for\nbuilding large monolithic applications and has 4 layers.\n\nIn the original version, the outer layer is divided into two more, which also have an inversion of dependencies\nto each other (directed inward) and communicate through interfaces.\n\nThe inner layer is also divided into two (with separation of interfaces), in the case of complex logic.\n\n---\n\nComplex tools can be divided into additional layers.\nHowever, you should add layers only if really necessary.\n\n### Alternative approaches\n\nIn addition to Clean architecture, _Onion architecture_ and _Hexagonal_ (_Ports and adapters_) are similar to it.\nBoth are based on the principle of Dependency Inversion.\n_Ports and adapters_ are very close to _Clean Architecture_, the differences are mainly in terminology.\n\n## Similar projects\n\n- [https:\u002F\u002Fgithub.com\u002Fbxcodec\u002Fgo-clean-arch](https:\u002F\u002Fgithub.com\u002Fbxcodec\u002Fgo-clean-arch)\n- [https:\u002F\u002Fgithub.com\u002Fzhashkevych\u002Fcourses-backend](https:\u002F\u002Fgithub.com\u002Fzhashkevych\u002Fcourses-backend)\n\n## Useful links\n\n- [The Clean Architecture article](https:\u002F\u002Fblog.cleancoder.com\u002Funcle-bob\u002F2012\u002F08\u002F13\u002Fthe-clean-architecture.html)\n- [Twelve factors](https:\u002F\u002F12factor.net\u002Fru\u002F)\n","evrone\u002Fgo-clean-template 是一个为 Go 语言服务设计的干净架构模板。它基于 Robert Martin 提出的原则，帮助开发者组织项目结构，避免代码混乱，并保持业务逻辑的独立性、清晰度和可扩展性。该项目采用依赖注入、Fiber Web 框架、Swagger API 文档生成、数据验证、高效 JSON 处理等技术特点，并支持 AMQP RPC、MQ RPC、gRPC 和 REST API 四种类型的服务器。此外，还集成了 Prometheus 监控、ZeroLog 日志记录以及单元测试与模拟库。此模板适用于需要构建易于维护且具有良好扩展性的微服务场景。",2,"2026-06-11 03:37:46","high_star"]