Expert implementation guide for custom Clean Architecture pattern in Golang projects.
Expert guidance for implementing features using this project's custom Clean Architecture pattern with Golang. This is NOT Uncle Bob's standard Clean Architecture - it's a specialized adaptation.
Four layers with strict dependency rules:
Integration → Application → Domain ← Infrastructure
Dependency Rule: Inner layers NEVER depend on outer layers.
Start here ALWAYS. Location: /test/integration/features/
Feature: Create entity functionality
Scenario: Create entity success
When I call "POST" "/v1/entities" with payload
Then status should be 201
And db should contain entity
Entity (/internal/domain/entity/)
Errors (/internal/domain/error/)
PREFIX-XXYYYYEnums (/internal/domain/enums/)
Adapter Interface (/internal/application/adapter/)
UseCase Interfaces (/internal/application/usecase/)
Service Implementation (/internal/application/service/)
Adapter Interfaces (/internal/integration/adapter/)
type Repository interface {
usecase.Find // MUST embed
usecase.Save // MUST embed
}
DTOs (/internal/integration/entrypoint/dto/)
Controller (/internal/integration/entrypoint/controller/)
Model (/internal/integration/persistence/model/)
Repository (/internal/integration/persistence/)
Dependency Injection (/internal/infra/dependency/injector.go)
// Type cast repository to usecase
usecase.Find(i.GetRepository())
Router (/internal/infra/server/router/router.go)
make test-integration
// Application defines need
type FindProduct interface {
FindById(ctx, id) (*entity, error)
}
// Integration MUST implement
type ProductRepository interface {
usecase.FindProduct // EMBED!
}
// Type cast in DI
usecase.FindProduct(repository)
CLI-01409 = Client conflict (409)USR-01404 = User not found (404)PRD-02500 = Product server error (500)Request → DTO → Entity → Model → DB
Response ← DTO ← Entity ← Model ← DB
Detailed guides in references/:
Ready-to-use templates in assets/:
entity-template.go - Domain entity templateservice-template.go - Application service templaterepository-template.go - Repository templateBefore starting any feature:
Study these existing implementations:
/internal/{domain,application,integration}/*/client*.go/internal/{domain,application,integration}/*/user*.go/internal/{domain,application,integration}/*/forest*.go