{"id":18541161,"url":"https://github.com/zetsux/gin-gorm-api-starter","last_synced_at":"2026-02-12T23:01:56.192Z","repository":{"id":149899756,"uuid":"614453734","full_name":"zetsux/gin-gorm-api-starter","owner":"zetsux","description":"🚀 A starter template for REST API using Gin (Golang) and GORM based on Controller-Service-Repository (CSR) pattern with automated tests ","archived":false,"fork":false,"pushed_at":"2025-11-03T12:45:51.000Z","size":180,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-29T09:35:21.009Z","etag":null,"topics":["api","automated-testing","controller-service-repository-pattern","gin","golang","gorm","rest-api","starter","starter-template","template"],"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/zetsux.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":"support/base/error.go","governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-15T16:03:02.000Z","updated_at":"2025-11-03T12:45:51.000Z","dependencies_parsed_at":"2024-01-26T05:14:10.758Z","dependency_job_id":"b668e6ac-51d6-480f-a38c-6d69ee066aba","html_url":"https://github.com/zetsux/gin-gorm-api-starter","commit_stats":null,"previous_names":["zetsux/gin-gorm-template-clean","zetsux/gin-gorm-api-starter","zetsux/gin-gorm-clean-starter"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/zetsux/gin-gorm-api-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetsux%2Fgin-gorm-api-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetsux%2Fgin-gorm-api-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetsux%2Fgin-gorm-api-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetsux%2Fgin-gorm-api-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zetsux","download_url":"https://codeload.github.com/zetsux/gin-gorm-api-starter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zetsux%2Fgin-gorm-api-starter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29384981,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T22:07:52.078Z","status":"ssl_error","status_checked_at":"2026-02-12T22:07:49.026Z","response_time":55,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api","automated-testing","controller-service-repository-pattern","gin","golang","gorm","rest-api","starter","starter-template","template"],"created_at":"2024-11-06T20:03:59.623Z","updated_at":"2026-02-12T23:01:55.158Z","avatar_url":"https://github.com/zetsux.png","language":"Go","readme":"# Gin GORM API Starter Template\n\n## Contents\n\n- [Description](#description)\n- [Architecture](#architecture)\n\n  - [Explanation (EN)](#explanation-en)\n  - [Explanation (ID)](#explanation-id)\n\n- [Pre-requisites](#pre-requisites)\n\n  - [PostgreSQL Requirements](#postgresql-requirements)\n  - [GitHooks Requirements](#githooks-requirements)\n\n- [How to Run?](#how-to-run)\n- [API Documentation (Postman)](#api-documentation-postman)\n\n## Description\n\nAn API starter template for projects based on Controller-Service-Repository (CSR) Pattern utilizing Gin (Golang) and PostgreSQL, with GORM as the ORM.\n\n## Architecture\n\n```\n/backend\n│\n├── /api\n│   └── /v1\n│       ├── /controller\n│       │   ├── user.go\n│       │   └── etc\n│       └── /router\n│           ├── user.go\n│           └── etc\n│\n├── /cmd\n│   ├── db.go\n│   ├── exec.go\n│   └── etc\n│\n├── /config\n│   ├── db.go\n│   └── etc\n│\n├── /core\n│   ├── /entity\n│   │   └── user.go\n│   │   └── etc\n│   ├── /helper\n│   │   ├── /dto\n│   │   │   ├── user.go\n│   │   │   └── etc\n│   │   ├── /errors\n│   │   │   ├── other.go\n│   │   │   ├── user.go\n│   │   │   └── etc\n│   │   └── /messages\n│   │       ├── file.go\n│   │       ├── user.go\n│   │       └── etc\n│   ├── /interface\n│   │   └── /query\n│   │       ├── user.go\n│   │       └── etc\n│   │   └── /repository\n│   │       ├── tx.go\n│   │       ├── user.go\n│   │       └── etc\n│   └── /service\n│       ├── user.go\n│       └── etc\n│\n├── /database\n│   ├── /seeder\n│   │   └── user.go\n│   │   └── etc\n│   └── migrator.go\n│\n├── /infrastructure\n│   ├── /query\n│   │   └── user.go\n│   │   └── etc\n│   └── /repository\n│       └── tx.go\n│       └── user.go\n│       └── etc\n│\n├── /provider\n│   ├── user.go\n│   └── etc\n│\n├── /support\n│   ├── /base\n│   │   └── model.go\n│   │   └── request.go\n│   │   └── response.go\n│   │   └── etc\n│   ├── /constant\n│   │   └── default.go\n│   │   └── enums.go\n│   │   └── etc\n│   ├── /middleware\n│   │   └── authentication.go\n│   │   └── cors.go\n│   │   └── authorization.go\n│   │   └── etc\n│   └── /util\n│       └── bcrypt.go\n│       └── file.go\n│       └── etc\n│\n├── /tests\n│   ├── /testutil\n│   └── /integration\n│\n└── main.go\n```\n\n### Explanation (EN)\n\n- `/api/v1` : The directory for things related to API like all available endpoints (routes) and the handlers for each endpoint (controller). Subdirectory `/v1` is used for easy version control in case of several development phases.\n\n  - `/controller` : The directory for things related to the Controller layer, which handles requests and returns responses.\n  - `/router` : The directory for things related to routing. Contains all supported routes/endpoints along with request methods and used middleware.\n\n- `/cmd` : The directory to store executable commands like for database migration or seeder runs.\n\n- `/config` : The directory for things related to program configuration like database configuration.\n\n- `/core` : The directory for things related to the core backend logic. Contains business logic, entities, and database interaction.\n\n  - `/entity` : The directory for entities/models that are mapped to the database via migration.\n  - `/helper` : The directory to store items that help backend operations, such as DTOs, error variables, and message constants.\n\n    - `/dto` : Stores DTO (Data Transfer Object) used as placeholders to transfer data for requests and responses.\n    - `/errors` : Stores error variables for each entity or other needs.\n    - `/messages` : Stores message constants for each entity or feature.\n\n  - `/interface` : The directory for all core interfaces used by the service layer, including contracts for repository and query layers.\n\n    - `/repository` : Interfaces for repository layer (entity CRUD).\n    - `/query` : Interfaces for query layer (read-only operations, projections).\n\n  - `/service` : The directory for the Service layer, responsible for application flow and business logic.\n\n- `/database` : The directory for things related to database migrations and seeding.\n\n  - `/seeder` : The directory for database seeders for each entity.\n\n- `/infrastructure` : The directory for implementations of interfaces defined in `/core/interface`, it's the only layer capable of interacting directly with the database.\n\n  - `/repository` : Implementations of repository interfaces, handling CRUD and transactional operations.\n  - `/query` : Implementations of query interfaces, handling read-only or optimized queries.\n\n- `/provider` : The directory for dependency injection setup, e.g., Samber/Do providers for wiring services, repositories, and queries.\n\n- `/support` : The directory for common supporting things that are frequently used across the architecture.\n\n  - `/base` : The directory for base structures such as variables, constants, and functions used in other directories. Includes response, request, and model base structures.\n  - `/middleware` : The directory for Middlewares, mechanisms that intercept HTTP requests/responses before they are handled by controllers.\n  - `/util` : The directory for utility/helper functions that can be used in other directories.\n\n- `/tests` : The directory for automated API testing (unit tests and integration tests).\n\n  - `/testutil` : Stores utility/helper functions for testing purposes.\n  - `/integration` : Stores integration test functions.\n\n- `main.go` : The entry point of the application.\n\n### Explanation (ID)\n\n- `/api/v1` : Direktori yang berisi berbagai hal yang berkaitan dengan API seperti daftar endpoint yang disediakan (route) serta handler (controller) dari setiap endpoint. Subdirectory `/v1` digunakan untuk version control apabila ada beberapa versi API.\n\n  - `/controller` : Direktori untuk menyimpan hal-hal terkait Controller, yang bertugas menerima request dan memberikan response.\n  - `/router` : Direktori untuk menyimpan hal-hal yang terkait dengan routing, berisi semua route/endpoints yang didukung beserta metode request dan middleware yang digunakan.\n\n- `/cmd` : Direktori untuk menyimpan perintah-perintah yang dapat dijalankan seperti migrasi atau _seeding_ pada database.\n\n- `/config` : Direktori yang berisi hal-hal terkait konfigurasi aplikasi, misalnya konfigurasi database.\n\n- `/core` : Direktori yang berisi bagian inti dari backend. Meliputi business logic, entitas, dan interaksi dengan database.\n\n  - `/entity` : Direktori untuk menyimpan entitas atau model yang digunakan di migrasi dan aplikasi.\n  - `/helper` : Direktori untuk menyimpan hal-hal yang membantu operasi backend, seperti DTO, variabel error, dan konstanta pesan.\n\n    - `/dto` : Direktori untuk menyimpan DTO (Data Transfer Object), placeholder untuk memindahkan data request dan response.\n    - `/errors` : Direktori untuk menyimpan variabel error untuk setiap entitas maupun kebutuhan lain.\n    - `/messages` : Direktori untuk menyimpan konstanta pesan untuk response API.\n\n  - `/interface` : Direktori untuk menyimpan semua interface inti yang digunakan service layer, termasuk kontrak untuk repository dan query.\n\n    - `/repository` : Interface untuk repository (CRUD entitas).\n    - `/query` : Interface untuk query (read-only, projections).\n\n  - `/service` : Direktori untuk service layer, yang menangani alur aplikasi dan logika bisnis.\n\n- `/database` : Direktori untuk hal-hal terkait migrasi dan seeding database.\n\n  - `/seeder` : Direktori untuk database seeding tiap entitas.\n\n- `/infrastructure` : Direktori untuk implementasi interface yang ada di `/core/interface`. Merupakan satu-satunya layer yang dapat berinteraksi secara langsung dengan basis data.\n\n  - `/repository` : Implementasi repository, menangani operasi CRUD dan transaksi.\n  - `/query` : Implementasi query, menangani operasi read-only atau query yang dioptimalkan.\n\n- `/provider` : Direktori untuk setup dependency injection, misalnya provider Samber/Do untuk menghubungkan service, repository, dan query.\n\n- `/support` : Direktori yang berisi hal-hal umum pembantu untuk digunakan di seluruh project.\n\n  - `/base` : Direktori yang berisi struktur dasar seperti variabel, konstanta, dan fungsi yang digunakan di directory lain. Termasuk response, request, dan model base structure.\n  - `/middleware` : Direktori untuk Middleware, mekanisme yang menengahi proses HTTP request/response sebelum ditangani controller.\n  - `/util` : Direktori untuk fungsi utilitas/pembantu yang dapat digunakan di berbagai directory.\n\n- `/tests` : Direktori untuk automated API testing (unit dan integration tests).\n\n  - `/testutil` : Menyimpan fungsi utilitas/pembantu untuk testing.\n  - `/integration` : Menyimpan fungsi integration testing.\n\n- `main.go` : Titik masuk (entry point) aplikasi.\n\n## Pre-requisites\n\n### PostgreSQL Requirements\n\n1. Create the database in PostgreSQL with the name equal to the value of DB_NAME in `.env`\n\n### GitHooks Requirements\n\n\u003e Note : GitHooks is not mandatory for this starter. Only do the steps below if you want to apply \u0026 use it.\n\n1. Install golangci-lint as the linters aggregator for pre-commit linting by executing `go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest`. Alternatively, you can follow the recommended method, which involves installing the binary from the [official source](https://github.com/golangci/golangci-lint/releases)\n2. Install commitlint as the conventional commit message checker by executing `go install github.com/conventionalcommit/commitlint@latest`. Alternatively, you can follow the recommended method, which involves installing the binary from the [official source](https://github.com/conventionalcommit/commitlint/releases)\n3. Configure your git's hooks path to be linked to the `.githooks` directory on this repository by executing `git config core.hooksPath .githooks`\n\n## How to Run?\n\n1. Use the command `make tidy` (or use `go mod tidy` instead, if `make` is unable to be used) to adjust the dependencies accordingly\n2. Use the command `make setup` (or use `go run main.go setup` instead, if `make` is unable to be used) to setup (migrate and seed) your database\n3. Use the command `make run` (or use `go run main.go` instead, if `make` is unable to be used) to run the application. You can also use Docker with air to auto-reload by running `make up` (or use `docker-compose up` instead if `make` is unable to be used)\n4. Use the command `make test` (or use `go test ./...` instead, if `make` is unable to be used) to run the automated testing\n\n## API Documentation (Postman)\n\nLink : https://documenter.getpostman.com/view/25087235/2s9YXfcizj\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzetsux%2Fgin-gorm-api-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzetsux%2Fgin-gorm-api-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzetsux%2Fgin-gorm-api-starter/lists"}