User Tools

Site Tools


go:architecture:clean_arch

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
go:architecture:clean_arch [2026/01/30 01:24] phong2018go:architecture:clean_arch [2026/01/30 01:33] (current) – [2. Application Layer — Usecase Orchestration] phong2018
Line 46: Line 46:
 ==== Overall Structure (Clean Architecture Only) ==== ==== Overall Structure (Clean Architecture Only) ====
  
-<code> internal/ ├── domain/ # Domain Layer (pure business logic) │ ├── model/ # Business entities │ ├── repository/ # Interfaces (contracts) │ └── service/ # Domain services (optional) │ ├── application/ # Application Layer │ ├── usecase/ # Use cases (orchestration) │ └── dto/ # Input / output data structures │ ├── interface/ # Interface (Presentation) Layer │ ├── grpc/ │ │ └── handler/ # gRPC handlers │ └── http/ # HTTP handlers (optional) │ ├── infrastructure/ # Infrastructure Layer │ ├── repository/ # Repository implementations │ ├── persistence/DB setup transactions │ └── client/ # External API clients │ └── shared/ # Cross-cutting concerns ├── constant/ ├── validator/ ├── logger/ └── database/ </code>+<code text> 
 +internal/ 
 +├── domain/                 # Domain Layer (pure business logic) 
 +│   ├── model/              Core business entities 
 +│   ├── repository/         Repository interfaces (contracts) 
 +│   └── service/            # Domain services (optional) 
 + 
 +├── application/            # Application Layer 
 +│   ├── usecase/            # Use cases (business orchestration) 
 +│   └── dto/                # Input / output data structures 
 + 
 +├── interface/              # Interface (Presentation) Layer 
 +│   ├── grpc/ 
 +│   │   └── handler/        # gRPC handlers 
 +│   └── http/               # HTTP handlers (optional) 
 + 
 +├── infrastructure/         # Infrastructure Layer 
 +│   ├── repository/         # Repository implementations 
 +│   ├── persistence/        Database setup transactions 
 +│   └── client/             # External API / service clients 
 + 
 +└── shared/                 # Cross-cutting concerns 
 +    ├── constant/ 
 +    ├── validator/ 
 +    ├── logger/ 
 +    └── database/ 
 +</code> 
  
 ===== IV. Layer Responsibilities ===== ===== IV. Layer Responsibilities =====
Line 58: Line 85:
 ===== V. Processing Flow (Request → Response) ===== ===== V. Processing Flow (Request → Response) =====
  
-<code> Client (gRPC / HTTP Request) ↓ Interface Layer (Handler) - Receive request - Validate input ↓ Application Layer (Usecase) - Orchestrate business logic ↓ Domain Layer (Repository Interface) - Define contracts ↓ Infrastructure Layer (Implementation) - Access DB / External API ↓ Database / External Service </code> +<code text> 
 +Client (gRPC / HTTP Request) 
 +         
 +Interface Layer (Handler) 
 +  - Receive request 
 +  - Validate input 
 +         
 +Application Layer (Usecase) 
 +  - Orchestrate business logic 
 +         
 +Domain Layer (Repository Interface) 
 +  - Define contracts 
 +         
 +Infrastructure Layer (Implementation) 
 +  - Access DB / External API 
 +         
 +Database / External Service 
 +</code>
 ===== VI. Detailed Layer Examples ===== ===== VI. Detailed Layer Examples =====
  
Line 73: Line 116:
  
 File location: File location:
-<code>+<code text>
 internal/domain/repository/add_point_repository.go internal/domain/repository/add_point_repository.go
-</code> 
  
 <code go> type AddPointRepository interface { FetchProcessingOrders( ctx context.Context, limit, offset int, ) ([]ProcessingOrder, error) <code go> type AddPointRepository interface { FetchProcessingOrders( ctx context.Context, limit, offset int, ) ([]ProcessingOrder, error)
Line 104: Line 146:
 <code> <code>
 internal/application/usecase/point_add_usecase.go internal/application/usecase/point_add_usecase.go
 +
 </code> </code>
  
-<code go> type PointAddUsecase struct { repo domain.AddPointRepository }+<code go> 
 +type PointAddUsecase struct { repo domain.AddPointRepository }
  
 func (u *PointAddUsecase) Execute(ctx context.Context) error { func (u *PointAddUsecase) Execute(ctx context.Context) error {
go/architecture/clean_arch.1769736252.txt.gz · Last modified: by phong2018