Ánh xạ Clean Architecture#

Thư mụcLayerVai trò
cmd/serverDelivery/Interface AdaptersEntry point của ứng dụng, khởi tạo server, config, routes
internal/Business LogicToàn bộ logic nghiệp vụ (domain)
pkg/InfrastructureCác thành phần dùng chung (Redis, database, external services)
migrate/InfrastructureDatabase migrations
logs/InfrastructureLog files
swagger/Delivery/Interface AdaptersAPI documentation

Ánh xạ từng tầng:#

Thư mụcTầng Clean ArchitectureChức năng
model/EntitiesĐịnh nghĩa cấu trúc dữ liệu nghiệp vụ (domain models)
usecase/Use CasesChứa logic nghiệp vụ, orchestrate các operation
handler/Interface Adapters - ControllersXử lý HTTP requests, gọi usecase
dto/request/Interface Adapters - DTOValidation input từ client
dto/response/Interface Adapters - DTOFormat dữ liệu trả về client
mapping/Interface Adapters - MapperChuyển đổi giữa DTO và Domain và Model
repository/Interface Adapters - GatewayInterface cho database operations

Luồng dữ liệu Clean Architecture#

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

Kiến trúc tổng quát Clean Architecture của Witches#

arc