Clean Architecture Mapping#

DirectoryLayerRole
cmd/serverDelivery / Interface AdaptersApplication entry point, server initialization, config, routes
internal/Business LogicAll business logic (domain)
pkg/InfrastructureShared components (Redis, database, external services)
migrate/InfrastructureDatabase migrations
logs/InfrastructureLog files
swagger/Delivery / Interface AdaptersAPI documentation

Layer Mapping per Domain:#

DirectoryClean Architecture LayerResponsibility
model/EntitiesDefines business data structures (domain models)
usecase/Use CasesContains business logic, orchestrates operations
handler/Interface Adapters – ControllersHandles HTTP requests, calls use cases
dto/request/Interface Adapters – DTOClient input validation
dto/response/Interface Adapters – DTOFormats data returned to the client
mapping/Interface Adapters – MapperConverts between DTO, Domain, and Model
repository/Interface Adapters – GatewayInterface for database operations

Clean Architecture Data Flow#

HTTP Request
    ↓
Delivery Layer (cmd/server/routers)
    ↓
Handler (internal/{domain}/handler)
    ↓
DTO → Domain (mapping/)
    ↓
UseCase (usecase/)
    ↓
Repository Interface (repository/)
    ↓
Domain → Model (mapping/)
    ↓
Infrastructure (pkg/, database, redis)

Witches Clean Architecture Overview#

arc