{"id":15095980,"url":"https://github.com/eldimious/golang-api-showcase","last_synced_at":"2025-09-07T18:33:52.494Z","repository":{"id":37561330,"uuid":"167950957","full_name":"eldimious/golang-api-showcase","owner":"eldimious","description":"Golang API project showcase heavily influenced by the Clean Architecture and Hexagonal Architecture, using PostgreSQL.","archived":false,"fork":false,"pushed_at":"2023-02-09T20:24:40.000Z","size":8581,"stargazers_count":285,"open_issues_count":3,"forks_count":30,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T19:18:59.369Z","etag":null,"topics":["boilerplate-api","clean-architecture","docker","gin-gonic","golang","golang-api","gorm","hexagonal-architecture","layered-architecture","postgresql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eldimious.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-28T11:27:28.000Z","updated_at":"2025-03-20T15:52:13.000Z","dependencies_parsed_at":"2024-06-20T14:00:55.773Z","dependency_job_id":"15e09168-c934-48c8-9f1a-19995571447f","html_url":"https://github.com/eldimious/golang-api-showcase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgolang-api-showcase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgolang-api-showcase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgolang-api-showcase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eldimious%2Fgolang-api-showcase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eldimious","download_url":"https://codeload.github.com/eldimious/golang-api-showcase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094990,"owners_count":21046770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boilerplate-api","clean-architecture","docker","gin-gonic","golang","golang-api","gorm","hexagonal-architecture","layered-architecture","postgresql"],"created_at":"2024-09-25T15:44:31.170Z","updated_at":"2025-04-09T19:19:04.275Z","avatar_url":"https://github.com/eldimious.png","language":"Go","funding_links":["https://ko-fi.com/Y8Y797KCA"],"categories":[],"sub_categories":[],"readme":"# What is this repository for? #\nGolang app architecture showcase using [Gin](https://github.com/gin-gonic/gin), [PostgreSQL](https://www.postgresql.org/) and [Gorm](https://github.com/jinzhu/gorm) as ORM. You can start your Golang projects building on this boilerplate.\n\n# Architecture Overview #\nThe app is designed to use a layered architecture. The architecture is heavily influenced by the Clean Architecture and Hexagonal Architecture. [Clean Architecture](https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html) is an architecture where `the business rules can be tested without the UI, database, web server, or any external element`. \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/719/1*ZNT5apOxDzGrTKUJQAIcvg.png\" width=\"350\"/\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/900/0*R7uuhFwZbhcqZSvn\" width=\"350\" /\u003e \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/1200/0*rFs1UtU4sRns5vCJ.png\" width=\"350\" /\u003e\n  \u003cimg src=\"https://cdn-images-1.medium.com/max/1200/0*C-snK7L4sMn7b6CW.png\" width=\"350\" /\u003e \n\u003c/p\u003e\n\nAlso, in entry point(server.go), I use Dependency Injection(DI). There are many reasons using Dependency Injection as:\n1. Decoupling\n2. Easier unit testing\n3. Faster development\n4. Dependency injection is really helpful when it comes to testing. You can easily mock your modules' dependencies using this pattern.\n\nYou can take a look at this tutorial: `https://blog.risingstack.com/dependency-injection-in-node-js/`.\nAccording to DI:\n  A. High-level modules should not depend on low-level modules. Both should depend on abstractions.\n  B. Abstractions should not depend on details.\n\nThe code style being used is based on the airbnb js style guide.\n\n\n## Data Layer ##\n\nThe data layer is implemented using repositories, that hide the underlying data sources (database, network, cache, etc), and provides an abstraction over them so other parts of the application that make use of the repositories, don't care about the origin of the data and are decoupled from the specific implementations used, like the Gorm that is used by this app. Furthermore, the repositories are responsible to map the entities they fetch from the data sources to the models used in the applications. This is important to enable the decoupling.\n\n## Domain Layer ##\n\nThe domain layer is implemented using services. They depend on the repositories to get the app models and apply the business rules on them. They are not coupled to a specific database implementation and can be reused if we add more data sources to the app or even if we change the database for example from MongoDB to Couchbase Server.\n\n## Routes/Controller Layer ##\n\nThis layer is being used in the express app and depends on the domain layer (services). Here we define the routes that can be called from outside. The services are always used as the last middleware on the routes and we must not rely on res.locals from express to get data from previous middlewares. That means that the middlewares registered before should not alter data being passed to the domain layer. They are only allowed to act upon the data without modification, like for example validating the data and skipping calling next().\n\n## Entry point ##\n\nThe entry point for the applications is the server.go file. It does not depend on gin or other external frameworks. It is responsible for instantiating the application layers, connecting to the db and  mounting the http server to the specified port.\n\n# Quick start #\n\n### Prerequisites ###\n\nCreate an .env file in project root to register the following required environment variables:\n  - `POSTGRES_HOST`     - Postgres DB host\n  - `POSTGRES_PORT`     - Postgres DB port\n  - `POSTGRES_USER`     - Postgres DB user\n  - `POSTGRES_DB`       - Postgres DB name\n  - `POSTGRES_PASSWORD` - Postgres DB password\n\n### Use Docker: ###\n\nYou can use Docker to start the app locally. The Dockerfile and the docker-compose.yml are already provided for you. For this option you must specify following var in the .env file:\n\nDATABASE_URL\n\nthen run the following command:\n\n```shell\ndocker-compose up\n```\n\n## Support Me\n\n[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y797KCA)\n\n## Show your support\n\nGive a ⭐️ if this project helped you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fgolang-api-showcase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feldimious%2Fgolang-api-showcase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feldimious%2Fgolang-api-showcase/lists"}