# amitshekhariitbhu/go-backend-clean-architecture

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/amitshekhariitbhu-go-backend-clean-architecture).**

6,059 stars · 660 forks · Go · Apache-2.0

## Links

- GitHub: https://github.com/amitshekhariitbhu/go-backend-clean-architecture
- Homepage: https://outcomeschool.com/blog/go-backend-clean-architecture
- awesome-repositories: https://awesome-repositories.com/repository/amitshekhariitbhu-go-backend-clean-architecture.md

## Topics

`api` `architecture` `backend` `clean-architecture` `docker` `gin` `go` `golang` `jwt-authentication` `project` `project-template` `test`

## Description

This is a Go backend template that structures a web service into domain, usecase, controller, and repository layers with strict dependency inversion. It provides a foundation for building maintainable and testable REST APIs by separating business logic from transport and data access concerns.

The project implements JWT-based authentication, issuing access and refresh tokens for user signup, login, and protected endpoint access. It uses the Gin HTTP framework to build a Docker-packaged REST API with public and private route groups, request validation, and middleware-based authentication. Dependencies are wired through explicit constructor calls at application startup without a dependency injection framework.

Data persistence is handled through a repository interface that abstracts MongoDB interactions behind a contract, enabling testable data access. The codebase supports mock-based layered testing, allowing verification of business logic and data access in isolation by substituting real dependencies with generated mock implementations. Configuration is loaded from a `.env` file and unmarshaled into a typed struct for runtime use.

## Tags

### Software Engineering & Architecture

- [Go Clean Architecture Templates](https://awesome-repositories.com/f/software-engineering-architecture/go-microservices-architectures/clean-architecture-implementations/go-clean-architecture-templates.md) — Provides a foundational Go backend template with strict clean architecture layering for maintainable and testable REST APIs.
- [Three-Layer Clean Architecture](https://awesome-repositories.com/f/software-engineering-architecture/go-microservices-architectures/clean-architecture-implementations/three-layer-clean-architecture.md) — Structures code into delivery, use-case, and repository layers with strict inward-only dependency rules. ([source](https://outcomeschool.com/program/android))
- [Dependency Inversion Patterns](https://awesome-repositories.com/f/software-engineering-architecture/project-management-governance/dependency-boundary-enforcers/dependency-inversion-patterns.md) — Separates code into domain, usecase, controller, and repository layers with strict dependency inversion.
- [Usecase Layer Executions](https://awesome-repositories.com/f/software-engineering-architecture/stateful-logic-encapsulation/business-logic-encapsulations/usecase-layer-executions.md) — Implements a dedicated usecase layer that orchestrates business logic independently of transport and data access. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))

### Part of an Awesome List

- [Registration and Profile Retrievals](https://awesome-repositories.com/f/awesome-lists/security/user-authentication/registration-and-profile-retrievals.md) — Registers new users with email and password and returns profile data after JWT authentication. ([source](https://cdn.jsdelivr.net/gh/amitshekhariitbhu/go-backend-clean-architecture@main/README.md))

### Data & Databases

- [Data Abstraction Layers](https://awesome-repositories.com/f/data-databases/data-abstraction-layers.md) — Abstracts database interactions behind an interface so usecases can operate without knowing storage details. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))
- [Domain Data Structure Declarations](https://awesome-repositories.com/f/data-databases/entity-modeling/extensible-domain-entities/domain-driven-entity-frameworks/functional-domain-modeling/domain-data-structure-declarations.md) — Declares domain models and interface contracts that define the boundaries between architecture layers. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))
- [Request Validation](https://awesome-repositories.com/f/data-databases/data-governance-modeling/data-management-governance/data-integrity-validation/data-validation/request-validation.md) — Validates incoming request payloads for required fields and correct types, returning 400 errors. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))
- [User-Scoped Task Management](https://awesome-repositories.com/f/data-databases/user-data-management/user-scoped-task-management.md) — Implements create and list operations for tasks scoped to the authenticated user via JWT. ([source](https://cdn.jsdelivr.net/gh/amitshekhariitbhu/go-backend-clean-architecture@main/README.md))

### Networking & Communication

- [Repository Pattern Abstractions](https://awesome-repositories.com/f/networking-communication/protocol-abstraction-layers/repository-pattern-abstractions.md) — Abstracts MongoDB interactions behind a repository interface for testable data access.
- [MongoDB Repository Abstractions](https://awesome-repositories.com/f/networking-communication/protocol-abstraction-layers/repository-pattern-abstractions/mongodb-repository-abstractions.md) — Persists data through a repository interface that abstracts MongoDB interactions behind a contract for testable data access.

### Security & Cryptography

- [Access and Refresh Token Issuances](https://awesome-repositories.com/f/security-cryptography/access-token-management/offline-access-tokens/access-and-refresh-token-issuances.md) — Generates short-lived access tokens and long-lived refresh tokens with separate signing secrets for user authentication. ([source](https://outcomeschool.com/blog/go-jwt-authentication-middleware))
- [JWT Authentications](https://awesome-repositories.com/f/security-cryptography/token-authentication/jwt-authentications.md) — Issues and validates signed JWT access and refresh tokens for user authentication.
- [Refresh Token Rotation](https://awesome-repositories.com/f/security-cryptography/account-management/account-synchronization/credential-refreshers/oauth-token-refreshes/refresh-token-rotation.md) — Accepts a valid refresh token to issue a new access and refresh token pair without requiring re-login. ([source](https://cdn.jsdelivr.net/gh/amitshekhariitbhu/go-backend-clean-architecture@main/README.md))
- [Identity Payload Extractions](https://awesome-repositories.com/f/security-cryptography/identity-token-services/identity-payload-extractions.md) — Decodes validated JWT tokens to retrieve user ID and name for downstream request handling. ([source](https://outcomeschool.com/blog/go-jwt-authentication-middleware))

### Web Development

- [Gin-Based Frameworks](https://awesome-repositories.com/f/web-development/api-frameworks/gin-based-frameworks.md) — Ships a REST API built on the Gin HTTP framework with public and private routes.
- [Middleware-Based Endpoint Protections](https://awesome-repositories.com/f/web-development/custom-api-endpoints/endpoint-specification/service-endpoints/protected-endpoints/middleware-based-endpoint-protections.md) — Uses middleware to intercept requests and validate JWT tokens before granting access to protected API routes. ([source](https://outcomeschool.com/blog/go-jwt-authentication-middleware))
- [Authenticated Route Separations](https://awesome-repositories.com/f/web-development/public-api-exposure/unauthenticated-public-apis/authenticated-route-separations.md) — Separates API routes into public and JWT-protected groups with middleware-based authentication. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))
- [User Profiles](https://awesome-repositories.com/f/web-development/user-profiles.md) — Returns the authenticated user's name and email via a protected profile endpoint. ([source](https://cdn.jsdelivr.net/gh/amitshekhariitbhu/go-backend-clean-architecture@main/README.md))

### Business & Productivity Software

- [User-Scoped Task CRUD](https://awesome-repositories.com/f/business-productivity-software/task-list-management/user-scoped-task-crud.md) — Implements create and list operations for tasks scoped to the authenticated user via JWT. ([source](https://cdn.jsdelivr.net/gh/amitshekhariitbhu/go-backend-clean-architecture@main/README.md))

### Programming Languages & Runtimes

- [Interface Mock Generators](https://awesome-repositories.com/f/programming-languages-runtimes/go-mocking-libraries/interface-mock-generators.md) — Generates mock implementations from Go interfaces to replace real dependencies in unit tests. ([source](https://outcomeschool.com/blog/test-with-testify-and-mockery-in-go))

### Testing & Quality Assurance

- [Isolated Layer Testing](https://awesome-repositories.com/f/testing-quality-assurance/data-layer-testing/isolated-layer-testing.md) — Replaces real databases and repositories with generated mocks to verify each layer's behavior without external dependencies. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))
- [Dependency Mocking](https://awesome-repositories.com/f/testing-quality-assurance/dependency-mocking.md) — Verifies business logic and data access in isolation using generated mock implementations.
- [Dependency-Mocked Unit Testers](https://awesome-repositories.com/f/testing-quality-assurance/general-testing-utilities/test-isolation/middleware-unit-testing/dependency-mocked-unit-testers.md) — Tests business logic and data access in isolation by substituting real dependencies with mocks.
- [Dependency Mocking](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/dependency-mocking.md) — Substitutes real databases with generated mocks to verify controller, usecase, and repository behavior. ([source](https://outcomeschool.com/blog/go-backend-clean-architecture))
- [Use Case Tests with Mocked Dependencies](https://awesome-repositories.com/f/testing-quality-assurance/software-testing/test-execution-orchestration/test-case-generators/test-case-organizers/use-case-tests-with-mocked-dependencies.md) — Tests use cases by injecting mocked repositories to verify business logic under success and error conditions. ([source](https://outcomeschool.com/blog/test-with-testify-and-mockery-in-go))
